Permalink
Browse files

HHH-7527 Enterprise OSGi JPA support

  • Loading branch information...
brmeyer committed Jan 23, 2013
1 parent 18f0bd2 commit 56867417e283b235aa0832affd43207cb9ea5327
Showing with 662 additions and 61 deletions.
  1. +50 −7 build.gradle
  2. +7 −0 hibernate-c3p0/hibernate-c3p0.gradle
  3. +13 −0 hibernate-core/hibernate-core.gradle
  4. +23 −2 hibernate-core/src/main/java/org/hibernate/boot/registry/BootstrapServiceRegistryBuilder.java
  5. +3 −4 ...ate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorBuilder.java
  6. +3 −2 hibernate-core/src/main/java/org/hibernate/engine/spi/SessionImplementor.java
  7. +15 −9 hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java
  8. +13 −8 hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java
  9. +7 −0 hibernate-ehcache/hibernate-ehcache.gradle
  10. +19 −0 hibernate-entitymanager/hibernate-entitymanager.gradle
  11. +6 −4 hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java
  12. +29 −3 ...-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java
  13. +16 −1 hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/Bootstrap.java
  14. +6 −0 hibernate-envers/hibernate-envers.gradle
  15. +3 −3 ...n/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
  16. +7 −0 hibernate-infinispan/hibernate-infinispan.gradle
  17. +13 −0 hibernate-osgi/hibernate-osgi.gradle
  18. +109 −0 hibernate-osgi/src/main/java/org/hibernate/osgi/HibernateBundleActivator.java
  19. +168 −0 hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java
  20. +84 −0 hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiJtaPlatform.java
  21. +7 −1 hibernate-proxool/hibernate-proxool.gradle
  22. +7 −0 hibernate-testing/hibernate-testing.gradle
  23. +2 −2 libraries.gradle
  24. +1 −15 release/release.gradle
  25. +2 −0 settings.gradle
  26. +49 −0 utilities.gradle
