Search in sources :

Example 1 with PersistenceUnitInfoImpl

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);
    }
}
Also used : PersistenceUnitInfoImpl(org.kie.server.services.jbpm.jpa.PersistenceUnitInfoImpl) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PersistenceProvider(javax.persistence.spi.PersistenceProvider) PersistenceUnitInfo(javax.persistence.spi.PersistenceUnitInfo) InitialContext(javax.naming.InitialContext) URL(java.net.URL) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) MarshallingException(org.kie.server.api.marshalling.MarshallingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 InitialContext (javax.naming.InitialContext)1 PersistenceProvider (javax.persistence.spi.PersistenceProvider)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 QueryNotFoundException (org.jbpm.services.api.query.QueryNotFoundException)1 MarshallingException (org.kie.server.api.marshalling.MarshallingException)1 PersistenceUnitInfoImpl (org.kie.server.services.jbpm.jpa.PersistenceUnitInfoImpl)1