Skip to content

Commit

Permalink
HHH-7527 Enterprise OSGi JPA support
Browse files Browse the repository at this point in the history
  • Loading branch information
brmeyer committed Feb 14, 2013
1 parent 18f0bd2 commit 5686741
Show file tree
Hide file tree
Showing 26 changed files with 662 additions and 61 deletions.
57 changes: 50 additions & 7 deletions build.gradle
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions hibernate-c3p0/hibernate-c3p0.gradle
Expand Up @@ -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'
}
}
13 changes: 13 additions & 0 deletions hibernate-core/hibernate-core.gradle
Expand Up @@ -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
Expand Down
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -171,7 +187,12 @@ public <T> BootstrapServiceRegistryBuilder withStrategySelectors(AvailabilityAnn
* @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,
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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...
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
Expand All @@ -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];
Expand All @@ -1602,7 +1608,7 @@ public List list(CriteriaImpl criteria) throws HibernateException {
loaders[i] = new CriteriaLoader(
getOuterJoinLoadable( implementors[i] ),
factory,
criteria,
criteriaImpl,
implementors[i],
getLoadQueryInfluencers()
);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
);
Expand All @@ -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()
);
Expand Down
7 changes: 7 additions & 0 deletions hibernate-ehcache/hibernate-ehcache.gradle
Expand Up @@ -4,3 +4,10 @@ dependencies {

testCompile project( ':hibernate-testing' )
}

jar {
manifest {
instruction 'Bundle-Description', 'Hibernate ORM EHCache'
instruction 'Bundle-SymbolicName', 'org.hibernate.ehcache'
}
}
19 changes: 19 additions & 0 deletions hibernate-entitymanager/hibernate-entitymanager.gradle
Expand Up @@ -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
////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 5686741

Please sign in to comment.