use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitSearch method getPersistenceUnit.
private static PersistenceUnitMetadata getPersistenceUnit(DeploymentUnit current, final String absolutePath, String puName) {
final String path;
if (absolutePath.startsWith("../")) {
path = absolutePath.substring(3);
} else {
path = absolutePath;
}
final VirtualFile parent = current.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getParent();
final VirtualFile resolvedPath = parent.getChild(path);
List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(DeploymentUtils.getTopDeploymentUnit(current));
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().equals(resolvedPath)) {
PersistenceUnitMetadataHolder holder = resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
if (holder != null) {
for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
if (traceEnabled) {
ROOT_LOGGER.tracef("getPersistenceUnit check '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
}
if (pu.getPersistenceUnitName().equals(puName)) {
if (traceEnabled) {
ROOT_LOGGER.tracef("getPersistenceUnit matched '%s' against pu '%s'", puName, pu.getPersistenceUnitName());
}
return pu;
}
}
}
}
}
throw JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(absolutePath, puName, current);
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitSearch method findWithinLibraryJar.
private static PersistenceUnitMetadata findWithinLibraryJar(DeploymentUnit unit, ResourceRoot moduleResourceRoot, String persistenceUnitName) {
final ResourceRoot deploymentRoot = moduleResourceRoot;
PersistenceUnitMetadataHolder holder = deploymentRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
if (holder == null || holder.getPersistenceUnits() == null) {
if (traceEnabled) {
ROOT_LOGGER.tracef("findWithinLibraryJar checking for '%s' found no persistence units", persistenceUnitName);
}
return null;
}
ambiguousPUError(unit, persistenceUnitName, holder);
persistenceUnitName = defaultPersistenceUnitName(persistenceUnitName, holder);
for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
if (traceEnabled) {
ROOT_LOGGER.tracef("findWithinLibraryJar check '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
}
if (persistenceUnitName == null || persistenceUnitName.length() == 0 || persistenceUnit.getPersistenceUnitName().equals(persistenceUnitName)) {
if (traceEnabled) {
ROOT_LOGGER.tracef("findWithinLibraryJar matched '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
}
return persistenceUnit;
}
}
return null;
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitSearch method findWithinDeployment.
/*
* When finding the default persistence unit, the first persistence unit encountered is returned.
*/
private static PersistenceUnitMetadata findWithinDeployment(DeploymentUnit unit, String persistenceUnitName) {
if (traceEnabled) {
ROOT_LOGGER.tracef("pu findWithinDeployment searching for %s", persistenceUnitName);
}
for (ResourceRoot root : DeploymentUtils.allResourceRoots(unit)) {
PersistenceUnitMetadataHolder holder = root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
if (holder == null || holder.getPersistenceUnits() == null) {
if (traceEnabled) {
ROOT_LOGGER.tracef("pu findWithinDeployment skipping empty pu holder for %s", persistenceUnitName);
}
continue;
}
ambiguousPUError(unit, persistenceUnitName, holder);
persistenceUnitName = defaultPersistenceUnitName(persistenceUnitName, holder);
for (PersistenceUnitMetadata persistenceUnit : holder.getPersistenceUnits()) {
if (traceEnabled) {
ROOT_LOGGER.tracef("findWithinDeployment check '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
}
if (persistenceUnitName == null || persistenceUnitName.length() == 0 || persistenceUnit.getPersistenceUnitName().equals(persistenceUnitName)) {
if (traceEnabled) {
ROOT_LOGGER.tracef("findWithinDeployment matched '%s' against pu '%s'", persistenceUnitName, persistenceUnit.getPersistenceUnitName());
}
return persistenceUnit;
}
}
}
return null;
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitXmlParserTestCase method testVersion.
/**
* See http://issues.jboss.org/browse/STXM-8
*/
@Test
public void testVersion() throws Exception {
final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">" + " <persistence-unit name=\"mypc\">" + " <description>Persistence Unit." + " </description>" + " <jta-data-source>java:/H2DS</jta-data-source>" + " <class>org.jboss.as.test.integration.jpa.epcpropagation.MyEntity</class>" + " <properties> <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/></properties>" + " </persistence-unit>" + "</persistence>";
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(persistence_xml));
PersistenceUnitMetadataHolder metadataHolder = PersistenceUnitXmlParser.parse(reader, PropertyReplacers.noop());
PersistenceUnitMetadata metadata = metadataHolder.getPersistenceUnits().get(0);
String version = metadata.getPersistenceXMLSchemaVersion();
assertEquals("1.0", version);
}
use of org.jboss.as.jpa.config.PersistenceUnitMetadataHolder in project wildfly by wildfly.
the class PersistenceUnitParseProcessor method handleJarDeployment.
private void handleJarDeployment(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!isEarDeployment(deploymentUnit) && !isWarDeployment(deploymentUnit) && (!appClientContainerMode || DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit))) {
// handle META-INF/persistence.xml
// ordered list of PUs
List<PersistenceUnitMetadataHolder> listPUHolders = new ArrayList<PersistenceUnitMetadataHolder>(1);
// handle META-INF/persistence.xml
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
VirtualFile persistence_xml = deploymentRoot.getRoot().getChild(META_INF_PERSISTENCE_XML);
parse(persistence_xml, listPUHolders, deploymentUnit);
PersistenceUnitMetadataHolder holder = normalize(listPUHolders);
// save the persistent unit definitions
// deploymentUnit.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
deploymentRoot.putAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS, holder);
markDU(holder, deploymentUnit);
ROOT_LOGGER.tracef("parsed persistence unit definitions for jar %s", deploymentRoot.getRootName());
incrementPersistenceUnitCount(deploymentUnit, holder.getPersistenceUnits().size());
addApplicationDependenciesOnProvider(deploymentUnit, holder);
}
}
Aggregations