Skip to content

Commit

Permalink
Merge pull request wildfly#7827 from scottmarlow/WFLY-5006_xpc_unsync
Browse files Browse the repository at this point in the history
WFLY-5006 support for extended persistence context with SynchronizationType.UNSYNCHRONIZED
  • Loading branch information
stuartwdouglas committed Jul 28, 2015
2 parents dd04a6c + 4479c43 commit edd0bb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Expand Up @@ -58,7 +58,6 @@ public class TransactionScopedEntityManager extends AbstractEntityManager implem
private final String puScopedName; // Scoped name of the persistent unit
private final Map properties;
private transient EntityManagerFactory emf;
private transient boolean isJPA21=true; // true if persistence provider supports JPA 2.1
private final SynchronizationType synchronizationType;
private transient Boolean deferDetach;

Expand Down Expand Up @@ -113,7 +112,6 @@ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassN
final ServiceController<?> controller = currentServiceContainer().getService(JPAServiceNames.getPUServiceName(puScopedName));
final PersistenceUnitServiceImpl persistenceUnitService = (PersistenceUnitServiceImpl) controller.getService();
emf = persistenceUnitService.getEntityManagerFactory();
isJPA21 = true;
}

private static ServiceContainer currentServiceContainer() {
Expand Down Expand Up @@ -164,13 +162,10 @@ private EntityManager getOrCreateTransactionScopedEntityManager(

private EntityManager createEntityManager(
EntityManagerFactory emf, Map properties, final SynchronizationType synchronizationType) {
if (isJPA21()) {
try {
return emf.createEntityManager(synchronizationType, properties); // properties may be null in jpa 2.1
} catch (AbstractMethodError consideredNotJPA21Exception) { // dealing with JPA 1.0 or 2.0 provider?
setJPA21(false);
}

// only JPA 2.1 applications can specify UNSYNCHRONIZED.
// Default is SYNCHRONIZED if synchronizationType is not passed to createEntityManager
if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) {
return emf.createEntityManager(synchronizationType, properties); // properties may be null in jpa 2.1
}

if (properties != null && properties.size() > 0) {
Expand All @@ -179,14 +174,6 @@ private EntityManager createEntityManager(
return emf.createEntityManager();
}

private boolean isJPA21() {
return isJPA21;
}

private void setJPA21(boolean value) {
isJPA21 = value;
}

/**
* return true if non-tx invocations should defer detaching of entities until entity manager is closed.
* Note that this is an extension for compatibility with JBoss application server 5.0/6.0 (see AS7-2781)
Expand Down
Expand Up @@ -172,7 +172,12 @@ public ManagedReference getReference() {
}

if (entityManager1 == null) {
entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(properties), synchronizationType);
if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) {
entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(synchronizationType, properties), synchronizationType);
}
else {
entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(properties), synchronizationType);
}
createdNewExtendedPersistence = true;
if (ROOT_LOGGER.isDebugEnabled())
ROOT_LOGGER.debugf("created new ExtendedEntityManager for unit name=%s, useDeepInheritance = %b", unitName, useDeepInheritance);
Expand Down

0 comments on commit edd0bb3

Please sign in to comment.