use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method normalize.
/**
* Eliminate duplicate PU definitions from clustering the deployment (first definition will win)
* <p/>
* JPA 8.2 A persistence unit must have a name. Only one persistence unit of any given name must be defined
* within a single EJB-JAR file, within a single WAR file, within a single application client jar, or within
* an EAR. See Section 8.2.2, “Persistence Unit Scope”.
*
* @param listPUHolders
* @return
*/
private PersistenceUnitMetadataHolder normalize(List<PersistenceUnitMetadataHolder> listPUHolders) {
// eliminate duplicates (keeping the first instance of each PU by name)
Map<String, PersistenceUnitMetadata> flattened = new HashMap<String, PersistenceUnitMetadata>();
for (PersistenceUnitMetadataHolder puHolder : listPUHolders) {
for (PersistenceUnitMetadata pu : puHolder.getPersistenceUnits()) {
if (!flattened.containsKey(pu.getPersistenceUnitName())) {
flattened.put(pu.getPersistenceUnitName(), pu);
} else {
PersistenceUnitMetadata first = flattened.get(pu.getPersistenceUnitName());
PersistenceUnitMetadata duplicate = pu;
ROOT_LOGGER.duplicatePersistenceUnitDefinition(duplicate.getPersistenceUnitName(), first.getScopedPersistenceUnitName(), duplicate.getScopedPersistenceUnitName());
}
}
}
PersistenceUnitMetadataHolder holder = new PersistenceUnitMetadataHolder(new ArrayList<PersistenceUnitMetadata>(flattened.values()));
return holder;
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method handleWarDeployment.
private void handleWarDeployment(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!appClientContainerMode && isWarDeployment(deploymentUnit)) {
int puCount;
// ordered list of PUs
List<PersistenceUnitMetadataHolder> listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
// handle WEB-INF/classes/META-INF/persistence.xml
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
VirtualFile persistence_xml = deploymentRoot.getRoot().getChild(WEB_PERSISTENCE_XML);
parse(persistence_xml, listPUHolders, deploymentUnit);
PersistenceUnitMetadataHolder holder = normalize(listPUHolders);
deploymentRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
addApplicationDependenciesOnProvider(deploymentUnit, holder);
markDU(holder, deploymentUnit);
puCount = holder.getPersistenceUnits().size();
// look for persistence.xml in jar files in the META-INF/persistence.xml directory (these are not currently
// handled as subdeployments)
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_FILE_EXTENSION)) {
listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
persistence_xml = resourceRoot.getRoot().getChild(META_INF_PERSISTENCE_XML);
parse(persistence_xml, listPUHolders, deploymentUnit);
holder = normalize(listPUHolders);
resourceRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
addApplicationDependenciesOnProvider(deploymentUnit, holder);
markDU(holder, deploymentUnit);
puCount += holder.getPersistenceUnits().size();
}
}
ROOT_LOGGER.tracef("parsed persistence unit definitions for war %s", deploymentRoot.getRootName());
incrementPersistenceUnitCount(deploymentUnit, puCount);
}
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method parse.
private void parse(final VirtualFile persistence_xml, final List<PersistenceUnitMetadataHolder> listPUHolders, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
ROOT_LOGGER.tracef("parse checking if %s exists, result = %b", persistence_xml.toString(), persistence_xml.exists());
if (persistence_xml.exists() && persistence_xml.isFile()) {
InputStream is = null;
try {
is = persistence_xml.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
PersistenceUnitMetadataHolder puHolder = PersistenceUnitXmlParser.parse(xmlReader, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
postParseSteps(persistence_xml, puHolder, deploymentUnit);
listPUHolders.add(puHolder);
} catch (Exception e) {
throw new DeploymentUnitProcessingException(JpaLogger.ROOT_LOGGER.failedToParse(persistence_xml), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// Ignore
}
}
}
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method handleWarDeployment.
private static void handleWarDeployment(DeploymentPhaseContext phaseContext, boolean startEarly, Platform platform) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (isWarDeployment(deploymentUnit) && JPADeploymentMarker.isJPADeployment(deploymentUnit)) {
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
PersistenceUnitMetadataHolder holder;
ArrayList<PersistenceUnitMetadataHolder> puList = new ArrayList<PersistenceUnitMetadataHolder>(1);
String deploymentRootName = null;
// handle persistence.xml definition in the root of the war
if (deploymentRoot != null && (holder = deploymentRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS)) != null && holder.getPersistenceUnits().size() > 0) {
// assemble and install the PU service
puList.add(holder);
deploymentRootName = deploymentRoot.getRootName();
}
// look for persistence.xml in war files in the META-INF/persistence.xml directory
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
if ((holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS)) != null && holder.getPersistenceUnits().size() > 0) {
// assemble and install the PU service
puList.add(holder);
}
}
}
if (startEarly) {
// only add the WebNonTxEmCloserAction valve on the earlier invocation (AS7-6690).
deploymentUnit.addToAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS, new WebNonTxEmCloserAction());
}
ROOT_LOGGER.tracef("install persistence unit definitions for war %s", deploymentRootName);
addPuService(phaseContext, puList, startEarly, platform);
}
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitServiceHandler method handleJarDeployment.
private static void handleJarDeployment(DeploymentPhaseContext phaseContext, boolean startEarly, Platform platform) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!isEarDeployment(deploymentUnit) && !isWarDeployment(deploymentUnit) && JPADeploymentMarker.isJPADeployment(deploymentUnit)) {
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
PersistenceUnitMetadataHolder holder;
if (deploymentRoot != null && (holder = deploymentRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS)) != null && holder.getPersistenceUnits().size() > 0) {
ArrayList<PersistenceUnitMetadataHolder> puList = new ArrayList<PersistenceUnitMetadataHolder>(1);
puList.add(holder);
ROOT_LOGGER.tracef("install persistence unit definition for jar %s", deploymentRoot.getRootName());
// assemble and install the PU service
addPuService(phaseContext, puList, startEarly, platform);
}
}
}
Aggregations