Skip to content

Commit

Permalink
WFLY-5075 allow application packaged copy of Hibernate ORM jars
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmarlow committed Aug 11, 2015
1 parent f4c6059 commit c1be882
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 91 deletions.
Expand Up @@ -77,5 +77,8 @@ public static List<PersistenceProvider> loadProviderModuleByName(String moduleNa
return result;
}

public static PersistenceProvider loadProviderFromDeployment(ClassLoader classLoader, String persistenceProviderClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
return (PersistenceProvider) classLoader.loadClass(persistenceProviderClassName).newInstance();
}
}

Expand Up @@ -943,15 +943,35 @@ private static PersistenceProvider lookupProvider(
* locate persistence provider in specified static module
*/
if (configuredPersistenceProviderModule != null) {
try {
List<PersistenceProvider> providers = PersistenceProviderLoader.loadProviderModuleByName(configuredPersistenceProviderModule);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
PersistenceProvider provider = getProviderByName(pu, providers);
if (provider != null) {
List<PersistenceProvider> providers;
if (Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED.equals(configuredPersistenceProviderModule)) {
try {
// load the persistence provider from the application deployment
final ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
PersistenceProvider provider = PersistenceProviderLoader.loadProviderFromDeployment(classLoader, persistenceProviderClassName);
providers = new ArrayList<>();
providers.add(provider);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
return provider;

} catch (ClassNotFoundException e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
} catch (InstantiationException e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
} catch (IllegalAccessException e) {
throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
}
} else {
try {
providers = PersistenceProviderLoader.loadProviderModuleByName(configuredPersistenceProviderModule);
PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
PersistenceProvider provider = getProviderByName(pu, providers);
if (provider != null) {
return provider;
}
} catch (ModuleLoadException e) {
throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, configuredPersistenceProviderModule, persistenceProviderClassName);
}
} catch (ModuleLoadException e) {
throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, configuredPersistenceProviderModule, persistenceProviderClassName);
}
}

Expand Down
77 changes: 1 addition & 76 deletions testsuite/compat/pom.xml
Expand Up @@ -51,8 +51,6 @@
<!-- This value is overridden in submodules with the correct relative path. -->
<xslt.scripts.dir>${basedir}/../integration/src/test/xslt</xslt.scripts.dir>

<version.org.hibernate>4.1.9.Final</version.org.hibernate>

<!-- EclipseLink -->
<eclipselink.version.2.3.stable>2.3.2</eclipselink.version.2.3.stable>
<eclipselink.version.2.3.milestone>2.3.3-M3</eclipselink.version.2.3.milestone>
Expand All @@ -62,24 +60,9 @@
</properties>

<!--
Compile-time dependencies upon anything in the AS7 runtime are allowed in this section.
Compile-time dependencies upon anything in the WildFly runtime are allowed in this section.
-->
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down Expand Up @@ -117,64 +100,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.org.hibernate}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>jipijapa-hibernate4-1</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-infinispan</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${version.org.hibernate}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.wildfly</groupId>
<artifactId>jipijapa-eclipselink</artifactId>
Expand Down
Expand Up @@ -46,9 +46,9 @@
*/

@RunWith(Arquillian.class)
public class Hibernate42xTestCase {
public class HibernateJarsInDeploymentTestCase {

private static final String ARCHIVE_NAME = "hibernate_42x";
private static final String ARCHIVE_NAME = "HibernateJarsInDeploymentTestCase";

private static void addHibernate42xJars(EnterpriseArchive ear) {
final String basedir = System.getProperty("basedir");
Expand All @@ -57,7 +57,7 @@ private static void addHibernate42xJars(EnterpriseArchive ear) {
File hibernatecore = new File(testdir, "hibernate-core.jar");
File hibernateannotations = new File(testdir, "hibernate-commons-annotations.jar");
File hibernateentitymanager = new File(testdir, "hibernate-entitymanager.jar");
File jipi = new File(testdir,"jipijapa-hibernate4-1.jar");
File jipi = new File(testdir,"jipijapa-hibernate5.jar");
File dom4j = new File(testdir, "dom4j.jar");
File antlr = new File(testdir, "antlr.jar");
ear.addAsLibraries(
Expand All @@ -76,8 +76,8 @@ public static Archive<?> deploy() throws Exception {
addHibernate42xJars(ear);

JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "beans.jar");
lib.addClasses(SFSB1.class, Hibernate42xTestCase.class);
lib.addAsManifestResource(Hibernate42xTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
lib.addClasses(SFSB1.class, HibernateJarsInDeploymentTestCase.class);
lib.addAsManifestResource(HibernateJarsInDeploymentTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
ear.addAsManifestResource(new StringAsset("Dependencies: org.jboss.jandex\n"), "MANIFEST.MF");
ear.addAsModule(lib);

Expand Down
Expand Up @@ -23,7 +23,6 @@

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="hibernate_pc">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
Expand Down
4 changes: 2 additions & 2 deletions testsuite/compat/src/test/scripts/build-jars.xml
Expand Up @@ -25,10 +25,10 @@
<project>
<target name="copy-jars" description="Copy jars to be tested.">
<copy file="${org.hibernate:hibernate-core:jar}" tofile="${tests.output.dir}/test-libs/hibernate-core.jar"/>
<copy file="${org.hibernate:hibernate-commons-annotations:jar}" tofile="${tests.output.dir}/test-libs/hibernate-commons-annotations.jar"/>
<copy file="${org.hibernate.common:hibernate-commons-annotations:jar}" tofile="${tests.output.dir}/test-libs/hibernate-commons-annotations.jar"/>
<copy file="${org.hibernate:hibernate-entitymanager:jar}" tofile="${tests.output.dir}/test-libs/hibernate-entitymanager.jar"/>
<copy file="${dom4j:dom4j:jar}" tofile="${tests.output.dir}/test-libs/dom4j.jar"/>
<copy file="${org.wildfly:jipijapa-hibernate4-1:jar}" tofile="${tests.output.dir}/test-libs/jipijapa-hibernate4-1.jar"/>
<copy file="${org.wildfly:jipijapa-hibernate5:jar}" tofile="${tests.output.dir}/test-libs/jipijapa-hibernate5.jar"/>
<copy file="${antlr:antlr:jar}" tofile="${tests.output.dir}/test-libs/antlr.jar"/>

<!-- create the eclipselink module to test with -->
Expand Down

0 comments on commit c1be882

Please sign in to comment.