@Test public void testChangeAnnotation() throws Exception { AnnotationImpl a1 = new AnnotationImpl(); a1.setInpoint(10); a1.setOutpoint(100); a1.setMediapackageId("mp123"); a1.setSessionId("session123"); a1.setType("ugc"); a1.setValue("This is some user generated content"); annotationService.addAnnotation(a1); Long a1Id = a1.getAnnotationId(); AnnotationImpl a2 = new AnnotationImpl(); a2.setAnnotationId(a1Id); a2.setValue("This is some other user generated content"); Annotation a3 = annotationService.changeAnnotation(a2); Assert.assertNotNull(a3); Long a2Id = a2.getAnnotationId(); Assert.assertEquals(a1Id, a2Id); Annotation a1FromDb = annotationService.getAnnotation(a1Id); Assert.assertEquals(a1.getAnnotationId(), a1FromDb.getAnnotationId()); Assert.assertEquals(a2.getValue(), a1FromDb.getValue()); Assert.assertEquals(a1.getSessionId(), a1FromDb.getSessionId()); Assert.assertEquals(a1.getUserId(), a1FromDb.getUserId()); Assert.assertEquals(a1.getUserId(), annotationService.securityService.getUser().getUsername()); Assert.assertTrue(annotationService.removeAnnotation(a1)); }
public Annotation changeAnnotation(Annotation a) throws NotFoundException { EntityTransaction tx = null; EntityManager em = null; AnnotationImpl b = null; long id = a.getAnnotationId(); try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); Query q = em.createNamedQuery("updateAnnotation"); q.setParameter("value", a.getValue()); q.setParameter("annotationId", id); int no = q.executeUpdate(); if (no == 1) { b = em.find(AnnotationImpl.class, id); } tx.commit(); return b; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
AnnotationServiceJpaImpl implements AnnotationService { public Annotation changeAnnotation(Annotation a) throws NotFoundException { EntityTransaction tx = null; EntityManager em = null; AnnotationImpl b = null; long id = a.getAnnotationId(); try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); Query q = em.createNamedQuery("updateAnnotation"); q.setParameter("value", a.getValue()); q.setParameter("annotationId", id); int no = q.executeUpdate(); if (no == 1) { b = em.find(AnnotationImpl.class, id); } tx.commit(); return b; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } } }
AnnotationServiceJpaImpl implements AnnotationService { public Annotation changeAnnotation(Annotation a) throws NotFoundException { EntityTransaction tx = null; EntityManager em = null; AnnotationImpl b = null; long id = a.getAnnotationId(); try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); Query q = em.createNamedQuery("updateAnnotation"); q.setParameter("value", a.getValue()); q.setParameter("annotationId", id); int no = q.executeUpdate(); if (no == 1) { b = em.find(AnnotationImpl.class, id); } tx.commit(); return b; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }  }
AnnotationServiceJpaImpl implements AnnotationService { public Annotation changeAnnotation(Annotation a) throws NotFoundException { EntityTransaction tx = null; EntityManager em = null; AnnotationImpl b = null; long id = a.getAnnotationId(); try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); Query q = em.createNamedQuery("updateAnnotation"); q.setParameter("value", a.getValue()); q.setParameter("annotationId", id); int no = q.executeUpdate(); if (no == 1) { b = em.find(AnnotationImpl.class, id); } tx.commit(); return b; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }  void setSecurityService(SecurityService securityService); Annotation addAnnotation(Annotation a); boolean removeAnnotation(Annotation a); Annotation changeAnnotation(Annotation a); Annotation getAnnotation(long id); @SuppressWarnings("unchecked") AnnotationList getAnnotations(int offset, int limit); AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit); AnnotationList getAnnotationsByMediapackageId(String mediapackageId, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByTypeAndDay(String type, String day, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByDay(String day, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByType(String type, int offset, int limit); }
AnnotationServiceJpaImpl implements AnnotationService { public Annotation changeAnnotation(Annotation a) throws NotFoundException { EntityTransaction tx = null; EntityManager em = null; AnnotationImpl b = null; long id = a.getAnnotationId(); try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); Query q = em.createNamedQuery("updateAnnotation"); q.setParameter("value", a.getValue()); q.setParameter("annotationId", id); int no = q.executeUpdate(); if (no == 1) { b = em.find(AnnotationImpl.class, id); } tx.commit(); return b; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }  void setSecurityService(SecurityService securityService); Annotation addAnnotation(Annotation a); boolean removeAnnotation(Annotation a); Annotation changeAnnotation(Annotation a); Annotation getAnnotation(long id); @SuppressWarnings("unchecked") AnnotationList getAnnotations(int offset, int limit); AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit); AnnotationList getAnnotationsByMediapackageId(String mediapackageId, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByTypeAndDay(String type, String day, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByDay(String day, int offset, int limit); @SuppressWarnings("unchecked") AnnotationList getAnnotationsByType(String type, int offset, int limit); static final String PERSISTENCE_UNIT; }