use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class WeldJpaInjectionServices method getScopedPUName.
private String getScopedPUName(final DeploymentUnit deploymentUnit, final String persistenceUnitName, Member injectionPoint) {
PersistenceUnitMetadata scopedPu;
scopedPu = PersistenceUnitSearch.resolvePersistenceUnitSupplier(deploymentUnit, persistenceUnitName);
if (null == scopedPu) {
throw WeldLogger.ROOT_LOGGER.couldNotFindPersistenceUnit(persistenceUnitName, deploymentUnit.getName(), injectionPoint);
}
return scopedPu.getScopedPersistenceUnitName();
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method addPuService.
/**
* Add one PU service per top level deployment that represents
*
*
* @param phaseContext
* @param puList
* @param startEarly
* @param platform
* @throws DeploymentUnitProcessingException
*
*/
private static void addPuService(final DeploymentPhaseContext phaseContext, final ArrayList<PersistenceUnitMetadataHolder> puList, final boolean startEarly, final Platform platform) throws DeploymentUnitProcessingException {
if (puList.size() > 0) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final Collection<ComponentDescription> components = eeModuleDescription.getComponentDescriptions();
if (module == null) {
// Unresolved OSGi bundles would not have a module attached
ROOT_LOGGER.failedToGetModuleAttachment(deploymentUnit);
return;
}
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ModuleClassLoader classLoader = module.getClassLoader();
for (PersistenceUnitMetadataHolder holder : puList) {
setAnnotationIndexes(holder, deploymentUnit);
for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
// only start the persistence unit if JPA_CONTAINER_MANAGED is true
String jpaContainerManaged = pu.getProperties().getProperty(Configuration.JPA_CONTAINER_MANAGED);
boolean deployPU = (jpaContainerManaged == null ? true : Boolean.parseBoolean(jpaContainerManaged));
if (deployPU) {
final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder = getPersistenceProviderDeploymentHolder(deploymentUnit);
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);
if (startEarly) {
if (twoPhaseBootStrapCapable) {
deployPersistenceUnitPhaseOne(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, adaptor);
} else if (false == Configuration.needClassFileTransformer(pu)) {
// will start later when startEarly == false
ROOT_LOGGER.tracef("persistence unit %s in deployment %s is configured to not need class transformer to be set, no class rewriting will be allowed", pu.getPersistenceUnitName(), deploymentUnit.getName());
} else {
// we need class file transformer to work, don't allow cdi bean manager to be access since that
// could cause application classes to be loaded (workaround by setting jboss.as.jpa.classtransformer to false). WFLY-1463
final boolean allowCdiBeanManagerAccess = false;
deployPersistenceUnit(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, startEarly, provider, adaptor, allowCdiBeanManagerAccess);
}
} else {
// !startEarly
if (twoPhaseBootStrapCapable) {
deployPersistenceUnitPhaseTwo(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, provider, adaptor);
} else if (false == Configuration.needClassFileTransformer(pu)) {
final boolean allowCdiBeanManagerAccess = true;
// PUs that have Configuration.JPA_CONTAINER_CLASS_TRANSFORMER = false will start during INSTALL phase
deployPersistenceUnit(phaseContext, deploymentUnit, eeModuleDescription, components, serviceTarget, classLoader, pu, startEarly, provider, adaptor, allowCdiBeanManagerAccess);
}
}
} else {
ROOT_LOGGER.tracef("persistence unit %s in deployment %s is not container managed (%s is set to false)", pu.getPersistenceUnitName(), deploymentUnit.getName(), Configuration.JPA_CONTAINER_MANAGED);
}
}
}
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitXmlParser method parse.
public static PersistenceUnitMetadataHolder parse(final XMLStreamReader reader, final PropertyReplacer propertyReplacer) throws XMLStreamException {
// check for a bogus document and throw error
reader.require(START_DOCUMENT, null, null);
// Read until the first start element
Version version = null;
while (reader.hasNext() && reader.next() != START_ELEMENT) {
if (reader.getEventType() == DTD) {
final String dtdLocation = readDTDLocation(reader);
if (dtdLocation != null) {
version = Version.forLocation(dtdLocation);
}
}
}
final String schemaLocation = readSchemaLocation(reader);
if (schemaLocation != null) {
version = Version.forLocation(schemaLocation);
}
if (version == null || Version.UNKNOWN.equals(version)) {
// Look at the version attribute
String versionString = null;
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final String attributeNamespace = reader.getAttributeNamespace(i);
if (attributeNamespace != null && !attributeNamespace.isEmpty()) {
continue;
}
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
if (attribute == Attribute.VERSION) {
versionString = reader.getAttributeValue(i);
}
}
if ("1.0".equals(versionString)) {
version = Version.JPA_1_0;
} else if ("1".equals(versionString)) {
version = Version.JPA_1_0;
} else if ("2.0".equals(versionString)) {
version = Version.JPA_2_0;
} else if ("2.1".equals(versionString)) {
version = Version.JPA_2_1;
} else if ("2".equals(versionString)) {
version = Version.JPA_2_0;
} else {
version = Version.JPA_2_1;
}
}
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final String attributeNamespace = reader.getAttributeNamespace(i);
if (attributeNamespace != null && !attributeNamespace.isEmpty()) {
continue;
}
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch(attribute) {
case VERSION:
// TODO: handle version
break;
default:
throw unexpectedAttribute(reader, i);
}
}
final List<PersistenceUnitMetadata> PUs = new ArrayList<PersistenceUnitMetadata>();
// until the ending PERSISTENCE tag
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch(element) {
case PERSISTENCEUNIT:
PersistenceUnitMetadata pu = parsePU(reader, version, propertyReplacer);
PUs.add(pu);
ROOT_LOGGER.readingPersistenceXml(pu.getPersistenceUnitName());
break;
default:
throw unexpectedElement(reader);
}
}
PersistenceUnitMetadataHolder result = new PersistenceUnitMetadataHolder(PUs);
if (ROOT_LOGGER.isTraceEnabled())
ROOT_LOGGER.trace(result.toString());
return result;
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class JPADependencyProcessor method addPUServiceDependencyToComponents.
/**
* Add the <code>puServiceName</code> as a dependency on each of the passed <code>components</code>
*
* @param components The components to which the PU service is added as a dependency
* @param holder The persistence units
*/
private static void addPUServiceDependencyToComponents(final Collection<ComponentDescription> components, final PersistenceUnitMetadataHolder holder) {
if (components == null || components.isEmpty() || holder == null) {
return;
}
for (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);
for (final ComponentDescription component : components) {
ROOT_LOGGER.debugf("Adding dependency on PU service %s for component %s", puServiceName, component.getComponentClassName());
component.addDependency(puServiceName, ServiceBuilder.DependencyType.REQUIRED);
}
}
}
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceRefProcessor method getPersistenceContextBindingSource.
private InjectionSource getPersistenceContextBindingSource(final DeploymentUnit deploymentUnit, final String unitName, PersistenceContextType type, SynchronizationType synchronizationType, Map properties) throws DeploymentUnitProcessingException {
PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, unitName);
String scopedPuName = pu.getScopedPersistenceUnitName();
ServiceName puServiceName = getPuServiceName(scopedPuName);
// get deployment settings from top level du (jboss-all.xml is only parsed at the top level).
final JPADeploymentSettings jpaDeploymentSettings = DeploymentUtils.getTopDeploymentUnit(deploymentUnit).getAttachment(JpaAttachments.DEPLOYMENT_SETTINGS_KEY);
return new PersistenceContextInjectionSource(type, synchronizationType, properties, puServiceName, deploymentUnit.getServiceRegistry(), scopedPuName, EntityManager.class.getName(), pu, jpaDeploymentSettings);
}
Aggregations