View
@@ -68,6 +68,8 @@ subprojects { subProject ->
apply plugin: 'java'
apply plugin: 'maven' // for install task as well as deploy dependencies
apply plugin: 'uploadAuth'
+ apply plugin: 'osgi'
+ apply from: "../utilities.gradle"
configurations {
provided {
@@ -169,13 +171,54 @@ subprojects { subProject ->
compileJava.options.define(compilerArgs: ["-proc:none", "-encoding", "UTF-8"])
compileTestJava.options.define(compilerArgs: ["-proc:none", "-encoding", "UTF-8"])
- manifest.mainAttributes(
- provider: 'gradle',
- 'Implementation-Url': 'http://hibernate.org',
- 'Implementation-Version': version,
- 'Implementation-Vendor': 'Hibernate.org',
- 'Implementation-Vendor-Id': 'org.hibernate'
- )
+ jar {
+ Set<String> exportPackages = new HashSet<String>()
+ Set<String> privatePackages = new HashSet<String>()
+
+ // TODO: Could more of this be pulled into utilities.gradle?
+ sourceSets.each { SourceSet sourceSet ->
+ // skip certain source sets
+ if ( ! ['test','matrix'].contains( sourceSet.name ) ) {
+ sourceSet.java.each { javaFile ->
+ // - org.hibernate.boot.registry.classloading.internal
+ // until EntityManagerFactoryBuilderImpl no longer imports ClassLoaderServiceImpl
+ // - .util for external module use (especially envers)
+ final String[] temporaryExports = [
+ 'org.hibernate.boot.registry.classloading.internal',
+ 'org.hibernate.internal.util' ]
+
+ final String packageName = determinePackageName( sourceSet.java, javaFile );
+ if ( ! temporaryExports.contains( packageName )
+ && ( packageName.endsWith( ".internal" )
+ || packageName.contains( ".internal." )
+ || packageName.endsWith( ".test" )
+ || packageName.contains( ".test." ) ) ) {
+ privatePackages.add( packageName );
+ }
+ else {
+ exportPackages.add( packageName );
+ }
+ }
+ }
+ }
+
+ manifest = osgiManifest {
+ // GRADLE-1411: Even if we override Imports and Exports
+ // auto-generation with instructions, classesDir and classpath
+ // need to be here (temporarily).
+ classesDir = sourceSets.main.output.classesDir
+ classpath = configurations.runtime
+
+ instruction 'Export-Package', exportPackages.toArray(new String[0])
+ instruction 'Private-Package', privatePackages.toArray(new String[0])
+ instruction 'Bundle-Vendor', 'Hibernate.org'
+
+ instruction 'Implementation-Url', 'http://hibernate.org'
+ instruction 'Implementation-Version', version
+ instruction 'Implementation-Vendor', 'Hibernate.org'
+ instruction 'Implementation-Vendor-Id', 'org.hibernate'
+ }
+ }
test {
systemProperties['hibernate.test.validatefailureexpected'] = true
@@ -8,4 +8,11 @@ dependencies {
transitive = true
}
testCompile project( ':hibernate-testing' )
+}
+
+jar {
+ manifest {
+ instruction 'Bundle-Description', 'Hibernate ORM C3P0'
+ instruction 'Bundle-SymbolicName', 'org.hibernate.c3p0'
+ }
}
@@ -37,6 +37,19 @@ manifest.mainAttributes(
'Main-Class': 'org.hibernate.Version'
)
+jar {
+ manifest {
+ instruction 'Bundle-Description', 'Hibernate ORM Core'
+ instruction 'Bundle-SymbolicName', 'org.hibernate.core'
+
+ // TODO: Uncomment once EntityManagerFactoryBuilderImpl no longer
+ // uses ClassLoaderServiceImpl.
+ instruction 'Export-Package',
+ 'org.hibernate.boot.registry.classloading.internal',
+ '*'
+ }
+}
+
sourceSets.main {
ext.jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
java.srcDir jaxbTargetDir
@@ -33,21 +33,25 @@
import org.hibernate.integrator.internal.IntegratorServiceImpl;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
+import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
/**
* Builder for bootstrap {@link org.hibernate.service.ServiceRegistry} instances.
*
* @author Steve Ebersole
+ * @author Brett Meyer
*
* @see BootstrapServiceRegistryImpl
* @see StandardServiceRegistryBuilder#StandardServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistry)
*/
public class BootstrapServiceRegistryBuilder {
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
private List<ClassLoader> providedClassLoaders;
-
+ private ClassLoaderService providedClassLoaderService;
private StrategySelectorBuilder strategySelectorBuilder = new StrategySelectorBuilder();
+
+
/**
* Add an {@link Integrator} to be applied to the bootstrap registry.
@@ -75,6 +79,18 @@ public BootstrapServiceRegistryBuilder with(ClassLoader classLoader) {
return this;
}
+ /**
+ * Adds a provided {@link ClassLoaderService} for use in class-loading and resource-lookup
+ *
+ * @param classLoader The class loader to use
+ *
+ * @return {@code this}, for method chaining
+ */
+ public BootstrapServiceRegistryBuilder with(ClassLoaderService classLoaderService) {
+ providedClassLoaderService = classLoaderService;
+ return this;
+ }
+
/**
* Applies the specified {@link ClassLoader} as the application class loader for the bootstrap registry
*
@@ -171,7 +187,12 @@ public BootstrapServiceRegistryBuilder withEnvironmentClassLoader(ClassLoader cl
* @return The built bootstrap registry
*/
public BootstrapServiceRegistry build() {
- final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl( providedClassLoaders );
+ final ClassLoaderService classLoaderService;
+ if ( providedClassLoaderService == null ) {
+ classLoaderService = new ClassLoaderServiceImpl( providedClassLoaders );
+ } else {
+ classLoaderService = providedClassLoaderService;
+ }
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
providedIntegrators,
@@ -26,9 +26,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.logging.Logger;
-
-import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
+import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.selector.Availability;
import org.hibernate.boot.registry.selector.AvailabilityAnnouncer;
import org.hibernate.boot.registry.selector.SimpleAvailabilityImpl;
@@ -97,6 +95,7 @@
import org.hibernate.hql.spi.MultiTableBulkIdStrategy;
import org.hibernate.hql.spi.PersistentTableBulkIdStrategy;
import org.hibernate.hql.spi.TemporaryTableBulkIdStrategy;
+import org.jboss.logging.Logger;
/**
* @author Steve Ebersole
@@ -127,7 +126,7 @@ public void addExplicitAvailability(Availability availability) {
explicitAvailabilities.add( availability );
}
- public StrategySelector buildSelector(ClassLoaderServiceImpl classLoaderService) {
+ public StrategySelector buildSelector(ClassLoaderService classLoaderService) {
StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );
// build the baseline...
@@ -30,6 +30,7 @@
import java.util.Map;
import org.hibernate.CacheMode;
+import org.hibernate.Criteria;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
@@ -170,11 +171,11 @@ public Object internalLoad(String entityName, Serializable id, boolean eager, bo
/**
* Execute a criteria query
*/
- public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode);
+ public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode);
/**
* Execute a criteria query
*/
- public List list(CriteriaImpl criteria);
+ public List list(Criteria criteria);
/**
* Execute a filter
@@ -74,8 +74,6 @@
import org.hibernate.Session;
import org.hibernate.SessionBuilder;
import org.hibernate.SessionException;
-import org.hibernate.procedure.ProcedureCall;
-import org.hibernate.engine.spi.SessionOwner;
import org.hibernate.SharedSessionBuilder;
import org.hibernate.SimpleNaturalIdLoadAccess;
import org.hibernate.Transaction;
@@ -100,6 +98,7 @@
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SessionFactoryImplementor;
+import org.hibernate.engine.spi.SessionOwner;
import org.hibernate.engine.spi.Status;
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
import org.hibernate.engine.transaction.spi.TransactionCoordinator;
@@ -150,6 +149,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.pretty.MessageHelper;
+import org.hibernate.procedure.ProcedureCall;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.stat.SessionStatistics;
@@ -1562,14 +1562,17 @@ public Criteria createCriteria(String entityName) {
return new CriteriaImpl(entityName, this);
}
- public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode) {
+ public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode) {
+ // TODO: Is this guaranteed to always be CriteriaImpl?
+ CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
+
errorIfClosed();
checkTransactionSynchStatus();
- String entityName = criteria.getEntityOrClassName();
+ String entityName = criteriaImpl.getEntityOrClassName();
CriteriaLoader loader = new CriteriaLoader(
getOuterJoinLoadable(entityName),
factory,
- criteria,
+ criteriaImpl,
entityName,
getLoadQueryInfluencers()
);
@@ -1583,16 +1586,19 @@ public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode) {
}
}
- public List list(CriteriaImpl criteria) throws HibernateException {
- final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteria );
+ public List list(Criteria criteria) throws HibernateException {
+ // TODO: Is this guaranteed to always be CriteriaImpl?
+ CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
+
+ final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess( criteriaImpl );
if ( naturalIdLoadAccess != null ) {
// EARLY EXIT!
return Arrays.asList( naturalIdLoadAccess.load() );
}
errorIfClosed();
checkTransactionSynchStatus();
- String[] implementors = factory.getImplementors( criteria.getEntityOrClassName() );
+ String[] implementors = factory.getImplementors( criteriaImpl.getEntityOrClassName() );
int size = implementors.length;
CriteriaLoader[] loaders = new CriteriaLoader[size];
@@ -1602,7 +1608,7 @@ public List list(CriteriaImpl criteria) throws HibernateException {
loaders[i] = new CriteriaLoader(
getOuterJoinLoadable( implementors[i] ),
factory,
- criteria,
+ criteriaImpl,
implementors[i],
getLoadQueryInfluencers()
);
@@ -30,8 +30,6 @@
import java.util.List;
import java.util.Map;
-import org.jboss.logging.Logger;
-
import org.hibernate.CacheMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.Criteria;
@@ -73,6 +71,7 @@
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.Type;
+import org.jboss.logging.Logger;
/**
* @author Gavin King
@@ -618,13 +617,16 @@ public Criteria createCriteria(String entityName) {
}
@Override
- public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode) {
+ public ScrollableResults scroll(Criteria criteria, ScrollMode scrollMode) {
+ // TODO: Is this guaranteed to always be CriteriaImpl?
+ CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
+
errorIfClosed();
- String entityName = criteria.getEntityOrClassName();
+ String entityName = criteriaImpl.getEntityOrClassName();
CriteriaLoader loader = new CriteriaLoader(
getOuterJoinLoadable( entityName ),
factory,
- criteria,
+ criteriaImpl,
entityName,
getLoadQueryInfluencers()
);
@@ -633,17 +635,20 @@ public ScrollableResults scroll(CriteriaImpl criteria, ScrollMode scrollMode) {
@Override
@SuppressWarnings( {"unchecked"})
- public List list(CriteriaImpl criteria) throws HibernateException {
+ public List list(Criteria criteria) throws HibernateException {
+ // TODO: Is this guaranteed to always be CriteriaImpl?
+ CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
+
errorIfClosed();
- String[] implementors = factory.getImplementors( criteria.getEntityOrClassName() );
+ String[] implementors = factory.getImplementors( criteriaImpl.getEntityOrClassName() );
int size = implementors.length;
CriteriaLoader[] loaders = new CriteriaLoader[size];
for( int i=0; i <size; i++ ) {
loaders[i] = new CriteriaLoader(
getOuterJoinLoadable( implementors[i] ),
factory,
- criteria,
+ criteriaImpl,
implementors[i],
getLoadQueryInfluencers()
);
@@ -4,3 +4,10 @@ dependencies {
testCompile project( ':hibernate-testing' )
}
+
+jar {
+ manifest {
+ instruction 'Bundle-Description', 'Hibernate ORM EHCache'
+ instruction 'Bundle-SymbolicName', 'org.hibernate.ehcache'
+ }
+}
@@ -21,6 +21,25 @@ dependencies {
testRuntime( "org.jboss.ejb3:jboss-ejb3-api:3.1.0" )
}
+jar {
+ manifest {
+ instruction 'Bundle-Description', 'Hibernate ORM JPA Entity Manager'
+ instruction 'Bundle-SymbolicName', 'org.hibernate.entitymanager'
+
+ // A cdi-api OSGi bundle does not currently exist. For now, explicitly
+ // ignore its packages. This will only cause issues if an app tries
+ // to use the BeanManagerListenerFactory functionality.
+ // NOTE: The "!" negates the package, keeping it out of Import-Package
+ // and including it in Ignore-Package. Also note that '*' does not mean
+ // <Import-Package>*</ImportPackage> will occur. This is simply a
+ // BND instruction -- the auto-discovery of imported packages still
+ // occurs.
+ instruction 'Import-Package',
+ '!javax.enterprise*',
+ '*'
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////////
// JPA model-gen set up
////////////////////////////////////////////////////////////////////////////////////////////////////////
Oops, something went wrong.

0 comments on commit 5686741

Please sign in to comment.