use of org.jboss.as.jpa.config.PersistenceUnitsInApplication in project wildfly by wildfly.
the class HibernateSearchProcessor method addSearchDependency.
private void addSearchDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
String searchModuleName = null;
PersistenceUnitsInApplication persistenceUnitsInApplication = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
for (PersistenceUnitMetadataHolder holder : persistenceUnitsInApplication.getPersistenceUnitHolders()) {
for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
String providerModule = pu.getProperties().getProperty(Configuration.HIBERNATE_SEARCH_MODULE);
if (providerModule != null) {
// one persistence unit specifying the Hibernate search module is allowed
if (searchModuleName == null) {
searchModuleName = providerModule;
} else // more than one persistence unit specifying different Hibernate search module names is not allowed
if (!providerModule.equals(searchModuleName)) {
throw JpaLogger.ROOT_LOGGER.differentSearchModuleDependencies(deploymentUnit.getName(), searchModuleName, providerModule);
}
}
}
}
if (NONE.equals(searchModuleName)) {
// Hibernate Search module will not be added to deployment
ROOT_LOGGER.debugf("Not adding Hibernate Search dependency to deployment %s", deploymentUnit.getName());
return;
}
// use Search module name specified in persistence unit definition
if (searchModuleName != null && !IGNORE.equals(searchModuleName)) {
ModuleIdentifier moduleIdentifier = ModuleIdentifier.fromString(searchModuleName);
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, false, true, true, false));
ROOT_LOGGER.debugf("added %s dependency to %s", moduleIdentifier, deploymentUnit.getName());
} else {
// add Hibernate Search module dependency if application is using the Hibernate Search Indexed annotation
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
List<AnnotationInstance> annotations = index.getAnnotations(SEARCH_INDEXED_ANNOTATION_NAME);
if (annotations != null && !annotations.isEmpty()) {
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, defaultSearchModule, false, true, true, false));
ROOT_LOGGER.debugf("deployment %s contains %s annotation, added %s dependency", deploymentUnit.getName(), SEARCH_INDEXED_ANNOTATION_NAME, defaultSearchModule);
}
}
}
use of org.jboss.as.jpa.config.PersistenceUnitsInApplication in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method incrementPersistenceUnitCount.
private void incrementPersistenceUnitCount(DeploymentUnit topDeploymentUnit, int persistenceUnitCount) {
topDeploymentUnit = DeploymentUtils.getTopDeploymentUnit(topDeploymentUnit);
// create persistence unit counter if not done already
synchronized (topDeploymentUnit) {
// ensure that only one deployment thread sets this at a time
PersistenceUnitsInApplication persistenceUnitsInApplication = getPersistenceUnitsInApplication(topDeploymentUnit);
persistenceUnitsInApplication.increment(persistenceUnitCount);
}
ROOT_LOGGER.tracef("incrementing PU count for %s by %d", topDeploymentUnit.getName(), persistenceUnitCount);
}
use of org.jboss.as.jpa.config.PersistenceUnitsInApplication in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method addApplicationDependenciesOnProvider.
private void addApplicationDependenciesOnProvider(DeploymentUnit topDeploymentUnit, PersistenceUnitMetadataHolder holder) {
topDeploymentUnit = DeploymentUtils.getTopDeploymentUnit(topDeploymentUnit);
synchronized (topDeploymentUnit) {
// ensure that only one deployment thread sets this at a time
PersistenceUnitsInApplication persistenceUnitsInApplication = getPersistenceUnitsInApplication(topDeploymentUnit);
persistenceUnitsInApplication.addPersistenceUnitHolder(holder);
}
}
use of org.jboss.as.jpa.config.PersistenceUnitsInApplication in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method getPersistenceUnitsInApplication.
private PersistenceUnitsInApplication getPersistenceUnitsInApplication(DeploymentUnit topDeploymentUnit) {
PersistenceUnitsInApplication persistenceUnitsInApplication = topDeploymentUnit.getAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION);
if (persistenceUnitsInApplication == null) {
persistenceUnitsInApplication = new PersistenceUnitsInApplication();
topDeploymentUnit.putAttachment(PersistenceUnitsInApplication.PERSISTENCE_UNITS_IN_APPLICATION, persistenceUnitsInApplication);
}
return persistenceUnitsInApplication;
}
use of org.jboss.as.jpa.config.PersistenceUnitsInApplication in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method nextPhaseDependsOnPersistenceUnit.
/**
* 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) && !Configuration.allowApplicationDefinedDatasource(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);
}
}
}
}
}
Aggregations