/** * 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); } } }
/** * 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) */ @Override protected boolean deferEntityDetachUntilClose() { if (deferDetach == null) deferDetach = (true == Configuration.deferEntityDetachUntilClose(emf.getProperties())? Boolean.TRUE : Boolean.FALSE); return deferDetach.booleanValue(); }
/** * pre-loads the default persistence provider * * @throws ModuleLoadException */ public static void loadDefaultProvider() throws ModuleLoadException { String defaultProviderModule = Configuration.getDefaultProviderModuleName(); loadProviderModuleByName(defaultProviderModule); }
/** * The sub-deployment phases run in parallel, ensure that no deployment/sub-deployment moves past * Phase.FIRST_MODULE_USE, until the applications persistence unit services are started. * * Note that some application persistence units will not be created until the Phase.INSTALL, in which case * NEXT_PHASE_DEPS is not needed. */ private static void nextPhaseDependsOnPersistenceUnit(final DeploymentPhaseContext phaseContext, final Platform platform) throws DeploymentUnitProcessingException { final DeploymentUnit topDeploymentUnit = DeploymentUtils.getTopDeploymentUnit(phaseContext.getDeploymentUnit()); final PersistenceUnitsInApplication persistenceUnitsInApplication = topDeploymentUnit.getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION); for(final PersistenceUnitMetadataHolder holder: persistenceUnitsInApplication.getPersistenceUnitHolders()) { for (final PersistenceUnitMetadata pu : holder.getPersistenceUnits()) { String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED); boolean deployPU = (jpaContainerManaged == null? true : Boolean.parseBoolean(jpaContainerManaged)); if (deployPU) { final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu); final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(phaseContext.getDeploymentUnit()); final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, phaseContext.getDeploymentUnit()); final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, phaseContext.getDeploymentUnit(), provider, platform); final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu); // only add the next phase dependency, if the persistence unit service is starting early. if( Configuration.needClassFileTransformer(pu)) { // wait until the persistence unit service is started before starting the next deployment phase phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, twoPhaseBootStrapCapable ? puServiceName.append(FIRST_PHASE) : puServiceName); } } } } }
ServiceBuilder<PhaseOnePersistenceUnitServiceImpl> builder = serviceTarget.addService(puServiceName, service); boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu); final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName()); final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());
String providerModuleName = Configuration.getProviderModuleNameFromProviderClassName(pu.getPersistenceProviderClassName()); if (providerModuleName != null) { addOptionalDependency(moduleSpecification, moduleLoader, deploymentUnit, ModuleIdentifier.fromString(providerModuleName));
/** * Determine if class file transformer is needed for the specified persistence unit * * if the persistence provider is Hibernate and use_class_enhancer is not true, don't need a class transformer. * for other persistence providers, the transformer is assumed to be needed. * * @param pu the PU * @return true if class file transformer support is needed for pu */ public static boolean needClassFileTransformer(PersistenceUnitMetadata pu) { boolean result = true; String provider = pu.getPersistenceProviderClassName(); if (pu.getProperties().containsKey(Configuration.JPA_CONTAINER_CLASS_TRANSFORMER)) { result = Boolean.parseBoolean(pu.getProperties().getProperty(Configuration.JPA_CONTAINER_CLASS_TRANSFORMER)); } else if (isHibernateProvider(provider)) { result = (Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_USE_CLASS_ENHANCER)) || Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_ENABLE_DIRTY_TRACKING)) || Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_ENABLE_LAZY_INITIALIZATION)) || Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_ENABLE_ASSOCIATION_MANAGEMENT))); } return result; }
private void setClassLoaderTransformer(DeploymentUnit deploymentUnit) { // (AS7-2233) each persistence unit can use a persistence provider, that might need // to use ClassTransformers. Providers that need class transformers will add them // during the call to CreateContainerEntityManagerFactory. DelegatingClassFileTransformer transformer = deploymentUnit.getAttachment(DelegatingClassFileTransformer.ATTACHMENT_KEY); boolean appContainsPersistenceProviderJars = false; // remove when we revert WFLY-10520 if ( transformer != null) { for (ResourceRoot resourceRoot : DeploymentUtils.allResourceRoots(deploymentUnit)) { PersistenceUnitMetadataHolder holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS); if (holder != null) { for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) { if (Configuration.needClassFileTransformer(pu)) { transformer.addTransformer(new JPADelegatingClassFileTransformer(pu)); } // remove this check when we revert WFLY-10520 String provider = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE); if (provider != null) { if (provider.equals(Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED)) { appContainsPersistenceProviderJars = true; } } } } } // WFLY-10520 Add Hibernate ORM 5.3 compatibility transformer if(!appContainsPersistenceProviderJars && hibernate51CompatibilityTransformer) { transformer.addTransformer(Hibernate51CompatibilityTransformer.getInstance()); } } }
scopedPersistenceUnitName = Configuration.getScopedPersistenceUnitName(pu); if (scopedPersistenceUnitName == null) { scopedPersistenceUnitName = createBeanName(deploymentUnit, pu.getPersistenceUnitName());
/** * The sub-deployment phases run in parallel, ensure that no deployment/sub-deployment moves past * Phase.FIRST_MODULE_USE, until the applications persistence unit services are started. * * Note that some application persistence units will not be created until the Phase.INSTALL, in which case * NEXT_PHASE_DEPS is not needed. */ private static void nextPhaseDependsOnPersistenceUnit(final DeploymentPhaseContext phaseContext, final Platform platform) throws DeploymentUnitProcessingException { final DeploymentUnit topDeploymentUnit = DeploymentUtils.getTopDeploymentUnit(phaseContext.getDeploymentUnit()); final PersistenceUnitsInApplication persistenceUnitsInApplication = topDeploymentUnit.getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION); for(final PersistenceUnitMetadataHolder holder: persistenceUnitsInApplication.getPersistenceUnitHolders()) { for (final PersistenceUnitMetadata pu : holder.getPersistenceUnits()) { String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED); boolean deployPU = (jpaContainerManaged == null? true : Boolean.parseBoolean(jpaContainerManaged)); if (deployPU) { final ServiceName puServiceName = PersistenceUnitServiceImpl.getPUServiceName(pu); final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(phaseContext.getDeploymentUnit()); final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, phaseContext.getDeploymentUnit()); final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, phaseContext.getDeploymentUnit(), provider, platform); final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu); // only add the next phase dependency, if the persistence unit service is starting early. if( Configuration.needClassFileTransformer(pu)) { // wait until the persistence unit service is started before starting the next deployment phase phaseContext.addToAttachmentList(Attachments.NEXT_PHASE_DEPS, twoPhaseBootStrapCapable ? puServiceName.append(FIRST_PHASE) : puServiceName); } } } } }
boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu); final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName()); final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());
String providerModuleName = Configuration.getProviderModuleNameFromProviderClassName(pu.getPersistenceProviderClassName()); if (providerModuleName != null) { addOptionalDependency(moduleSpecification, moduleLoader, deploymentUnit, ModuleIdentifier.fromString(providerModuleName));
/** * Determine if class file transformer is needed for the specified persistence unit * * if the persistence provider is Hibernate and use_class_enhancer is not true, don't need a class transformer. * for other persistence providers, the transformer is assumed to be needed. * * @param pu the PU * @return true if class file transformer support is needed for pu */ public static boolean needClassFileTransformer(PersistenceUnitMetadata pu) { boolean result = true; String provider = pu.getPersistenceProviderClassName(); if (pu.getProperties().containsKey(Configuration.JPA_CONTAINER_CLASS_TRANSFORMER)) { result = Boolean.parseBoolean(pu.getProperties().getProperty(Configuration.JPA_CONTAINER_CLASS_TRANSFORMER)); } else if (isHibernateProvider(provider)) { result = (Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_USE_CLASS_ENHANCER)) || Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_ENABLE_DIRTY_TRACKING)) || Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_ENABLE_LAZY_INITIALIZATION)) || Boolean.TRUE.toString().equals(pu.getProperties().getProperty(HIBERNATE_ENABLE_ASSOCIATION_MANAGEMENT))); } return result; }
private void setClassLoaderTransformer(DeploymentUnit deploymentUnit) { // (AS7-2233) each persistence unit can use a persistence provider, that might need // to use ClassTransformers. Providers that need class transformers will add them // during the call to CreateContainerEntityManagerFactory. DelegatingClassFileTransformer transformer = deploymentUnit.getAttachment(DelegatingClassFileTransformer.ATTACHMENT_KEY); boolean appContainsPersistenceProviderJars = false; // remove when we revert WFLY-10520 if ( transformer != null) { for (ResourceRoot resourceRoot : DeploymentUtils.allResourceRoots(deploymentUnit)) { PersistenceUnitMetadataHolder holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS); if (holder != null) { for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) { if (Configuration.needClassFileTransformer(pu)) { transformer.addTransformer(new JPADelegatingClassFileTransformer(pu)); } // remove this check when we revert WFLY-10520 String provider = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE); if (provider != null) { if (provider.equals(Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED)) { appContainsPersistenceProviderJars = true; } } } } } // WFLY-10520 Add Hibernate ORM 5.3 compatibility transformer if(!appContainsPersistenceProviderJars && hibernate51CompatibilityTransformer) { transformer.addTransformer(Hibernate51CompatibilityTransformer.getInstance()); } } }
scopedPersistenceUnitName = Configuration.getScopedPersistenceUnitName(pu); if (scopedPersistenceUnitName == null) { scopedPersistenceUnitName = createBeanName(deploymentUnit, pu.getPersistenceUnitName());
final PersistenceProvider provider = lookupProvider(pu, persistenceProviderDeploymentHolder, deploymentUnit); final PersistenceProviderAdaptor adaptor = getPersistenceProviderAdaptor(pu, persistenceProviderDeploymentHolder, deploymentUnit, provider, platform); final boolean twoPhaseBootStrapCapable = (adaptor instanceof TwoPhaseBootstrapCapable) && Configuration.allowTwoPhaseBootstrap(pu); deployPersistenceUnitPhaseOne(deploymentUnit, eeModuleDescription, serviceTarget, classLoader, pu, adaptor); else if (false == Configuration.needClassFileTransformer(pu)) { if (twoPhaseBootStrapCapable) { deployPersistenceUnitPhaseTwo(deploymentUnit, eeModuleDescription, serviceTarget, classLoader, pu, provider, adaptor); } else if (false == Configuration.needClassFileTransformer(pu)) { final boolean allowCdiBeanManagerAccess = true;
/** * 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); } } }
boolean useDefaultDataSource = Configuration.allowDefaultDataSourceUse(pu); final String jtaDataSource = adjustJndi(pu.getJtaDataSourceName()); final String nonJtaDataSource = adjustJndi(pu.getNonJtaDataSourceName());
/** * pre-loads the default persistence provider * * @throws ModuleLoadException */ public static void loadDefaultProvider() throws ModuleLoadException { String defaultProviderModule = Configuration.getDefaultProviderModuleName(); loadProviderModuleByName(defaultProviderModule); }
String providerNameDerivedFromClassName = Configuration.getProviderModuleNameFromProviderClassName(persistenceProviderClassName);