Search in sources :

Example 1 with PersistenceUnitDescriptor

use of org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor 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 PersistenceUnitDescriptor

use of org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor in project robo4j by Robo4J.

the class PersistenceContextBuilder method build.

public PersistenceContextBuilder build() {
    PersistenceDescriptorFactory persistenceDescriptorFactory = new PersistenceDescriptorFactory();
    PersistenceUnitInfo persistenceUnitInfo = persistenceDescriptorFactory.get(RoboClassLoader.getInstance().getClassLoader(), sourceType, packages);
    PersistenceUnitDescriptor persistenceUnitDescriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);
    EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilderImpl(persistenceUnitDescriptor, new HashMap<>());
    registeredClasses = persistenceDescriptorFactory.registeredClasses();
    dataSourceContext = new DataSourceProxy(builder.build());
    return this;
}
Also used : PersistenceUnitInfoDescriptor(org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) PersistenceDescriptorFactory(com.robo4j.db.sql.jpa.PersistenceDescriptorFactory) PersistenceUnitDescriptor(org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)

Aggregations

PersistenceUnitDescriptor (org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)2 PersistenceDescriptorFactory (com.robo4j.db.sql.jpa.PersistenceDescriptorFactory)1 File (java.io.File)1 InputStream (java.io.InputStream)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)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 ScanOptions (org.hibernate.boot.archive.scan.spi.ScanOptions)1 ScanResult (org.hibernate.boot.archive.scan.spi.ScanResult)1 Scanner (org.hibernate.boot.archive.scan.spi.Scanner)1 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)1 ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)1 PersistenceUnitInfoDescriptor (org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor)1 StandardJpaScanEnvironmentImpl (org.hibernate.jpa.boot.internal.StandardJpaScanEnvironmentImpl)1 EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)1 Test (org.junit.Test)1