use of org.kie.server.services.jbpm.jpa.PersistenceUnitInfoImpl in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtension method build.
protected EntityManagerFactory build(Map<String, String> properties) {
try {
InitialContext ctx = new InitialContext();
InputStream inputStream = PersistenceUnitInfoLoader.class.getResourceAsStream(PERSISTENCE_XML_LOCATION);
PersistenceUnitInfo info = PersistenceUnitInfoLoader.load(inputStream, ctx, this.getClass().getClassLoader());
// prepare persistence unit root location
URL root = PersistenceUnitInfoLoader.class.getResource(PERSISTENCE_XML_LOCATION);
String jarLocation = root.toExternalForm().split("!")[0].replace(PERSISTENCE_XML_LOCATION, "");
try {
((PersistenceUnitInfoImpl) info).setPersistenceUnitRootUrl(new URL(jarLocation));
} catch (Exception e) {
// in case setting URL to jar file location only fails, fallback to complete URL
((PersistenceUnitInfoImpl) info).setPersistenceUnitRootUrl(root);
}
// Need to explicitly set jtaDataSource here, its value is fetched in Hibernate logger before configuration
((PersistenceUnitInfoImpl) info).setJtaDataSource(properties.get("javax.persistence.jtaDataSource"));
getPersistenceUnitExtensionLoaders(this.getClass().getClassLoader()).stream().filter(PersistenceUnitExtensionsLoader::isEnabled).forEach(extensionsLoader -> extensionsLoader.loadExtensions(info));
List<PersistenceProvider> persistenceProviders = PersistenceProviderResolverHolder.getPersistenceProviderResolver().getPersistenceProviders();
PersistenceProvider selectedProvider = null;
if (persistenceProviders != null) {
for (PersistenceProvider provider : persistenceProviders) {
if (provider.getClass().getName().equals(info.getPersistenceProviderClassName())) {
selectedProvider = provider;
break;
}
}
}
return createEntityManagerFactory(properties, info, selectedProvider);
} catch (Exception e) {
throw new RuntimeException("Unable to create EntityManagerFactory due to " + e.getMessage(), e);
}
}
Aggregations