Search in sources :

Example 1 with ParsedPersistenceXmlDescriptor

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();
    }
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) StandardScanner(org.hibernate.boot.archive.scan.internal.StandardScanner) Scanner(org.hibernate.boot.archive.scan.spi.Scanner) MappingFileDescriptor(org.hibernate.boot.archive.scan.spi.MappingFileDescriptor) ScanResult(org.hibernate.boot.archive.scan.spi.ScanResult) StandardJpaScanEnvironmentImpl(org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl) StandardScanner(org.hibernate.boot.archive.scan.internal.StandardScanner) InputStream(java.io.InputStream) ScanOptions(org.hibernate.boot.archive.scan.spi.ScanOptions) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) ScanEnvironment(org.hibernate.boot.archive.scan.spi.ScanEnvironment) File(java.io.File) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) PersistenceUnitDescriptor(org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor) Test(org.junit.Test)

Example 2 with ParsedPersistenceXmlDescriptor

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;
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) PersistenceException(javax.persistence.PersistenceException) Map(java.util.Map) PersistenceException(javax.persistence.PersistenceException)

Example 3 with ParsedPersistenceXmlDescriptor

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;
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 4 with ParsedPersistenceXmlDescriptor

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;
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 5 with ParsedPersistenceXmlDescriptor

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;
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Aggregations

ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)9 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 Test (org.junit.Test)3 URL (java.net.URL)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Transaction (javax.transaction.Transaction)2 TransactionManager (javax.transaction.TransactionManager)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 JBossAppServerJtaPlatform (org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform)2 JtaPlatform (org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 PersistenceException (javax.persistence.PersistenceException)1 UserTransaction (javax.transaction.UserTransaction)1 StandardScanOptions (org.hibernate.boot.archive.scan.internal.StandardScanOptions)1 StandardScanner (org.hibernate.boot.archive.scan.internal.StandardScanner)1 MappingFileDescriptor (org.hibernate.boot.archive.scan.spi.MappingFileDescriptor)1 ScanEnvironment (org.hibernate.boot.archive.scan.spi.ScanEnvironment)1