List of usage examples for javax.persistence EntityTransaction isActive
public boolean isActive();
From source file:com.nandhootoo.services.ProductServiceImpl.java
public void persist(Product product) { EntityTransaction tx = null; try {//w w w . ja v a 2 s . c o m entityManager.persist(product); } catch (Exception ex) { if (tx != null && tx.isActive()) tx.rollback(); throw (RuntimeException) ex.getCause(); } }
From source file:com.nandhootoo.services.DepartmentServiceImpl.java
public void merge(Department department) { EntityTransaction tx = null; try {//from ww w .j a v a 2 s. co m entityManager.merge(department); } catch (Exception ex) { if (tx != null && tx.isActive()) tx.rollback(); throw (RuntimeException) ex.getCause(); } }
From source file:com.nandhootoo.services.DepartmentServiceImpl.java
public void persist(Department department) { EntityTransaction tx = null; try {/* ww w. j ava 2 s .c o m*/ entityManager.persist(department); } catch (Exception ex) { if (tx != null && tx.isActive()) tx.rollback(); throw (RuntimeException) ex.getCause(); } }
From source file:org.nuxeo.ecm.core.persistence.PersistenceProvider.java
protected void doCommit(EntityManager em) { try {// www .ja v a 2s . c o m em.flush(); } catch (TransactionRequiredException e) { // ignore } EntityTransaction et = getTransaction(em); if (et == null || !et.isActive()) { return; } et.commit(); }
From source file:org.nuxeo.ecm.core.persistence.PersistenceProvider.java
protected void doRollback(EntityManager em) { try {//from w w w . jav a 2s. c om em.flush(); } catch (TransactionRequiredException e) { // ignore } EntityTransaction et = getTransaction(em); if (et == null || !et.isActive()) { return; } et.rollback(); }
From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java
public void update(final PurseSeineTrip trip) { final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); try {//from w w w . jav a2s. c om xa.begin(); mgr.merge(trip); xa.commit(); } catch (Exception ex) { if (xa.isActive()) { xa.rollback(); } } finally { mgr.close(); } }
From source file:au.com.cybersearch2.classyjpa.entity.LoaderTaskImpl.java
/** * Handle load complete on calling thread * @param loader the loader that completed the load * @param success Boolean object - Boolean.TRUE indicates successful result *//*w w w.j a va 2s . c om*/ @Override public void onLoadComplete(Loader<Boolean> loader, Boolean success) { if (uncaughtException != null) { EntityTransaction transaction = transactionInfo.getTransaction(); if ((transaction != null) && transaction.isActive()) transaction.rollback(); if (transactionInfo.getRollbackException() == null) transactionInfo.setRollbackException(uncaughtException); } Throwable rollbackException = transactionInfo.getRollbackException(); if ((rollbackException != null) || (success == null)) success = Boolean.FALSE; if (rollbackException != null) { persistenceWork.onRollback(rollbackException); log.error(TAG, "Persistence container rolled back transaction", rollbackException); } else persistenceWork.onPostExecute(success); if (success) workTracker.setStatus(WorkStatus.FINISHED); else workTracker.setStatus(WorkStatus.FAILED); // Notify waiting threads at very last point of exit synchronized (workTracker) { workTracker.notifyAll(); } }
From source file:org.apache.juddi.replication.ReplicationNotifier.java
/** * returns the latest version of the replication config or null if there * is no config// w w w . j a v a 2s. co m * * @return */ public static org.uddi.repl_v3.ReplicationConfiguration FetchEdges() { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = null; org.uddi.repl_v3.ReplicationConfiguration item = new org.uddi.repl_v3.ReplicationConfiguration(); try { tx = em.getTransaction(); tx.begin(); Query q = em .createQuery("SELECT item FROM ReplicationConfiguration item order by item.serialNumber DESC"); q.setMaxResults(1); ReplicationConfiguration results = (ReplicationConfiguration) q.getSingleResult(); // ReplicationConfiguration find = em.find(ReplicationConfiguration.class, null); if (results != null) { MappingModelToApi.mapReplicationConfiguration(results, item); } tx.commit(); return item; } catch (Exception ex) { //log.error("error", ex); //no config available if (tx != null && tx.isActive()) { tx.rollback(); } } finally { em.close(); } return null; }
From source file:org.spc.ofp.tubs.domain.purseseine.TripRepository.java
public void save(final PurseSeineTrip trip) { final EntityManager mgr = emf.createEntityManager(); final EntityTransaction xa = mgr.getTransaction(); try {//from w ww.j av a 2 s. c o m xa.begin(); mgr.persist(trip); mgr.flush(); xa.commit(); mgr.refresh(trip); } catch (Exception ex) { if (xa.isActive()) { xa.rollback(); } } finally { mgr.close(); } }
From source file:name.livitski.tools.persista.TransactionalWork.java
/** * Performs the {@link #code database operations} provided by * the subclass in JPA transactional brackets. If there is currently * no active transaction at the entity manager, a new transaction * is started./*from w w w .jav a 2s . co m*/ * If the code finishes normally and does not request the rollback, * the transaction is committed if it was started by this method * (local transaction). * If the implementor's code throws an exception or requests the * rollback, the local transaction is rolled back and any ongoing * transaction is marked * {@link EntityTransaction#setRollbackOnly() rollback-only}. * @param db the entity manager the operation will be performed with * @return <code>true</code> if the transaction has or may still * be committed * @throws AbstractStorageException indicates an error during * the operation * @throws RuntimeException any unchecked implementor's exceptions * will be rethrown * @see EntityManager#getTransaction() */ public boolean exec(final EntityManager db) throws AbstractStorageException { final EntityTransaction transaction = db.getTransaction(); boolean commit = false; Exception status = null; boolean localTransaction; if (transaction.isActive()) localTransaction = false; else { transaction.begin(); localTransaction = true; } try { commit = code(db); return commit; } catch (AbstractStorageException fault) { status = fault; throw fault; } catch (RuntimeException fault) { status = fault; throw fault; } finally { if (!localTransaction) { if (commit) db.flush(); else transaction.setRollbackOnly(); } else if (!commit || transaction.getRollbackOnly()) { try { transaction.rollback(); } catch (RuntimeException fault) { if (null != status) log().error("Transaction rollback failed", fault); else throw fault; } } else // commit local transaction { try { transaction.commit(); } catch (RuntimeException fault) { throw fault; } } } }