use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method postParseSteps.
/**
* Some of this might need to move to the install phase
*
* @param persistence_xml
* @param puHolder
*/
private void postParseSteps(final VirtualFile persistence_xml, final PersistenceUnitMetadataHolder puHolder, final DeploymentUnit deploymentUnit) {
for (PersistenceUnitMetadata pu : puHolder.getPersistenceUnits()) {
// set URLs
List<URL> jarfilesUrls = new ArrayList<URL>();
if (pu.getJarFiles() != null) {
for (String jar : pu.getJarFiles()) {
jarfilesUrls.add(getRelativeURL(persistence_xml, jar));
}
}
pu.setJarFileUrls(jarfilesUrls);
URL url = getPersistenceUnitURL(persistence_xml);
pu.setPersistenceUnitRootUrl(url);
String scopedPersistenceUnitName;
/**
* WFLY-5478 allow custom scoped persistence unit name hint in persistence unit definition.
* Specified scoped persistence unit name needs to be unique across application server deployments.
* Application is responsible for picking a unique name.
* Currently, a non-unique name will result in a DuplicateServiceException deployment failure:
* org.jboss.msc.service.DuplicateServiceException: Service jboss.persistenceunit.my2lccustom#test_pu.__FIRST_PHASE__ is already registered
*/
scopedPersistenceUnitName = Configuration.getScopedPersistenceUnitName(pu);
if (scopedPersistenceUnitName == null) {
scopedPersistenceUnitName = createBeanName(deploymentUnit, pu.getPersistenceUnitName());
} else {
ROOT_LOGGER.tracef("persistence unit '%s' specified a custom scoped persistence unit name hint " + "(jboss.as.jpa.scopedname=%s). The specified name *must* be unique across all application server deployments.", pu.getPersistenceUnitName(), scopedPersistenceUnitName);
if (scopedPersistenceUnitName.indexOf('/') != -1) {
throw JpaLogger.ROOT_LOGGER.invalidScopedName(scopedPersistenceUnitName, '/');
}
}
pu.setScopedPersistenceUnitName(scopedPersistenceUnitName);
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata 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)) {
// 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);
}
}
}
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class JPADependencyProcessor method loadPersistenceUnits.
private int loadPersistenceUnits(final ModuleSpecification moduleSpecification, final ModuleLoader moduleLoader, final DeploymentUnit deploymentUnit, final Set<String> moduleDependencies, final PersistenceUnitMetadataHolder holder) throws DeploymentUnitProcessingException {
int defaultProviderCount = 0;
if (holder != null) {
for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
String providerModule = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
String adapterModule = pu.getProperties().getProperty(Configuration.ADAPTER_MODULE);
String adapterClass = pu.getProperties().getProperty(Configuration.ADAPTER_CLASS);
if (adapterModule != null) {
ROOT_LOGGER.debugf("%s is configured to use adapter module '%s'", pu.getPersistenceUnitName(), adapterModule);
moduleDependencies.add(adapterModule);
}
deploymentUnit.putAttachment(JpaAttachments.ADAPTOR_CLASS_NAME, adapterClass);
String provider = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
if (provider != null) {
if (provider.equals(Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED)) {
ROOT_LOGGER.debugf("%s is configured to use application supplied persistence provider", pu.getPersistenceUnitName());
} else {
moduleDependencies.add(provider);
ROOT_LOGGER.debugf("%s is configured to use provider module '%s'", pu.getPersistenceUnitName(), provider);
}
} else if (Configuration.PROVIDER_CLASS_DEFAULT.equals(pu.getPersistenceProviderClassName())) {
// track number of references to default provider module
defaultProviderCount++;
} else {
// inject other provider modules into application
// in case its not obvious, everything but hibernate3 can end up here. For Hibernate3, the Configuration.PROVIDER_MODULE
// should of been specified.
//
// since we don't know (until after PersistenceProviderProcessor runs in a later phase) if the provider
// is packaged with the app or will be accessed as a module, make the module dependency optional (in case it
// doesn't exist).
String providerModuleName = Configuration.getProviderModuleNameFromProviderClassName(pu.getPersistenceProviderClassName());
if (providerModuleName != null) {
addOptionalDependency(moduleSpecification, moduleLoader, deploymentUnit, ModuleIdentifier.fromString(providerModuleName));
ROOT_LOGGER.debugf("%s is configured to use persistence provider '%s', adding an optional dependency on module '%s'", pu.getPersistenceUnitName(), pu.getPersistenceProviderClassName(), providerModuleName);
}
}
}
}
return defaultProviderCount;
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitSearch method resolvePersistenceUnitSupplier.
public static PersistenceUnitMetadata resolvePersistenceUnitSupplier(DeploymentUnit deploymentUnit, String persistenceUnitName) {
if (traceEnabled) {
ROOT_LOGGER.tracef("pu search for name '%s' inside of %s", persistenceUnitName, deploymentUnit.getName());
}
int scopeSeparatorCharacter = (persistenceUnitName == null ? -1 : persistenceUnitName.indexOf('#'));
if (scopeSeparatorCharacter != -1) {
final String path = persistenceUnitName.substring(0, scopeSeparatorCharacter);
final String name = persistenceUnitName.substring(scopeSeparatorCharacter + 1);
PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, path, name);
if (traceEnabled) {
ROOT_LOGGER.tracef("pu search found %s", pu.getScopedPersistenceUnitName());
}
return pu;
} else {
PersistenceUnitMetadata name = findPersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
if (traceEnabled) {
if (name != null) {
ROOT_LOGGER.tracef("pu search found %s", name.getScopedPersistenceUnitName());
}
}
return name;
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitSearch method ambiguousPUError.
private static void ambiguousPUError(DeploymentUnit unit, String persistenceUnitName, PersistenceUnitMetadataHolder holder) {
if (holder.getPersistenceUnits().size() > 1 && (persistenceUnitName == null || persistenceUnitName.length() == 0)) {
int numberOfDefaultPersistenceUnits = 0;
// get number of persistence units that are marked as default
for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
String defaultPU = persistenceUnit.getProperties().getProperty(Configuration.JPA_DEFAULT_PERSISTENCE_UNIT);
if (Boolean.TRUE.toString().equals(defaultPU)) {
numberOfDefaultPersistenceUnits++;
}
}
ROOT_LOGGER.tracef("checking for ambiguous persistence unit injection error, " + "number of persistence units marked default (%s) = %d", Configuration.JPA_DEFAULT_PERSISTENCE_UNIT, numberOfDefaultPersistenceUnits);
// don't throw an error if there is exactly one default persistence unit
if (numberOfDefaultPersistenceUnits != 1) {
// AS7-2275 no unitName and there is more than one persistence unit;
throw JpaLogger.ROOT_LOGGER.noPUnitNameSpecifiedAndMultiplePersistenceUnits(holder.getPersistenceUnits().size(), unit);
}
}
}
Aggregations