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 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();
}
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();
}
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");
}
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);
}
Aggregations