List of usage examples for javax.persistence EntityTransaction commit
public void commit();
From source file:com.appdynamics.loan.persistence.BasePersistenceImpl.java
@Transactional public void save(final Serializable object) { EntityManager entityManager = getEntityManager(); EntityTransaction txn = entityManager.getTransaction(); txn.begin();//w ww . jav a 2s . co m try { entityManager.persist(object); } catch (Exception ex) { txn.rollback(); } finally { if (!txn.getRollbackOnly()) { txn.commit(); } } }
From source file:info.san.books.app.model.listener.LivreListener.java
@EventHandler public void handle(LivreDeletedEvent e) { EntityManager em = Persistence.getInstance().createEntityManager(); EntityTransaction t = em.getTransaction(); t.begin();/*w w w . j av a 2 s. c o m*/ LivreEntry entry = em.getReference(LivreEntry.class, e.getIsbn()); em.remove(entry); t.commit(); }
From source file:it.infn.ct.futuregateway.apiserver.v1.ApplicationCollectionService.java
/** * Retrieve the application list.//from w w w .j a va 2 s.c om * The fields not requested for the list are cleaned. * @return The list of applications */ private List<Application> retrieveApplicationList() { List<Application> lstApps; EntityManager em = getEntityManager(); EntityTransaction et = null; try { et = em.getTransaction(); et.begin(); lstApps = em.createNamedQuery("applications.all", Application.class).getResultList(); et.commit(); } catch (RuntimeException re) { if (et != null && et.isActive()) { et.rollback(); } log.error("Impossible to retrieve the Application list"); log.error(re); throw new RuntimeException("Impossible to access the " + "application list"); } finally { em.close(); } if (lstApps != null) { for (Application ap : lstApps) { ap.setDescription(null); ap.setParameters(null); } } return lstApps; }
From source file:org.spc.ofp.tubs.domain.common.CommonRepository.java
public boolean saveImportStatus(final ImportStatus status) { boolean success = false; final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); xa.begin();//from w w w . java2s. c o m try { if (status.getId() > 0L) { mgr.merge(status); } else { mgr.persist(status); } xa.commit(); success = true; } catch (Exception ignoreMe) { rollbackQuietly(xa); } finally { mgr.close(); } return success; }
From source file:test.unit.be.fedict.hsm.entity.PersistenceTest.java
@Test public void testAudit() throws Exception { AuditEntity auditEntity = new AuditEntity("applicationName", "applicationKeyAlias", "keyStoreName", "keyStoreAlias", "digestValue"); EntityTransaction entityTransaction = this.entityManager.getTransaction(); entityTransaction.begin();//from ww w . j a va 2 s. c om this.entityManager.persist(auditEntity); entityTransaction.commit(); long auditId = auditEntity.getId(); entityTransaction.begin(); List<AuditEntity> result = AuditEntity.listAll(this.entityManager); entityTransaction.commit(); assertEquals(1, result.size()); assertEquals(auditId, result.get(0).getId()); }
From source file:test.unit.be.fedict.hsm.entity.PersistenceTest.java
@Test public void testKeyStoreEntity() throws Exception { KeyStoreEntity keyStoreEntity = new KeyStoreEntity("name", KeyStoreType.PKCS12, "/home/fcorneli/test.p12", "test", 0); EntityTransaction entityTransaction = this.entityManager.getTransaction(); entityTransaction.begin();/*from www. j av a 2 s . com*/ entityManager.persist(keyStoreEntity); entityTransaction.commit(); long id = keyStoreEntity.getId(); LOG.debug("keystore entity identifier: " + id); KeyStoreEntity resultEntity = this.entityManager.find(KeyStoreEntity.class, id); assertNotNull(resultEntity); LOG.debug("key store entity: " + resultEntity); List<KeyStoreEntity> keyStoreList = KeyStoreEntity.getList(this.entityManager); assertNotNull(keyStoreList); assertEquals(1, keyStoreList.size()); assertTrue(KeyStoreEntity.hasKeyStore(this.entityManager, "name")); }
From source file:org.opennaas.core.security.acl.ACLManager.java
private void executeSqlQuery(String sqlQuery) { log.debug("Executing SQL query: [ " + sqlQuery + " ]"); EntityManager em = securityRepository.getEntityManager(); EntityTransaction et = em.getTransaction(); et.begin();/*from ww w .j av a 2 s.c o m*/ try { em.createNativeQuery(sqlQuery).executeUpdate(); em.flush(); et.commit(); log.debug("SQL query executed."); } catch (Exception e) { log.error("Error executing SQL query, rollbacking", e); et.rollback(); } }
From source file:test.unit.be.fedict.hsm.entity.PersistenceTest.java
@Test public void testKeyStoreEntityUniqueName() throws Exception { String keyStoreName = UUID.randomUUID().toString(); KeyStoreEntity keyStoreEntity = new KeyStoreEntity(keyStoreName, KeyStoreType.PKCS12, "/home/fcorneli/test.p12", "test", 0); EntityTransaction entityTransaction = this.entityManager.getTransaction(); entityTransaction.begin();/*from ww w . jav a 2 s. c o m*/ this.entityManager.persist(keyStoreEntity); entityTransaction.commit(); KeyStoreEntity keyStoreEntity2 = new KeyStoreEntity(keyStoreName, KeyStoreType.PKCS12, "/home/fcorneli/test.p12", "test", 0); entityTransaction.begin(); try { this.entityManager.persist(keyStoreEntity2); fail(); } catch (PersistenceException e) { entityTransaction.rollback(); } }
From source file:test.unit.be.fedict.hsm.entity.PersistenceTest.java
@Test public void testUniqueApplicationName() throws Exception { ApplicationEntity applicationEntity = new ApplicationEntity("app"); ApplicationEntity applicationEntity2 = new ApplicationEntity("app"); EntityTransaction entityTransaction = this.entityManager.getTransaction(); entityTransaction.begin();//from w w w . j a v a2s .co m this.entityManager.persist(applicationEntity); entityTransaction.commit(); entityTransaction.begin(); assertTrue(ApplicationEntity.hasApplication(this.entityManager, "app")); try { this.entityManager.persist(applicationEntity2); fail(); } catch (PersistenceException e) { entityTransaction.rollback(); } }
From source file:test.unit.be.fedict.hsm.entity.PersistenceTest.java
@Test public void testApplicationKeyUniqueAlias() throws Exception { ApplicationEntity applicationEntity = new ApplicationEntity("app"); EntityTransaction entityTransaction = this.entityManager.getTransaction(); entityTransaction.begin();/*from w w w . java 2 s . c o m*/ this.entityManager.persist(applicationEntity); entityTransaction.commit(); long appId = applicationEntity.getId(); entityTransaction.begin(); applicationEntity = this.entityManager.find(ApplicationEntity.class, appId); ApplicationKeyEntity applicationKeyEntity = new ApplicationKeyEntity(applicationEntity, "alias"); ApplicationKeyEntity applicationKeyEntity2 = new ApplicationKeyEntity(applicationEntity, "alias"); this.entityManager.persist(applicationKeyEntity); try { this.entityManager.persist(applicationKeyEntity2); fail(); } catch (EntityExistsException e) { entityTransaction.rollback(); } }