use of org.jipijapa.plugin.spi.PersistenceUnitMetadata 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.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class PersistenceUnitSearch method findWithinApplication.
private static PersistenceUnitMetadata findWithinApplication(DeploymentUnit unit, String persistenceUnitName) {
if (traceEnabled) {
ROOT_LOGGER.tracef("pu findWithinApplication for %s", persistenceUnitName);
}
PersistenceUnitMetadata name = findWithinDeployment(unit, persistenceUnitName);
if (name != null) {
if (traceEnabled) {
ROOT_LOGGER.tracef("pu findWithinApplication matched for %s", persistenceUnitName);
}
return name;
}
List<ResourceRoot> resourceRoots = unit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (!SubDeploymentMarker.isSubDeployment(resourceRoot)) {
name = findWithinLibraryJar(unit, resourceRoot, persistenceUnitName);
if (name != null) {
return name;
}
}
}
return null;
}
use of org.jipijapa.plugin.spi.PersistenceUnitMetadata 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.jipijapa.plugin.spi.PersistenceUnitMetadata 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.jipijapa.plugin.spi.PersistenceUnitMetadata in project wildfly by wildfly.
the class JpaDependenciesProvider method getDependencies.
@Override
public Set<ServiceName> getDependencies(DeploymentUnit deploymentUnit) {
Set<ServiceName> dependencies = new HashSet<>();
for (ResourceRoot root : DeploymentUtils.allResourceRoots(deploymentUnit)) {
final PersistenceUnitMetadataHolder persistenceUnits = root.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
if (persistenceUnits != null && persistenceUnits.getPersistenceUnits() != null) {
for (final PersistenceUnitMetadata pu : persistenceUnits.getPersistenceUnits()) {
final Properties properties = pu.getProperties();
final String jpaContainerManaged = properties.getProperty(Configuration.JPA_CONTAINER_MANAGED);
final boolean deployPU = (jpaContainerManaged == null || Boolean.parseBoolean(jpaContainerManaged));
if (deployPU) {
final ServiceName serviceName = PersistenceUnitServiceImpl.getPUServiceName(pu);
dependencies.add(serviceName);
}
}
}
}
return dependencies;
}
Aggregations