/** * Close the current transaction's EntityManager. * Called after a transaction begin attempt failed. * @param txObject the current transaction */ protected void closeEntityManagerAfterFailedBegin(JpaTransactionObject txObject) { if (txObject.isNewEntityManagerHolder()) { EntityManager em = txObject.getEntityManagerHolder().getEntityManager(); try { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } } catch (Throwable ex) { logger.debug("Could not rollback EntityManager after failed transaction begin", ex); } finally { EntityManagerFactoryUtils.closeEntityManager(em); } txObject.setEntityManagerHolder(null, false); } }
/** * Close the current transaction's EntityManager. * Called after a transaction begin attempt failed. * @param txObject the current transaction */ protected void closeEntityManagerAfterFailedBegin(JpaTransactionObject txObject) { if (txObject.isNewEntityManagerHolder()) { EntityManager em = txObject.getEntityManagerHolder().getEntityManager(); try { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } } catch (Throwable ex) { logger.debug("Could not rollback EntityManager after failed transaction begin", ex); } finally { EntityManagerFactoryUtils.closeEntityManager(em); } txObject.setEntityManagerHolder(null, false); } }
@Override protected Object doGetTransaction() { JpaTransactionObject txObject = new JpaTransactionObject(); txObject.setSavepointAllowed(isNestedTransactionAllowed()); EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(obtainEntityManagerFactory()); if (emHolder != null) { if (logger.isDebugEnabled()) { logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() + "] for JPA transaction"); } txObject.setEntityManagerHolder(emHolder, false); } if (getDataSource() != null) { ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(getDataSource()); txObject.setConnectionHolder(conHolder); } return txObject; }
/** * Close the current transaction's EntityManager. * Called after a transaction begin attempt failed. * @param txObject the current transaction */ protected void closeEntityManagerAfterFailedBegin(JpaTransactionObject txObject) { if (txObject.isNewEntityManagerHolder()) { EntityManager em = txObject.getEntityManagerHolder().getEntityManager(); try { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } } catch (Throwable ex) { logger.debug("Could not rollback EntityManager after failed transaction begin", ex); } finally { EntityManagerFactoryUtils.closeEntityManager(em); } txObject.setEntityManagerHolder(null, false); } }
logger.debug("Opened new EntityManager [" + newEm + "] for JPA transaction"); txObject.setEntityManagerHolder(new EntityManagerHolder(newEm), true);
@Override protected Object doGetTransaction() { JpaTransactionObject txObject = new JpaTransactionObject(); txObject.setSavepointAllowed(isNestedTransactionAllowed()); EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(obtainEntityManagerFactory()); if (emHolder != null) { if (logger.isDebugEnabled()) { logger.debug("Found thread-bound EntityManager [" + emHolder.getEntityManager() + "] for JPA transaction"); } txObject.setEntityManagerHolder(emHolder, false); } if (getDataSource() != null) { ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(getDataSource()); txObject.setConnectionHolder(conHolder); } return txObject; }
logger.debug("Opened new EntityManager [" + newEm + "] for JPA transaction"); txObject.setEntityManagerHolder(new EntityManagerHolder(newEm), true);
@Override protected Object doSuspend(Object transaction) { JpaTransactionObject txObject = (JpaTransactionObject) transaction; txObject.setEntityManagerHolder(null, false); EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager.unbindResource(obtainEntityManagerFactory()); txObject.setConnectionHolder(null); ConnectionHolder connectionHolder = null; if (getDataSource() != null && TransactionSynchronizationManager.hasResource(getDataSource())) { connectionHolder = (ConnectionHolder) TransactionSynchronizationManager.unbindResource(getDataSource()); } return new SuspendedResourcesHolder(entityManagerHolder, connectionHolder); }
@Override protected Object doSuspend(Object transaction) { JpaTransactionObject txObject = (JpaTransactionObject) transaction; txObject.setEntityManagerHolder(null, false); EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager.unbindResource(obtainEntityManagerFactory()); txObject.setConnectionHolder(null); ConnectionHolder connectionHolder = null; if (getDataSource() != null && TransactionSynchronizationManager.hasResource(getDataSource())) { connectionHolder = (ConnectionHolder) TransactionSynchronizationManager.unbindResource(getDataSource()); } return new SuspendedResourcesHolder(entityManagerHolder, connectionHolder); }