Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion hibernate-core/hibernate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jar {
manifest {
instruction 'Bundle-Description', 'Hibernate ORM Core'

instruction 'Import-Package',
instructionFirst 'Import-Package',
'javax.security.auth;resolution:=optional',
'javax.security.jacc;resolution:=optional',
'javax.validation;resolution:=optional',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,19 @@ public ClassLoaderServiceImpl(ClassLoader classLoader) {
public ClassLoaderServiceImpl(Collection<ClassLoader> providedClassLoaders) {
final LinkedHashSet<ClassLoader> orderedClassLoaderSet = new LinkedHashSet<ClassLoader>();

// first add all provided class loaders, if any
// normalize adding known class-loaders...
// first, the Hibernate class loader
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );

// then add all provided class loaders, if any
if ( providedClassLoaders != null ) {
for ( ClassLoader classLoader : providedClassLoaders ) {
if ( classLoader != null ) {
orderedClassLoaderSet.add( classLoader );
}
}
}

// normalize adding known class-loaders...
// first, the Hibernate class loader
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );

// then the TCCL, if one...
final ClassLoader tccl = locateTCCL();
if ( tccl != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
package org.hibernate.internal;

import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -33,37 +38,32 @@
import java.util.Hashtable;
import java.util.Properties;
import java.util.Set;

import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Cause;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;

import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.cache.CacheException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolver;
import org.hibernate.engine.jndi.JndiException;
import org.hibernate.engine.jndi.JndiNameException;
import org.hibernate.engine.loading.internal.CollectionLoadContext;
import org.hibernate.engine.loading.internal.EntityLoadContext;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.id.IntegralDataTypeHolder;
import org.hibernate.engine.jndi.JndiException;
import org.hibernate.engine.jndi.JndiNameException;
import org.hibernate.type.BasicType;
import org.hibernate.type.SerializationException;
import org.hibernate.type.Type;

import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Cause;
import org.jboss.logging.LogMessage;
import org.jboss.logging.Message;
import org.jboss.logging.MessageLogger;

/**
* The jboss-logging {@link MessageLogger} for the hibernate-core module. It reserves message ids ranging from
Expand Down Expand Up @@ -1619,12 +1619,4 @@ void cannotResolveNonNullableTransientDependencies(String transientEntityString,
@LogMessage(level = INFO)
@Message( value = "'javax.persistence.validation.mode' named multiple values : %s", id = 448 )
void multipleValidationModes(String modes);

@LogMessage(level = WARN)
@Message(value = "Exception while loading a class or resource found during scanning", id = 449)
void unableToLoadScannedClassOrResource(@Cause Exception e);

@LogMessage(level = WARN)
@Message(value = "Exception while discovering OSGi service implementations : %s", id = 450)
void unableToDiscoverOsgiService(String service, @Cause Exception e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public EntityManagerFactory createEntityManagerFactory(String persistenceUnitNam
}

protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties) {
return getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties, null );
}

protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map properties, ClassLoader providedClassLoader) {
log.tracef( "Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s", persistenceUnitName );

final Map integration = wrap( properties );
Expand Down Expand Up @@ -118,7 +122,7 @@ protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(Strin
continue;
}

return Bootstrap.getEntityManagerFactoryBuilder( persistenceUnit, integration );
return Bootstrap.getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoader );
}

log.debug( "Found no matching persistence units" );
Expand Down
94 changes: 94 additions & 0 deletions hibernate-osgi/hibernate-osgi.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
configurations {
osgiRuntime
}

sourceSets {
testResult
testClientBundle
}

sourceSets.test {
compileClasspath += sourceSets.testResult.output
runtimeClasspath += sourceSets.testResult.output
}

sourceSets.testClientBundle {
compileClasspath += sourceSets.testResult.output
runtimeClasspath += sourceSets.testResult.output
}

dependencies {
compile( project( ':hibernate-core' ) )
compile( project( ':hibernate-entitymanager' ) )
// MUST use 4.3.1! 4.3.0 was compiled with "-target jsr14".
// http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html
compile( "org.osgi:org.osgi.core:4.3.1" )

testCompile( libraries.shrinkwrap_api )
testCompile( libraries.shrinkwrap )
testCompile( "org.jboss.arquillian.junit:arquillian-junit-container:1.0.3.Final" )
testCompile( "org.jboss.osgi.metadata:jbosgi-metadata:3.0.0.CR1" )
testRuntime( "org.jboss.arquillian.container:arquillian-osgi-felix:2.0.0.CR4" )
testRuntime( "org.apache.felix:org.apache.felix.framework:4.0.3" )
testRuntime( "org.apache.felix:org.apache.felix.main:4.0.3" )
testRuntime( "org.jboss.logmanager:jboss-logmanager:1.4.1.Final" )

osgiRuntime( "org.jboss.arquillian.osgi:arquillian-osgi-bundle:1.0.3.Final" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation of the OSGi dep's seems odd.

osgiRuntime( "org.ops4j.pax.url:pax-url-wrap:1.5.2" )
osgiRuntime( "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0-SNAPSHOT" )
osgiRuntime( "javax.enterprise:cdi-api:1.1-PFD" )
osgiRuntime( "org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec:1.0.0.Alpha1" )
osgiRuntime( "org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.0.0.Alpha1" )
osgiRuntime( "commons-collections:commons-collections:3.2.1" )
osgiRuntime( "commons-pool:commons-pool:1.6" )
osgiRuntime( "commons-dbcp:commons-dbcp:1.4" )
osgiRuntime( "commons-lang:commons-lang:2.6" )
osgiRuntime( "net.sourceforge.serp:serp:1.14.1" )
osgiRuntime( "com.h2database:h2:1.3.170" )
osgiRuntime( "org.apache.servicemix.bundles:org.apache.servicemix.bundles.antlr:2.7.7_5" )
osgiRuntime( "org.jboss.javassist:com.springsource.javassist:3.15.0.GA" )
osgiRuntime( "org.apache.servicemix.specs:org.apache.servicemix.specs.jsr303-api-1.0.0:2.2.0" )
osgiRuntime( "org.apache.servicemix.bundles:org.apache.servicemix.bundles.ant:1.8.2_2" )
osgiRuntime( "org.apache.servicemix.specs:org.apache.servicemix.specs.stax-api-1.2:2.2.0" )
osgiRuntime( "org.apache.servicemix.bundles:org.apache.servicemix.bundles.dom4j:1.6.1_5" )
osgiRuntime( "org.hibernate.common:hibernate-commons-annotations:4.0.2.Final" )
osgiRuntime( "org.jboss:jandex:1.1.0.Alpha1" )
osgiRuntime( "com.fasterxml:classmate:0.5.4" )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClasMate 0.8.0 is referenced in ../libraries.gradle (some other libs as well, commons-annotations, jandex etc.).

osgiRuntime( "org.jboss.logging:jboss-logging:3.1.0.GA" )

testClientBundleCompile( project( ':hibernate-core' ) )
testClientBundleCompile( project( ':hibernate-entitymanager' ) )
// MUST use 4.3.1! 4.3.0 was compiled with "-target jsr14".
// http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html
testClientBundleCompile( "org.osgi:org.osgi.core:4.3.1" )
}

def pomName() {
Expand All @@ -26,3 +83,40 @@ jar {
'javax.persistence.spi;version="2.1.0"'
}
}

task copyBnd(type: Copy) {
into "$buildDir/osgi-lib/bnd"
from "src/test/resources/bnd"
}

task runBnd(type: JavaExec){
main = "-jar"
args "$buildDir/osgi-lib/bnd/bnd.jar", "$buildDir/osgi-lib/bnd/cdi-api.bnd", "$buildDir/osgi-lib/bnd/el-api.bnd", "$buildDir/osgi-lib/bnd/jandex.bnd", "$buildDir/osgi-lib/bnd/serp.bnd"
}

task copyToLib(type: Copy) {
into "$buildDir/osgi-lib"
from configurations.osgiRuntime
}

task testClientBundleJar(type: Jar) {
from sourceSets.testClientBundle.output, sourceSets.testResult.output
destinationDir new File("$buildDir/osgi-lib")
archiveName "testClientBundle.jar"

// The OSGi plugin acts up when we need to export multiple source sets. Just do it manually.
manifest {
attributes("Export-Package" : "org.hibernate.osgi.test.client,org.hibernate.osgi.test.result",
"Bundle-Name" : "testClientBundle",
"Bundle-Activator" : "org.hibernate.osgi.test.client.OsgiTestActivator",
"Bundle-ManifestVersion" : "2",
"Bundle-SymbolicName" : "testClientBundle",
"Import-Package" : "javassist.util.proxy,javax.persistence,javax.persistence.spi,org.h2,org.hibernate,org.hibernate.proxy,org.osgi.framework")
}
}

runBnd.dependsOn copyToLib
runBnd.dependsOn copyBnd
test.dependsOn runBnd
test.dependsOn testClientBundleJar
test.dependsOn jar
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import javax.persistence.PersistenceException;

import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.jpa.boot.archive.spi.ArchiveContext;
import org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.jpa.boot.archive.spi.ArchiveEntry;
Expand All @@ -43,10 +42,7 @@
* @author Tim Ward
*/
public class OsgiArchiveDescriptor implements ArchiveDescriptor {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
OsgiArchiveDescriptor.class.getName()
);
private static final Logger LOG = Logger.getLogger( OsgiArchiveDescriptor.class );

private final Bundle persistenceBundle;
private final BundleWiring bundleWiring;
Expand Down Expand Up @@ -119,7 +115,7 @@ public InputStreamAccess getStreamAccess() {
context.obtainArchiveEntryHandler( entry ).handleEntry( entry, context );
}
catch ( Exception e ) {
LOG.unableToLoadScannedClassOrResource( e );
LOG.warn( "Exception while loading a class or resource found during scanning", e );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.IntegratorProvider;
import org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList;
import org.hibernate.jpa.boot.spi.TypeContributorList;
Expand Down Expand Up @@ -90,7 +92,8 @@ public EntityManagerFactory createEntityManagerFactory(String persistenceUnitNam

osgiClassLoader.addBundle( requestingBundle );

return super.createEntityManagerFactory( persistenceUnitName, settings );
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, settings, osgiClassLoader );
return builder == null ? null : builder.build();
}

@Override
Expand All @@ -106,7 +109,7 @@ public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitI

osgiClassLoader.addClassLoader( info.getClassLoader() );

return super.createContainerEntityManagerFactory( info, settings );
return Bootstrap.getEntityManagerFactoryBuilder( info, settings, osgiClassLoader ).build();
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Collection;
import java.util.List;

import org.hibernate.internal.CoreMessageLogger;
import org.jboss.logging.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
Expand All @@ -35,10 +34,7 @@
* @author Brett Meyer
*/
public class OsgiServiceUtil {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(
CoreMessageLogger.class,
OsgiServiceUtil.class.getName()
);
private static final Logger LOG = Logger.getLogger( OsgiServiceUtil.class );

/**
* Locate all implementors of the given service contract in the given OSGi buindle context
Expand All @@ -58,7 +54,7 @@ public static <T> List<T> getServiceImpls(Class<T> contract, BundleContext conte
}
}
catch ( Exception e ) {
LOG.unableToDiscoverOsgiService( contract.getName(), e );
LOG.warnf( e, "Exception while discovering OSGi service implementations : %s", contract.getName() );
}
return serviceImpls;
}
Expand Down
Loading