Search in sources :

Example 6 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 7 with ParsedPersistenceXmlDescriptor

use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project hibernate-orm by hibernate.

the class DdlInWildFlyUsingBmtAndEmfTest method testCreateThenDrop.

@Test
public void testCreateThenDrop() throws Exception {
    URL persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource(PERSISTENCE_XML_RESOURCE_NAME);
    if (persistenceXmlUrl == null) {
        persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource('/' + PERSISTENCE_XML_RESOURCE_NAME);
    }
    assertNotNull(persistenceXmlUrl);
    ParsedPersistenceXmlDescriptor persistenceUnit = PersistenceXmlParser.locateIndividualPersistenceUnit(persistenceXmlUrl);
    // creating the EMF causes SchemaCreator to be run...
    EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, Collections.emptyMap()).build();
    // closing the EMF causes the delayed SchemaDropper to be run...
    // wrap in a transaction just to see if we can get this to fail in the way the WF report says;
    // in my experience however this succeeds with or without the transaction
    final TransactionManager tm = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(JtaPlatform.class).retrieveTransactionManager();
    tm.begin();
    Transaction txn = tm.getTransaction();
    emf.close();
    txn.commit();
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) JBossAppServerJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) Transaction(javax.transaction.Transaction) UserTransaction(javax.transaction.UserTransaction) TransactionManager(javax.transaction.TransactionManager) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityManagerFactory(javax.persistence.EntityManagerFactory) URL(java.net.URL) Test(org.junit.Test)

Example 8 with ParsedPersistenceXmlDescriptor

use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project hibernate-orm by hibernate.

the class DdlInWildFlyUsingBmtAndEmfTest method testCreateThenDrop.

@Test
public void testCreateThenDrop() throws Exception {
    URL persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource(PERSISTENCE_XML_RESOURCE_NAME);
    if (persistenceXmlUrl == null) {
        persistenceXmlUrl = Thread.currentThread().getContextClassLoader().getResource('/' + PERSISTENCE_XML_RESOURCE_NAME);
    }
    assertNotNull(persistenceXmlUrl);
    ParsedPersistenceXmlDescriptor persistenceUnit = PersistenceXmlParser.locateIndividualPersistenceUnit(persistenceXmlUrl);
    // creating the EMF causes SchemaCreator to be run...
    EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, Collections.emptyMap()).build();
    // closing the EMF causes the delayed SchemaDropper to be run...
    // wrap in a transaction just to see if we can get this to fail in the way the WF report says;
    // in my experience however this succeeds with or without the transaction
    final TransactionManager tm = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(JtaPlatform.class).retrieveTransactionManager();
    tm.begin();
    Transaction txn = tm.getTransaction();
    emf.close();
    txn.commit();
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) JBossAppServerJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) EntityManagerFactory(javax.persistence.EntityManagerFactory) URL(java.net.URL) Test(org.junit.Test)

Example 9 with ParsedPersistenceXmlDescriptor

use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project keycloak by keycloak.

the class JpaUtils method createEntityManagerFactory.

public static EntityManagerFactory createEntityManagerFactory(KeycloakSession session, String unitName, Map<String, Object> properties, boolean jta) {
    PersistenceUnitTransactionType txType = jta ? PersistenceUnitTransactionType.JTA : PersistenceUnitTransactionType.RESOURCE_LOCAL;
    List<ParsedPersistenceXmlDescriptor> persistenceUnits = PersistenceXmlParser.locatePersistenceUnits(properties);
    for (ParsedPersistenceXmlDescriptor persistenceUnit : persistenceUnits) {
        if (persistenceUnit.getName().equals(unitName)) {
            List<Class<?>> providedEntities = getProvidedEntities(session);
            for (Class<?> entityClass : providedEntities) {
                // Add all extra entity classes to the persistence unit.
                persistenceUnit.addClasses(entityClass.getName());
            }
            // Now build the entity manager factory, supplying a proxy classloader, so Hibernate will be able
            // to find and load the extra provided entities.
            persistenceUnit.setTransactionType(txType);
            return Bootstrap.getEntityManagerFactoryBuilder(persistenceUnit, properties, new ProxyClassLoader(providedEntities)).build();
        }
    }
    throw new RuntimeException("Persistence unit '" + unitName + "' not found");
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) ProxyClassLoader(org.keycloak.connections.jpa.entityprovider.ProxyClassLoader) PersistenceUnitTransactionType(javax.persistence.spi.PersistenceUnitTransactionType)

Example 10 with ParsedPersistenceXmlDescriptor

use of org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor in project keycloak by keycloak.

the class KeycloakProcessor method configureHibernate.

/**
 * <p>Configures the persistence unit for Quarkus.
 *
 * <p>The main reason we have this build step is because we re-use the same persistence unit from {@code keycloak-model-jpa}
 * module, the same used by the Wildfly distribution. The {@code hibernate-orm} extension expects that the dialect is statically
 * set to the persistence unit if there is any from the classpath and we use this method to obtain the dialect from the configuration
 * file so that we can build the application with whatever dialect we want. In addition to the dialect, we should also be
 * allowed to set any additional defaults that we think that makes sense.
 *
 * @param config
 * @param descriptors
 */
@BuildStep
void configureHibernate(HibernateOrmConfig config, List<PersistenceXmlDescriptorBuildItem> descriptors, List<JdbcDataSourceBuildItem> jdbcDataSources, BuildProducer<AdditionalJpaModelBuildItem> additionalJpaModel, CombinedIndexBuildItem indexBuildItem) {
    ParsedPersistenceXmlDescriptor descriptor = descriptors.get(0).getDescriptor();
    configureJpaProperties(descriptor, config, jdbcDataSources);
    configureJpaModel(descriptor, indexBuildItem);
}
Also used : ParsedPersistenceXmlDescriptor(org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

ParsedPersistenceXmlDescriptor (org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor)16 ArrayList (java.util.ArrayList)10 Properties (java.util.Properties)10 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 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 PersistenceException (javax.persistence.PersistenceException)1 PersistenceUnitTransactionType (javax.persistence.spi.PersistenceUnitTransactionType)1 UserTransaction (javax.transaction.UserTransaction)1 StandardScanOptions (org.hibernate.boot.archive.scan.internal.StandardScanOptions)1 StandardScanner (org.hibernate.boot.archive.scan.internal.StandardScanner)1