use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project hibernate-orm by hibernate.
the class ScannerTest method testNativeScanner.
@Test
public void testNativeScanner() throws Exception {
File defaultPar = buildDefaultPar();
addPackageToClasspath(defaultPar);
PersistenceUnitDescriptor descriptor = new ParsedPersistenceXmlDescriptor(defaultPar.toURL());
ScanEnvironment env = new StandardJpaScanEnvironmentImpl(descriptor);
ScanOptions options = new StandardScanOptions("hbm,class", descriptor.isExcludeUnlistedClasses());
Scanner scanner = new StandardScanner();
ScanResult scanResult = scanner.scan(env, options, StandardScanParameters.INSTANCE);
assertEquals(3, scanResult.getLocatedClasses().size());
assertClassesContained(scanResult, ApplicationServer.class);
assertClassesContained(scanResult, Version.class);
assertEquals(2, scanResult.getLocatedMappingFiles().size());
for (MappingFileDescriptor mappingFileDescriptor : scanResult.getLocatedMappingFiles()) {
assertNotNull(mappingFileDescriptor.getName());
assertNotNull(mappingFileDescriptor.getStreamAccess());
InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
assertNotNull(stream);
stream.close();
}
}
use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project hibernate-orm by hibernate.
the class HibernatePersistenceProvider method getEntityManagerFactoryBuilderOrNull.
private EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties, ClassLoader providedClassLoader, ClassLoaderService providedClassLoaderService) {
log.tracef("Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s", persistenceUnitName);
final Map integration = wrap(properties);
final List<ParsedPersistenceXmlDescriptor> units;
try {
units = PersistenceXmlParser.locatePersistenceUnits(integration);
} catch (Exception e) {
log.debug("Unable to locate persistence units", e);
throw new PersistenceException("Unable to locate persistence units", e);
}
log.debugf("Located and parsed %s persistence units; checking each", units.size());
if (persistenceUnitName == null && units.size() > 1) {
// no persistence-unit name to look for was given and we found multiple persistence-units
throw new PersistenceException("No name provided and multiple persistence units found");
}
for (ParsedPersistenceXmlDescriptor persistenceUnit : units) {
log.debugf("Checking persistence-unit [name=%s, explicit-provider=%s] against incoming persistence unit name [%s]", persistenceUnit.getName(), persistenceUnit.getProviderClassName(), persistenceUnitName);
final boolean matches = persistenceUnitName == null || persistenceUnit.getName().equals(persistenceUnitName);
if (!matches) {
log.debug("Excluding from consideration due to name mis-match");
continue;
}
// See if we (Hibernate) are the persistence provider
if (!ProviderChecker.isProvider(persistenceUnit, properties)) {
log.debug("Excluding from consideration due to provider mis-match");
continue;
}
if (providedClassLoaderService != null) {
return getEntityManagerFactoryBuilder(persistenceUnit, integration, providedClassLoaderService);
} else {
return getEntityManagerFactoryBuilder(persistenceUnit, integration, providedClassLoader);
}
}
log.debug("Found no matching persistence units");
return null;
}
use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtilsEjb3 method enumDocuments.
public static List<String> enumDocuments(String persistenceUnitName, EntityResolver entityResolver) {
List<String> result = new ArrayList<String>();
List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(new Properties());
for (ParsedPersistenceXmlDescriptor descriptor : persistenceUnits) {
if (descriptor.getName().equals(persistenceUnitName)) {
result.addAll(descriptor.getMappingFileNames());
}
}
return result;
}
use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtilsEjb3 method enumDocuments.
public static List<String> enumDocuments(String persistenceUnitName, EntityResolver entityResolver) {
List<String> result = new ArrayList<String>();
List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(new Properties());
for (ParsedPersistenceXmlDescriptor descriptor : persistenceUnits) {
if (descriptor.getName().equals(persistenceUnitName)) {
result.addAll(descriptor.getMappingFileNames());
}
}
return result;
}
use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project jbosstools-hibernate by jbosstools.
the class OpenMappingUtilsEjb3 method enumDocuments.
public static List<String> enumDocuments(String persistenceUnitName, EntityResolver entityResolver) {
List<String> result = new ArrayList<String>();
List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(new Properties());
for (ParsedPersistenceXmlDescriptor descriptor : persistenceUnits) {
if (descriptor.getName().equals(persistenceUnitName)) {
result.addAll(descriptor.getMappingFileNames());
}
}
return result;
}
Aggregations