this.entityManagerFactory = entityManagerFactory;
this.entityManagerProperties = entityManagerProperties;
}
private EntityManager getEntityManager(boolean activeRequired) {
TransactionImpl transaction = (TransactionImpl) transactionManager.getTransaction();
if (activeRequired && (transaction == null || transaction.getStatus() != Status.STATUS_ACTIVE)) {
throw new TransactionRequiredException("No active transaction");
}
if (transaction == null) {
return null;
}
EntityManagerWrapper entityManagerWrapper = (EntityManagerWrapper) transactionManager.getResource(persistenceUnit);
if (entityManagerWrapper == null) {
EntityManager entityManager = createEntityManager();
entityManagerWrapper = new EntityManagerWrapperTxScoped(entityManager);
transactionManager.putResource(persistenceUnit, entityManagerWrapper);
try {
transaction.registerSynchronization(entityManagerWrapper);
} catch (javax.transaction.RollbackException e) {
throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e);
} catch (SystemException e) {
throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e);
}