in jpa-support/src/main/java/org/apache/aries/jpa/support/impl/EMSupplierImpl.java [98:128]
public EntityManager get() {
Coordination coordination = getTopCoordination();
if (coordination == null) {
throw new IllegalStateException("Need active coordination");
}
EntityManager em = getEm(coordination);
if (em == null) {
LOG.debug("Creating EntityManager for persistence unit " + unitName + ", coordination " + coordination.getName());
em = createEm(emf);
emSet.add(em);
setEm(coordination, em);
coordination.addParticipant(new EmShutDownParticipant());
}
else if (tmTracker != null) {
TransactionManager tm = tmTracker.getService();
if (tm == null) {
LOG.warn("Transaction manager is not available.");
return em;
}
try {
final Transaction transaction = tm.getTransaction();
if (transaction != null && transaction.getStatus() == Status.STATUS_ACTIVE) {
em.joinTransaction();
}
}
catch( SystemException se ) {
throw new IllegalStateException("Unable to check transaction status and join the transaction", se);
}
}
return em;
}