public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); PersistenceContext pc = ae.getAnnotation(PersistenceContext.class); PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class); Class<?> resourceType = EntityManager.class; if (pc != null) { if (pu != null) { throw new IllegalStateException("Member may only be annotated with either " + "@PersistenceContext or @PersistenceUnit, not both: " + member); } Properties properties = null; PersistenceProperty[] pps = pc.properties(); if (!ObjectUtils.isEmpty(pps)) { properties = new Properties(); for (PersistenceProperty pp : pps) { properties.setProperty(pp.name(), pp.value()); } } this.unitName = pc.unitName(); this.type = pc.type(); this.synchronizedWithTransaction = SynchronizationType.SYNCHRONIZED.equals(pc.synchronization()); this.properties = properties; } else { resourceType = EntityManagerFactory.class; this.unitName = pu.unitName(); } checkResourceType(resourceType); }
public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); PersistenceContext pc = ae.getAnnotation(PersistenceContext.class); PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class); Class<?> resourceType = EntityManager.class; if (pc != null) { if (pu != null) { throw new IllegalStateException("Member may only be annotated with either " + "@PersistenceContext or @PersistenceUnit, not both: " + member); } Properties properties = null; PersistenceProperty[] pps = pc.properties(); if (!ObjectUtils.isEmpty(pps)) { properties = new Properties(); for (PersistenceProperty pp : pps) { properties.setProperty(pp.name(), pp.value()); } } this.unitName = pc.unitName(); this.type = pc.type(); this.synchronizedWithTransaction = SynchronizationType.SYNCHRONIZED.equals(pc.synchronization()); this.properties = properties; } else { resourceType = EntityManagerFactory.class; this.unitName = pu.unitName(); } checkResourceType(resourceType); }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final UnitLiteral that = UnitLiteral.class.cast(o); return name.equals(that.name) && synchronization.equals(that.synchronization); }
private EntityManager createEntityManager() { if (sync.equals(SynchronizationType.UNSYNCHRONIZED)) { return new SyncEntityManagerWrapper(emf.createEntityManager(sync), sync); } return emf.createEntityManager(); }
private EntityManager createEntityManager() { if (sync.equals(SynchronizationType.UNSYNCHRONIZED)) { return new SyncEntityManagerWrapper(emf.createEntityManager(sync), sync); } return emf.createEntityManager(); }
private void validateCompatibleSyncTypes(EntityManager existingEm) { if (existingEm instanceof SyncEntityManagerWrapper && ((SyncEntityManagerWrapper) existingEm).getSynchronizationType().equals(sync)) { throw new IllegalStateException("Incompatible SynchronizationType for the same PersistenceContext across " + "multiple injection points. The SynchronizationType can not be SYNCHRONIZED if a " + "previous one that is UNSYCHRONIZED already exists."); } } }
private EntityManager createEntityManager( EntityManagerFactory emf, Map properties, final SynchronizationType synchronizationType) { // only JPA 2.1 applications can specify UNSYNCHRONIZED. // Default is SYNCHRONIZED if synchronizationType is not passed to createEntityManager if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { // properties are allowed to be be null in jpa 2.1 return unsynchronizedEntityManagerWrapper(emf.createEntityManager(synchronizationType, properties)); } if (properties != null && properties.size() > 0) { return emf.createEntityManager(properties); } return emf.createEntityManager(); }
private void validateCompatibleSyncTypes(EntityManager existingEm) { if (existingEm instanceof SyncEntityManagerWrapper && ((SyncEntityManagerWrapper) existingEm).getSynchronizationType().equals(sync)) { throw new IllegalStateException("Incompatible SynchronizationType for the same PersistenceContext across " + "multiple injection points. The SynchronizationType can not be SYNCHRONIZED if a " + "previous one that is UNSYCHRONIZED already exists."); } } }
private EntityManager createEntityManager( EntityManagerFactory emf, Map properties, final SynchronizationType synchronizationType) { // only JPA 2.1 applications can specify UNSYNCHRONIZED. // Default is SYNCHRONIZED if synchronizationType is not passed to createEntityManager if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { // properties are allowed to be be null in jpa 2.1 return unsynchronizedEntityManagerWrapper(emf.createEntityManager(synchronizationType, properties)); } if (properties != null && properties.size() > 0) { return emf.createEntityManager(properties); } return emf.createEntityManager(); }
protected void setJTATransactionWrapper() { transaction = new JTATransactionWrapper(this); //if this is not unsynchronized and there is a transaction, this EM needs to join it if (syncType == null || syncType.equals(SynchronizationType.SYNCHRONIZED)) { //use the wrapper's checkForTransaction as this.checkForTransaction does an unnecessary isJoined check if (transaction.checkForTransaction(false) != null) { //extendedPersistenceContext should be null, which will force the wrapper to register with the transaction transaction.registerIfRequired(this.extendedPersistenceContext); } } }
/** * throw error if jta transaction already has an UNSYNCHRONIZED persistence context and a SYNCHRONIZED persistence context * is requested. We are only fussy in this test, if the target component persistence context is SYNCHRONIZED. * * WFLY-7075 introduces two extensions, allow a (transaction) joined UNSYNCHRONIZED persistence context to be treated as SYNCHRONIZED, * allow the checking for mixed SynchronizationType to be skipped. */ private static void testForMixedSynchronizationTypes(EntityManagerFactory emf, EntityManager entityManagerFromJTA, String scopedPuName, final SynchronizationType targetSynchronizationType, Map targetProperties) { boolean skipMixedSyncTypeChecking = Configuration.skipMixedSynchronizationTypeCheck(emf, targetProperties); // extension to allow skipping of check based on properties of target entity manager boolean allowJoinedUnsyncPersistenceContext = Configuration.allowJoinedUnsyncPersistenceContext(emf, targetProperties); // extension to allow joined unsync persistence context to be treated as sync persistence context if (!skipMixedSyncTypeChecking && SynchronizationType.SYNCHRONIZED.equals(targetSynchronizationType) && entityManagerFromJTA instanceof SynchronizationTypeAccess && SynchronizationType.UNSYNCHRONIZED.equals(((SynchronizationTypeAccess) entityManagerFromJTA).getSynchronizationType()) && (!allowJoinedUnsyncPersistenceContext || !entityManagerFromJTA.isJoinedToTransaction())) { throw JpaLogger.ROOT_LOGGER.badSynchronizationTypeCombination(scopedPuName); } } }
/** * throw error if jta transaction already has an UNSYNCHRONIZED persistence context and a SYNCHRONIZED persistence context * is requested. We are only fussy in this test, if the target component persistence context is SYNCHRONIZED. * * WFLY-7075 introduces two extensions, allow a (transaction) joined UNSYNCHRONIZED persistence context to be treated as SYNCHRONIZED, * allow the checking for mixed SynchronizationType to be skipped. */ private static void testForMixedSynchronizationTypes(EntityManagerFactory emf, EntityManager entityManagerFromJTA, String scopedPuName, final SynchronizationType targetSynchronizationType, Map targetProperties) { boolean skipMixedSyncTypeChecking = Configuration.skipMixedSynchronizationTypeCheck(emf, targetProperties); // extension to allow skipping of check based on properties of target entity manager boolean allowJoinedUnsyncPersistenceContext = Configuration.allowJoinedUnsyncPersistenceContext(emf, targetProperties); // extension to allow joined unsync persistence context to be treated as sync persistence context if (!skipMixedSyncTypeChecking && SynchronizationType.SYNCHRONIZED.equals(targetSynchronizationType) && entityManagerFromJTA instanceof SynchronizationTypeAccess && SynchronizationType.UNSYNCHRONIZED.equals(((SynchronizationTypeAccess) entityManagerFromJTA).getSynchronizationType()) && (!allowJoinedUnsyncPersistenceContext || !entityManagerFromJTA.isJoinedToTransaction())) { throw JpaLogger.ROOT_LOGGER.badSynchronizationTypeCombination(scopedPuName); } } }
/** * Associate the extended persistence context with the current JTA transaction (if one is found) * * this method is private to the JPA subsystem */ public void internalAssociateWithJtaTx() { isInTx = TransactionUtil.isInTx(transactionManager); // ensure that a different XPC (with same name) is not already present in the TX if (isInTx) { // 7.6.3.1 throw EJBException if a different persistence context is already joined to the // transaction (with the same puScopedName). EntityManager existing = TransactionUtil.getTransactionScopedEntityManager(puScopedName, transactionSynchronizationRegistry); if (existing != null && existing != this) { // should be enough to test if not the same object throw JpaLogger.ROOT_LOGGER.cannotUseExtendedPersistenceTransaction(puScopedName, existing, this); } else if (existing == null) { if (SynchronizationType.SYNCHRONIZED.equals(synchronizationType)) { // JPA 7.9.1 join the transaction if not already done for SynchronizationType.SYNCHRONIZED. underlyingEntityManager.joinTransaction(); } // associate the entity manager with the current transaction TransactionUtil.putEntityManagerInTransactionRegistry(puScopedName, this, transactionSynchronizationRegistry); } } }
/** * Associate the extended persistence context with the current JTA transaction (if one is found) * * this method is private to the JPA subsystem */ public void internalAssociateWithJtaTx() { isInTx = TransactionUtil.isInTx(transactionManager); // ensure that a different XPC (with same name) is not already present in the TX if (isInTx) { // 7.6.3.1 throw EJBException if a different persistence context is already joined to the // transaction (with the same puScopedName). EntityManager existing = TransactionUtil.getTransactionScopedEntityManager(puScopedName, transactionSynchronizationRegistry); if (existing != null && existing != this) { // should be enough to test if not the same object throw JpaLogger.ROOT_LOGGER.cannotUseExtendedPersistenceTransaction(puScopedName, existing, this); } else if (existing == null) { if (SynchronizationType.SYNCHRONIZED.equals(synchronizationType)) { // JPA 7.9.1 join the transaction if not already done for SynchronizationType.SYNCHRONIZED. underlyingEntityManager.joinTransaction(); } // associate the entity manager with the current transaction TransactionUtil.putEntityManagerInTransactionRegistry(puScopedName, this, transactionSynchronizationRegistry); } } }
throw new NullPointerException("SynchronizationType must not be null"); if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { throw new UnsupportedOperationException("TODO - implement JPA 2.1 feature");
throw new NullPointerException("SynchronizationType must not be null"); if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { throw new UnsupportedOperationException("TODO - implement JPA 2.1 feature");
if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(synchronizationType, properties), synchronizationType, tsr, transactionManager);
if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(synchronizationType, properties), synchronizationType, tsr, transactionManager);