Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-7527 Enterprise OSGi JPA support #465

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 @@ -155,13 +157,51 @@ 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 ->
// - .util for external module use (especially envers)
final String[] temporaryExports = [
'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 {
// pass along command line defined system props (-D) to the test
Expand Down
7 changes: 7 additions & 0 deletions hibernate-c3p0/hibernate-c3p0.gradle
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public String toString() {
public CascadeStyle() {
}

static final Map<String, CascadeStyle> STYLES = new HashMap<String, CascadeStyle>();
public static final Map<String, CascadeStyle> STYLES = new HashMap<String, CascadeStyle>();

static {
STYLES.put( "all", ALL );
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1561,14 +1561,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 @@ -1582,16 +1585,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 @@ -1601,7 +1607,7 @@ public List list(CriteriaImpl criteria) throws HibernateException {
loaders[i] = new CriteriaLoader(
getOuterJoinLoadable( implementors[i] ),
factory,
criteria,
criteriaImpl,
implementors[i],
getLoadQueryInfluencers()
);
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public final class ReflectHelper {
OBJECT_EQUALS = eq;
OBJECT_HASHCODE = hash;
}

// TODO: Better way to do this?
public static ClassLoader overridenClassLoader = null;

/**
* Disallow instantiation of ReflectHelper.
Expand Down Expand Up @@ -160,9 +163,14 @@ public static boolean implementsInterface(Class clazz, Class intf) {
*/
public static Class classForName(String name, Class caller) throws ClassNotFoundException {
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if ( contextClassLoader != null ) {
return contextClassLoader.loadClass( name );
if (overridenClassLoader != null) {
return overridenClassLoader.loadClass( name );
}
else {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if ( contextClassLoader != null ) {
return contextClassLoader.loadClass( name );
}
}
}
catch ( Throwable ignore ) {
Expand All @@ -182,9 +190,14 @@ public static Class classForName(String name, Class caller) throws ClassNotFound
*/
public static Class classForName(String name) throws ClassNotFoundException {
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if ( contextClassLoader != null ) {
return contextClassLoader.loadClass(name);
if (overridenClassLoader != null) {
return overridenClassLoader.loadClass( name );
}
else {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if ( contextClassLoader != null ) {
return contextClassLoader.loadClass(name);
}
}
}
catch ( Throwable ignore ) {
Expand Down
7 changes: 7 additions & 0 deletions hibernate-ehcache/hibernate-ehcache.gradle
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ dependencies {
testRuntime( libraries.validator )
}

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
Loading