List of usage examples for javax.persistence EntityManager remove
public void remove(Object entity);
From source file:com.edugility.substantia.substance.TestCasePerson.java
@Test public void testingJPA() throws Exception { final EntityManagerFactory emf = Persistence.createEntityManagerFactory("test"); assertNotNull(emf);// w w w .j a v a 2 s . c om final EntityManager em = emf.createEntityManager(); assertNotNull(em); final EntityTransaction et = em.getTransaction(); assertNotNull(et); et.begin(); final Person p = new Person(); em.persist(p); em.flush(); assertFalse(p.isTransient()); assertTrue(p.isVersioned()); assertEquals(Long.valueOf(1L), p.getId()); assertEquals(Integer.valueOf(1), p.getVersion()); et.commit(); et.begin(); final Person p2 = em.find(Person.class, 1L, LockModeType.OPTIMISTIC_FORCE_INCREMENT); assertNotNull(p2); assertFalse(p2.isTransient()); assertTrue(p2.isVersioned()); assertEquals(Long.valueOf(1L), p2.getId()); assertEquals(Integer.valueOf(1), p2.getVersion()); et.commit(); et.begin(); final Person p3 = em.getReference(Person.class, 1L); assertNotNull(p3); assertFalse(p3.isTransient()); assertTrue(p3.isVersioned()); assertEquals(Long.valueOf(1L), p3.getId()); assertEquals(Integer.valueOf(2), p3.getVersion()); et.commit(); et.begin(); assertTrue(em.contains(p)); em.remove(p); et.commit(); em.close(); emf.close(); }
From source file:org.eclipse.jubula.client.core.persistence.Persistor.java
/** * @param s// w ww . j a va 2 s .c o m * session, which contain the current persistent object * @param po * object to delete * @throws PMException * in case of failed rollback * @throws PMAlreadyLockedException * in case of locked object * @throws PMDirtyVersionException * in case of version conflict * @throws ProjectDeletedException * if the project was deleted in another instance * @throws InterruptedException * if the oepration was canceled */ public void deletePO(EntityManager s, IPersistentObject po) throws PMException, PMAlreadyLockedException, PMDirtyVersionException, ProjectDeletedException, InterruptedException { Validate.notNull(s); try { s.remove(po); } catch (PersistenceException e) { if (e.getCause() instanceof InterruptedException) { // Operation was canceled. throw new InterruptedException(); } PersistenceManager.handleDBExceptionForMasterSession(po, e); } }
From source file:org.rhq.enterprise.server.content.test.RepoManagerBeanTest.java
@Test(enabled = ENABLED) public void createDeleteRepoGroup() throws Exception { // Setup/* www . j a v a2 s.c om*/ EntityManager entityManager = getEntityManager(); RepoGroupType groupType = new RepoGroupType("testCreateDeleteRepoGroupType"); entityManager.persist(groupType); entityManager.flush(); String groupName = "testCreateDeleteRepoGroup"; RepoGroup group = repoManager.getRepoGroupByName(groupName); assert group == null; // Test group = new RepoGroup(groupName); group.setRepoGroupType(groupType); group = repoManager.createRepoGroup(overlord, group); // Verify int id = group.getId(); group = repoManager.getRepoGroup(overlord, id); assert group != null; assert group.getName().equals(groupName); // Cleanup repoManager.deleteRepoGroup(overlord, id); group = repoManager.getRepoGroup(overlord, id); assert group == null; entityManager.remove(groupType); }
From source file:portal.api.impl.PortalJpaController.java
public void deleteMANOplatform(int mpid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); MANOplatform c = entityManager.find(MANOplatform.class, mpid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/*from w w w .j a v a2s .com*/ entityManager.remove(c); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void deleteMANOprovider(int mpid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); MANOprovider c = entityManager.find(MANOprovider.class, mpid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//w w w .j a v a 2 s. com entityManager.remove(c); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void deleteUser(int userid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); PortalUser u = entityManager.find(PortalUser.class, userid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();// w w w . j a v a2s . c o m entityManager.remove(u); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void deleteProperty(int propid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); PortalProperty c = entityManager.find(PortalProperty.class, propid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/* w ww .j a v a 2 s . com*/ entityManager.remove(c); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void deletInfrastructure(int infraid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); Infrastructure c = entityManager.find(Infrastructure.class, infraid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from w ww .j a v a 2 s . c o m entityManager.remove(c); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void deleteVxFOnBoardedDescriptor(int mpid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); VxFOnBoardedDescriptor c = entityManager.find(VxFOnBoardedDescriptor.class, mpid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();//from w w w . ja va 2s . c o m entityManager.remove(c); entityTransaction.commit(); }
From source file:portal.api.impl.PortalJpaController.java
public void deleteExperimentOnBoardDescriptor(int mpid) { EntityManager entityManager = entityManagerFactory.createEntityManager(); ExperimentOnBoardDescriptor c = entityManager.find(ExperimentOnBoardDescriptor.class, mpid); EntityTransaction entityTransaction = entityManager.getTransaction(); entityTransaction.begin();/* ww w . j ava 2 s. c o m*/ entityManager.remove(c); entityTransaction.commit(); }