HHH-14518 : drop `hibernate-osgi` module

This commit is contained in:
Steve Ebersole 2021-05-14 15:03:07 -05:00
parent c7e37dc1d7
commit af3031a3d5
33 changed files with 0 additions and 2332 deletions

View File

@ -1,17 +0,0 @@
hibernate-osgi Test Debugging
=============================
Here's a quick tip for debugging hibernate-osgi test failures. Sometimes, a dependency or code change will result
in an error that looks like the following:
Caused by: java.lang.ClassNotFoundException: *** Class 'org.hibernate.osgi.test.OsgiTestCase' was not found, but
this is likely normal since package 'org.hibernate.osgi.test' is dynamically imported by bundle
arquillian-osgi-bundle [5]. However, bundle hibernate-osgi-test [20] does export this package with attributes that
do not match. ***
That error is extremely misleading and is not the actual problem. To get to the root issue, open this file:
hibernate-osgi/target/test-results/TEST-org.hibernate.osgi.test.OsgiTestCase.xml
The root issue will usually be embedded half-way through. More often than not, searching for
*org.osgi.framework.BundleException* will find it.

View File

@ -1,272 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
description = 'Support for running Hibernate O/RM in OSGi environments'
apply from: rootProject.file( 'gradle/published-java-module.gradle' )
apply plugin: 'com.github.lburgazzoli.karaf'
ext {
osgiCoreVersion = '6.0.0'
osgiCompediumVersion = '5.0.0'
karafVersion = '4.2.1'
paxExamVersion = '4.12.0'
}
/*
* With the current karaf/pax-exam versions and with JDK11.0.3,
* we get errors like "java.lang.IllegalStateException: Unknown protocol: jrt".
*
* This is suspiciously similar to the problems we had on Hibernate Search,
* and we gave up the idea of fixing those after a few hours.
*
* Copy-pasting the explanation from Search (not sure it applies here, but it's likely):
* > Upgrading to Karaf 4.2.5 fixes that, but then we get errors about "/karaf.log" not being accessible.
* > Upgrading once again to Pax-exam 4.13.1 fixes that, but then startup looks stuck at some point,
* > without any particular error even if we raise all the different log levels to "trace".
* > Upgrading pax-url to 2.6.1 to be in line with the versions in the Karaf pom doesn't change anything.
* > Strangely, with these upgrades, everything still works fine with JDK8,
* > but we get in trouble with JDK11.0.0 and above.
* > A bit ironic since the problems we were trying to solve initially only affected JDK11.0.3,
* > not JDK11.0.0.
*/
if ( gradle.ext.javaVersions.test.launcher.asInt() >= 11 ) {
logger.warn( '[WARN] Skipping all tests for hibernate-osgi due to Karaf/Pax-Exam issues with latest JDK 11' )
test.enabled = false
}
sourceSets {
test {
// send javac output and resource copying to the same output directory for test
// so Pax Exam can more easily find it without explicit TinyBundle hooks
java.outputDir = file( "${buildDir}/classes/test" )
output.resourcesDir = java.outputDir
}
}
configurations {
karafDistro {
description = 'Configuration used to isolate the dependency on the Karaf distro'
transitive = false
}
hibernateEnvers {
description = 'Feature for easily adding Envers support to hibernate-orm'
transitive = false
}
}
dependencies {
compile( project( ':hibernate-core' ) ) {
// having javax.activation-api as a dependency requires us to have com.sun.activation:javax.activation
// this dependency wasn't there in the 5.2.x bundles so ignoring it for now
// we might reintroduce it at some point if users complain about it
exclude module: 'javax.activation-api'
// JAXB is included in the Karaf distribution
exclude module: 'jaxb-api'
exclude module: 'jaxb-runtime'
}
testCompile( project( ':hibernate-envers' ) )
compile "org.osgi:org.osgi.core:${osgiCoreVersion}"
compile "org.osgi:org.osgi.compendium:${osgiCompediumVersion}"
compile "net.bytebuddy:byte-buddy:${byteBuddyVersion}"
// Needed by JBoss JTA
runtime( libraries.interceptor )
testCompile "org.ops4j.pax.exam:pax-exam:${project.paxExamVersion}"
testCompile "org.ops4j.pax.exam:pax-exam-junit4:${project.paxExamVersion}"
testCompile "org.ops4j.pax.exam:pax-exam-container-karaf:${project.paxExamVersion}"
// Need this explicitly in order to use @Inject -> shouldn't this be a transtive dep of pax-exam?
// is there ever a pax exam test that *does not* use this?
testCompile 'javax.inject:javax.inject:1'
testCompile( "org.apache.karaf:apache-karaf:${project.karafVersion}" ) {
// having trouble finding this one locally
exclude group: 'org.eclipse', module: 'org.eclipse.osgi'
exclude group: 'org.hibernate', module: 'hibernate-osgi'
}
karafDistro "org.apache.karaf:apache-karaf:${project.karafVersion}@tar.gz"
hibernateEnvers( project( ':hibernate-envers' ) )
hibernateEnvers( libraries.dom4j )
}
jar {
manifest {
attributes(
// BND Plugin instructions (for OSGi):
'Bundle-Activator': 'org.hibernate.osgi.HibernateBundleActivator',
'Provide-Capability': 'osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider',
'Import-Package': [
// TODO: Shouldn't have to explicitly list this, but the plugin
// generates it with a [1.0,2) version.
"javax.persistence;version=\"${project.jpaVersion.osgiName}\"",
"javax.persistence.spi;version=\"${project.jpaVersion.osgiName}\"",
// Temporarily support JTA 1.1 -- Karaf and other frameworks still
// use it. Without this, the plugin generates [1.2,2).
'javax.transaction;version="[1.1,2)"',
// Also import every package referenced in the code
'*'
].join( ',' )
)
}
}
task generateVersionFile {
File outputFileDir = project.file( "${buildDir}/classes/test/META-INF/hibernate-osgi/" )
File outputFile = new File( outputFileDir, 'Version.txt' )
inputs.property( "version", project.version )
outputs.file outputFile
doFirst {
outputFileDir.mkdirs()
def writer = new FileWriter( outputFile )
try {
writer.write( "${project.version}" )
writer.flush()
}
finally {
writer.close()
}
}
}
karaf {
features {
xsdVersion = '1.4.0'
feature {
name = 'hibernate-orm'
description = 'Combines all Hibernate core dependencies and required modules into a single feature'
includeProject = true
feature ('wrap') {
prerequisite = true
}
feature 'transaction-api'
// Most Hibernate modules declare OSGi metadata through blueprints, so we need this feature
feature 'aries-blueprint'
}
// NOTE : would like to include spatial as well, but we need to wait for
// it to not define dependency on postgresql driver
feature {
name = 'hibernate-envers'
description = 'Feature for easily adding Envers support to hibernate-orm'
includeProject = false
feature ('wrap') {
prerequisite = true
}
configurations 'hibernateEnvers'
feature('hibernate-orm') {
version = project.version
}
}
// The hibernate-infinispan feature is now provided by the Infinispan project.
}
}
task generateDependsFile {
// In order to fully use org.ops4j.pax.exam.CoreOptions.maven() stuff
// we need to generate a META-INF/maven/dependencies.properties file
// just like the generate-depends-file Maven goal from ServiceMix/Karaf
File outputFileDir = project.file( 'target/classes/test/META-INF/maven/' )
File outputFile = new File( outputFileDir, 'dependencies.properties' )
outputs.file outputFile
doFirst {
outputFileDir.mkdirs()
Properties properties = new Properties();
// first we add our GAV info
properties.setProperty( "groupId", "${project.group}" );
properties.setProperty( "artifactId", project.name );
properties.setProperty( "version", "${project.version}" );
properties.setProperty( "${project.group}/${project.name}/version", "${project.version}" );
// then for all our deps
project.configurations.testRuntime.resolvedConfiguration.resolvedArtifacts.each {
final String keyBase = it.moduleVersion.id.group + '/' + it.moduleVersion.id.name;
properties.setProperty( "${keyBase}/scope", "compile" )
properties.setProperty( "${keyBase}/type", it.extension )
properties.setProperty( "${keyBase}/version", it.moduleVersion.id.version )
}
FileOutputStream outputStream = new FileOutputStream( outputFile );
try {
properties.store( outputStream, "Generated from Gradle by Hibernate build for PaxExam testing of hibernate-osgi module" )
}
finally {
outputStream.close()
}
}
}
task generatePaxExamEnvironmentFile {
// I found this better/easier than duplicating information...
description = 'Generates a Properties file that the Pax Exam test can access to know information about the test environment'
File outputFile = new File( sourceSets.test.output.resourcesDir, 'pax-exam-environment.properties' )
File karafUnpackDirectory = file( "${buildDir}/karaf-unpack" )
// set up up-to-date checks
inputs.files( configurations.testRuntime )
inputs.property( 'karafUnpackDirectory', karafUnpackDirectory )
outputs.file( outputFile )
doFirst {
// should only be one artifacts..
File karafDistroFile = configurations.karafDistro.resolvedConfiguration.resolvedArtifacts[0].file
Properties properties = new Properties();
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.distroUrl', karafDistroFile.toURI().toURL().toExternalForm() )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.unpackDir', karafUnpackDirectory.absolutePath )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.version', karafVersion as String )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.probe.classesDir', sourceSets.test.java.outputDir.absolutePath )
properties.setProperty( 'org.ops4j.pax.exam.container.karaf.probe.resourcesDir', sourceSets.test.output.resourcesDir.absolutePath )
properties.setProperty( 'org.hibernate.osgi.test.karafFeatureFile', karaf.features.outputFile.absolutePath )
outputFile.parentFile.mkdirs()
FileOutputStream outputStream = new FileOutputStream( outputFile );
try {
properties.store( outputStream, "Generated from Gradle by Hibernate build for PaxExam testing of hibernate-osgi module" )
}
finally {
outputStream.close()
}
}
}
tasks.test.dependsOn tasks.generateFeatures
tasks.test.dependsOn tasks.jar
tasks.test.dependsOn tasks.generateDependsFile
tasks.test.dependsOn tasks.generatePaxExamEnvironmentFile
// we also need to make sure that hibernate-core, hibernate-entitymanager and hibernate-osgi
// are published to maven-local before running tests
tasks.test.dependsOn rootProject.childProjects.'hibernate-core'.tasks.publishToMavenLocal
tasks.test.dependsOn rootProject.childProjects.'hibernate-envers'.tasks.publishToMavenLocal
tasks.test.dependsOn tasks.publishToMavenLocal
publishing {
publications {
publishedArtifacts( MavenPublication ) {
artifact( project.extensions.karaf.features.outputFile ) {
classifier 'karaf'
builtBy generateFeatures
}
}
}
}

View File

@ -1,81 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.util.Dictionary;
import java.util.Hashtable;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
/**
* This BundleActivator provides three different uses of Hibernate in OSGi
* environments:
*
* 1.) Enterprise OSGi JPA: The OSGi container/runtime is in charge of managing
* all of the client bundles' persistence units. The container/runtime is
* also in charge of creating and managing the EntityManagerFactory through a
* registered PersistenceProvider (this).
* 2.) Un-managed OSGI JPA: Same as #1, but the container does not manage
* the persistence units. Client bundles identify a typical
* PersistenceProvider, registered by this activator.
* 3.) Client bundles create and manage their own SessionFactory. A
* SessionFactory is registered as an OSGi ServiceFactory -- each requesting
* bundle gets its own instance of a SessionFactory. The use of services,
* rather than manual building of the SessionFactory, is necessary to shield users
* from ClassLoader issues. See {@link OsgiSessionFactoryService} for more
* information.
*
* @author Brett Meyer
* @author Tim Ward
*/
@SuppressWarnings("UnusedDeclaration")
public class HibernateBundleActivator implements BundleActivator {
private OsgiServiceUtil osgiServiceUtil;
private ServiceRegistration<?> persistenceProviderService;
private ServiceRegistration<?> sessionFactoryService;
@Override
@SuppressWarnings("unchecked")
public void start(BundleContext context) throws Exception {
osgiServiceUtil = new OsgiServiceUtil( context );
// Build a JtaPlatform specific for this OSGi context
final OsgiJtaPlatform osgiJtaPlatform = new OsgiJtaPlatform( osgiServiceUtil );
final Dictionary properties = new Hashtable();
// In order to support existing persistence.xml files, register using the legacy provider name.
properties.put( "javax.persistence.provider", HibernatePersistenceProvider.class.getName() );
persistenceProviderService = context.registerService(
PersistenceProvider.class.getName(),
new OsgiPersistenceProviderService( osgiJtaPlatform, osgiServiceUtil ),
properties
);
sessionFactoryService = context.registerService(
SessionFactory.class.getName(),
new OsgiSessionFactoryService( osgiJtaPlatform, osgiServiceUtil ),
new Hashtable()
);
}
@Override
public void stop(BundleContext context) throws Exception {
osgiServiceUtil.stop();
osgiServiceUtil = null;
persistenceProviderService.unregister();
persistenceProviderService = null;
sessionFactoryService.unregister();
sessionFactoryService = null;
}
}

View File

@ -1,52 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.util.LinkedHashSet;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
/**
* The ClassLoaderService that should be used when running in OSGi;
* this helps for example to load the Services correctly.
*
* @author Sanne Grinovero
*/
public class OSGiClassLoaderServiceImpl extends ClassLoaderServiceImpl implements ClassLoaderService {
private final OsgiServiceUtil osgiServiceUtil;
private final OsgiClassLoader osgiClassLoader;
public OSGiClassLoaderServiceImpl(OsgiClassLoader osgiClassLoader, OsgiServiceUtil osgiServiceUtil) {
super( osgiClassLoader );
this.osgiClassLoader = osgiClassLoader;
this.osgiServiceUtil = osgiServiceUtil;
}
@Override
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
Iterable<S> parentDiscoveredServices = super.loadJavaServices( serviceContract );
S[] serviceImpls = osgiServiceUtil.getServiceImpls(serviceContract);
LinkedHashSet<S> composite = new LinkedHashSet<S>();
for ( S service : parentDiscoveredServices ) {
composite.add( service );
}
for ( S service : serviceImpls ) {
composite.add( service );
}
return composite;
}
@Override
public void stop() {
super.stop();
osgiClassLoader.stop();
osgiServiceUtil.stop();
}
}

View File

@ -1,105 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import javax.persistence.PersistenceException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.boot.archive.spi.ArchiveContext;
import org.hibernate.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.boot.archive.spi.ArchiveEntry;
import org.hibernate.boot.archive.spi.InputStreamAccess;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleWiring;
/**
* ArchiveDescriptor implementation for describing archives in the OSGi sense
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiArchiveDescriptor implements ArchiveDescriptor {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( OsgiArchiveDescriptor.class );
private final Bundle persistenceBundle;
private final BundleWiring bundleWiring;
/**
* Creates a OsgiArchiveDescriptor
*
* @param persistenceBundle The bundle being described as an archive
*/
@SuppressWarnings("RedundantCast")
public OsgiArchiveDescriptor(Bundle persistenceBundle) {
this.persistenceBundle = persistenceBundle;
bundleWiring = (BundleWiring) persistenceBundle.adapt( BundleWiring.class );
}
@Override
public void visitArchive(ArchiveContext context) {
final Collection<String> resources = bundleWiring.listResources( "/", "*", BundleWiring.LISTRESOURCES_RECURSE );
for ( final String resource : resources ) {
// TODO: Is there a better way to check this? Karaf is including directories.
if ( !resource.endsWith( "/" ) ) {
try {
// TODO: Is using resource as the names correct?
final InputStreamAccess inputStreamAccess = new InputStreamAccess() {
@Override
public String getStreamName() {
return resource;
}
@Override
public InputStream accessInputStream() {
return openInputStream();
}
private InputStream openInputStream() {
try {
return persistenceBundle.getResource( resource ).openStream();
}
catch ( IOException e ) {
throw new PersistenceException(
"Unable to open an InputStream on the OSGi Bundle resource!",
e );
}
}
};
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return resource;
}
@Override
public String getNameWithinArchive() {
return resource;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
context.obtainArchiveEntryHandler( entry ).handleEntry( entry, context );
}
catch ( Exception e ) {
LOG.unableToLoadScannedClassOrResource( e );
}
}
}
}
}

View File

@ -1,55 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.net.URL;
import org.hibernate.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.osgi.framework.Bundle;
/**
* ArchiveDescriptorFactory implementation for OSGi environments
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiArchiveDescriptorFactory implements ArchiveDescriptorFactory {
private Bundle persistenceBundle;
/**
* Creates a OsgiArchiveDescriptorFactory
*
* @param persistenceBundle The OSGi bundle being scanned
*/
public OsgiArchiveDescriptorFactory(Bundle persistenceBundle) {
this.persistenceBundle = persistenceBundle;
}
@Override
public ArchiveDescriptor buildArchiveDescriptor(URL url) {
return buildArchiveDescriptor( url, "" );
}
@Override
public ArchiveDescriptor buildArchiveDescriptor(URL url, String entry) {
return new OsgiArchiveDescriptor( persistenceBundle );
}
@Override
public URL getJarURLFromURLEntry(URL url, String entry) throws IllegalArgumentException {
// not used
return null;
}
@Override
public URL getURLFromPath(String jarPath) {
// not used
return null;
}
}

View File

@ -1,233 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.hibernate.service.spi.Stoppable;
import org.osgi.framework.Bundle;
/**
* Custom OSGI ClassLoader helper which knows all the "interesting"
* class loaders and bundles. Encapsulates the OSGi related CL capabilities.
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiClassLoader extends ClassLoader implements Stoppable {
// Leave these as Sets -- addClassLoader or addBundle may be called more
// than once if a SF or EMF is closed and re-created.
// HHH-12553: must be thread-safe. Concurrent impl. would be best, but we have to retain insertion-order.
private Set<ClassLoader> classLoaders = Collections.synchronizedSet(new LinkedHashSet<ClassLoader>());
private Set<Bundle> bundles = Collections.synchronizedSet(new LinkedHashSet<Bundle>());
private ConcurrentMap<String, Class<?>> classCache = new ConcurrentHashMap<String, Class<?>>();
private ConcurrentMap<String, URL> resourceCache = new ConcurrentHashMap<String, URL>();
static {
ClassLoader.registerAsParallelCapable();
}
public OsgiClassLoader() {
// DO NOT use ClassLoader#parent, which is typically the SystemClassLoader for most containers. Instead,
// allow the ClassNotFoundException to be thrown. ClassLoaderServiceImpl will check the SystemClassLoader
// later on. This is especially important for embedded OSGi containers, etc.
super( null );
}
/**
* Load the class and break on first found match.
*
* TODO: Should this throw a different exception or warn if multiple
* classes were found? Naming collisions can and do happen in OSGi...
*/
@Override
@SuppressWarnings("rawtypes")
protected Class<?> findClass(String name) throws ClassNotFoundException {
Class< ? > cachedClass = classCache.get( name );
if ( cachedClass != null ) {
return cachedClass;
}
synchronized (bundles) {
for ( Bundle bundle : bundles ) {
try {
final Class clazz = bundle.loadClass( name );
if ( clazz != null ) {
classCache.put( name, clazz );
return clazz;
}
}
catch ( Exception ignore ) {
}
}
}
synchronized (classLoaders) {
for ( ClassLoader classLoader : classLoaders ) {
try {
final Class clazz = classLoader.loadClass( name );
if ( clazz != null ) {
classCache.put( name, clazz );
return clazz;
}
}
catch ( Exception ignore ) {
}
}
}
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
/**
* Load the class and break on first found match.
*
* TODO: Should this throw a different exception or warn if multiple
* classes were found? Naming collisions can and do happen in OSGi...
*/
@Override
protected URL findResource(String name) {
URL cachedResource = resourceCache.get( name );
if ( cachedResource != null ) {
return cachedResource;
}
synchronized (bundles) {
for ( Bundle bundle : bundles ) {
try {
final URL resource = bundle.getResource( name );
if ( resource != null ) {
resourceCache.put( name, resource );
return resource;
}
}
catch ( Exception ignore ) {
}
}
}
synchronized (classLoaders) {
for ( ClassLoader classLoader : classLoaders ) {
try {
final URL resource = classLoader.getResource( name );
if ( resource != null ) {
resourceCache.put( name, resource );
return resource;
}
}
catch ( Exception ignore ) {
}
}
}
// TODO: Error?
return null;
}
/**
* Load the class and break on first found match.
*
* Note: Since they're Enumerations, do not cache these results!
*
* TODO: Should this throw a different exception or warn if multiple
* classes were found? Naming collisions can and do happen in OSGi...
*/
@Override
@SuppressWarnings("unchecked")
protected Enumeration<URL> findResources(String name) {
final List<Enumeration<URL>> enumerations = new ArrayList<Enumeration<URL>>();
synchronized (bundles) {
for ( Bundle bundle : bundles ) {
try {
final Enumeration<URL> resources = bundle.getResources( name );
if ( resources != null ) {
enumerations.add( resources );
}
}
catch ( Exception ignore ) {
}
}
}
synchronized (classLoaders) {
for ( ClassLoader classLoader : classLoaders ) {
try {
final Enumeration<URL> resources = classLoader.getResources( name );
if ( resources != null ) {
enumerations.add( resources );
}
}
catch ( Exception ignore ) {
}
}
}
final Enumeration<URL> aggEnumeration = new Enumeration<URL>() {
@Override
public boolean hasMoreElements() {
for ( Enumeration<URL> enumeration : enumerations ) {
if ( enumeration != null && enumeration.hasMoreElements() ) {
return true;
}
}
return false;
}
@Override
public URL nextElement() {
for ( Enumeration<URL> enumeration : enumerations ) {
if ( enumeration != null && enumeration.hasMoreElements() ) {
return enumeration.nextElement();
}
}
throw new NoSuchElementException();
}
};
return aggEnumeration;
}
/**
* Adds a ClassLoader to the wrapped set of ClassLoaders
*
* @param classLoader The ClassLoader to add
*/
public void addClassLoader( ClassLoader classLoader ) {
classLoaders.add( classLoader );
}
/**
* Adds a Bundle to the wrapped set of Bundles
*
* @param bundle The Bundle to add
*/
public void addBundle( Bundle bundle ) {
bundles.add( bundle );
}
@Override
public void stop() {
classLoaders.clear();
bundles.clear();
classCache.clear();
resourceCache.clear();
}
}

View File

@ -1,99 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import org.hibernate.TransactionException;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
/**
* Offers the JTA Platform provided by the OSGi container. The Enterprise
* OSGi spec requires all containers to register UserTransaction
* and TransactionManager OSGi services.
*
* @author Brett Meyer
*/
public class OsgiJtaPlatform implements JtaPlatform {
private static final long serialVersionUID = 1L;
private OsgiServiceUtil osgiServiceUtil;
/**
* Constructs a OsgiJtaPlatform
*/
public OsgiJtaPlatform(OsgiServiceUtil osgiServiceUtil) {
this.osgiServiceUtil = osgiServiceUtil;
}
@Override
public TransactionManager retrieveTransactionManager() {
try {
final TransactionManager transactionManager = osgiServiceUtil.getServiceImpl(
TransactionManager.class );
if (transactionManager == null) {
throw new TransactionException("Cannot retrieve the TransactionManager OSGi service!");
}
return transactionManager;
}
catch (Exception e) {
throw new TransactionException("Cannot retrieve the TransactionManager OSGi service!", e);
}
}
@Override
public UserTransaction retrieveUserTransaction() {
try {
final UserTransaction userTransaction = osgiServiceUtil.getServiceImpl(
UserTransaction.class );
if (userTransaction == null) {
throw new TransactionException("Cannot retrieve the UserTransaction OSGi service!");
}
return userTransaction;
}
catch (Exception e) {
throw new TransactionException("Cannot retrieve the UserTransaction OSGi service!", e);
}
}
@Override
public Object getTransactionIdentifier(Transaction transaction) {
// AbstractJtaPlatform just uses the transaction itself.
return transaction;
}
@Override
public boolean canRegisterSynchronization() {
try {
return JtaStatusHelper.isActive( retrieveTransactionManager() );
}
catch (Exception e) {
return false;
}
}
@Override
public void registerSynchronization(Synchronization synchronization) {
try {
retrieveTransactionManager().getTransaction().registerSynchronization( synchronization );
}
catch (Exception e) {
throw new TransactionException( "Could not obtain transaction from OSGi services!" );
}
}
@Override
public int getCurrentStatus() throws SystemException {
return retrieveTransactionManager().getStatus();
}
}

View File

@ -1,146 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceUnitInfo;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.cfg.AvailableSettings;
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;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;
/**
* Acts as the PersistenceProvider service in OSGi environments
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiPersistenceProvider extends HibernatePersistenceProvider {
private OsgiClassLoader osgiClassLoader;
private OsgiJtaPlatform osgiJtaPlatform;
private OsgiServiceUtil osgiServiceUtil;
private Bundle requestingBundle;
/**
* Constructs a OsgiPersistenceProvider
*
* @param osgiClassLoader The ClassLoader we built from OSGi Bundles
* @param osgiJtaPlatform The OSGi-specific JtaPlatform impl we built
* @param requestingBundle The OSGi Bundle requesting the PersistenceProvider
*/
public OsgiPersistenceProvider(
OsgiClassLoader osgiClassLoader,
OsgiJtaPlatform osgiJtaPlatform,
OsgiServiceUtil osgiServiceUtil,
Bundle requestingBundle) {
this.osgiClassLoader = osgiClassLoader;
this.osgiJtaPlatform = osgiJtaPlatform;
this.osgiServiceUtil = osgiServiceUtil;
this.requestingBundle = requestingBundle;
}
// TODO: Does "hibernate.classloaders" and osgiClassLoader need added to the
// EMFBuilder somehow?
@Override
@SuppressWarnings("unchecked")
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
final Map settings = generateSettings( properties );
// TODO: This needs tested.
settings.put( org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner( requestingBundle ) );
// TODO: This is temporary -- for PersistenceXmlParser's use of
// ClassLoaderServiceImpl#fromConfigSettings
settings.put( AvailableSettings.ENVIRONMENT_CLASSLOADER, osgiClassLoader );
osgiClassLoader.addBundle( requestingBundle );
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, settings,
new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) );
return builder == null ? null : builder.build();
}
@Override
@SuppressWarnings("unchecked")
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
final Map settings = generateSettings( properties );
// OSGi ClassLoaders must implement BundleReference
final ClassLoader classLoader = info.getClassLoader();
settings.put(
org.hibernate.cfg.AvailableSettings.SCANNER,
new OsgiScanner( ( (BundleReference) classLoader).getBundle() )
);
osgiClassLoader.addClassLoader( classLoader );
final ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader( classLoader );
return Bootstrap.getEntityManagerFactoryBuilder( info, settings,
new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) ).build();
}
finally {
Thread.currentThread().setContextClassLoader( prevCL );
}
}
@SuppressWarnings("unchecked")
private Map generateSettings(Map properties) {
final Map settings = new HashMap();
if ( properties != null ) {
settings.putAll( properties );
}
settings.put( AvailableSettings.JTA_PLATFORM, osgiJtaPlatform );
final Integrator[] integrators = osgiServiceUtil.getServiceImpls( Integrator.class );
final IntegratorProvider integratorProvider = new IntegratorProvider() {
@Override
public List<Integrator> getIntegrators() {
return Arrays.asList( integrators );
}
};
settings.put( EntityManagerFactoryBuilderImpl.INTEGRATOR_PROVIDER, integratorProvider );
final StrategyRegistrationProvider[] strategyRegistrationProviders = osgiServiceUtil.getServiceImpls(
StrategyRegistrationProvider.class );
final StrategyRegistrationProviderList strategyRegistrationProviderList = new StrategyRegistrationProviderList() {
@Override
public List<StrategyRegistrationProvider> getStrategyRegistrationProviders() {
return Arrays.asList( strategyRegistrationProviders );
}
};
settings.put( EntityManagerFactoryBuilderImpl.STRATEGY_REGISTRATION_PROVIDERS, strategyRegistrationProviderList );
final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls( TypeContributor.class );
final TypeContributorList typeContributorList = new TypeContributorList() {
@Override
public List<TypeContributor> getTypeContributors() {
return Arrays.asList( typeContributors );
}
};
settings.put( EntityManagerFactoryBuilderImpl.TYPE_CONTRIBUTORS, typeContributorList );
return settings;
}
}

View File

@ -1,79 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.util.LinkedHashSet;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader;
import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
/**
* See the description on {@link OsgiSessionFactoryService}. This class is similar, providing an
* PersistenceProvider as an OSGi Service.
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiPersistenceProviderService implements ServiceFactory {
private OsgiJtaPlatform osgiJtaPlatform;
private OsgiServiceUtil osgiServiceUtil;
/**
* Constructs a OsgiPersistenceProviderService
*
* @param osgiJtaPlatform The OSGi-specific JtaPlatform created in HibernateBundleActivator
*/
public OsgiPersistenceProviderService(
OsgiJtaPlatform osgiJtaPlatform,
OsgiServiceUtil osgiServiceUtil) {
this.osgiJtaPlatform = osgiJtaPlatform;
this.osgiServiceUtil = osgiServiceUtil;
}
@Override
public Object getService(Bundle requestingBundle, ServiceRegistration registration) {
final OsgiClassLoader osgiClassLoader = new OsgiClassLoader();
// First, add the client bundle that's requesting the OSGi services.
osgiClassLoader.addBundle( requestingBundle );
// Then, automatically add hibernate-core and hibernate-entitymanager. These are needed to load resources
// contained in those jars, such as em's persistence.xml schemas.
osgiClassLoader.addBundle( FrameworkUtil.getBundle( SessionFactory.class ) );
osgiClassLoader.addBundle( FrameworkUtil.getBundle( HibernateEntityManagerFactory.class ) );
// Some "boot time" code does still rely on TCCL. "run time" code should all be using
// ClassLoaderService now.
final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
LinkedHashSet<ClassLoader> newTcclDelegates = new LinkedHashSet<>();
newTcclDelegates.add( osgiClassLoader );
newTcclDelegates.add( originalTccl );
final ClassLoader newTccl = new AggregatedClassLoader(
newTcclDelegates, TcclLookupPrecedence.NEVER
);
Thread.currentThread().setContextClassLoader( newTccl );
try {
return new OsgiPersistenceProvider( osgiClassLoader, osgiJtaPlatform, osgiServiceUtil, requestingBundle );
}
finally {
Thread.currentThread().setContextClassLoader( originalTccl );
}
}
@Override
public void ungetService(Bundle requestingBundle, ServiceRegistration registration, Object service) {
// ?
}
}

View File

@ -1,29 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import org.hibernate.boot.archive.scan.spi.AbstractScannerImpl;
import org.osgi.framework.Bundle;
/**
* OSGi-specific implementation of the Scanner contract. Scans the persistence
* unit Bundle for classes and resources.
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiScanner extends AbstractScannerImpl {
/**
* Constructs the scanner for finding things in a OSGi bundle
*
* @param persistenceBundle The OSGi Bundle to scan
*/
public OsgiScanner(Bundle persistenceBundle) {
super( new OsgiArchiveDescriptorFactory( persistenceBundle ) );
}
}

View File

@ -1,95 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.service.spi.Stoppable;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
/**
* Utilities for dealing with OSGi environments
*
* @author Brett Meyer
*/
public class OsgiServiceUtil implements Stoppable {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( OsgiServiceUtil.class );
private BundleContext context;
private Map<String, ServiceTracker> serviceTrackers = new HashMap<String, ServiceTracker>();
public OsgiServiceUtil(BundleContext context) {
this.context = context;
}
/**
* Locate all implementors of the given service contract in the given OSGi buindle context. Utilizes
* {@link ServiceTracker} (best practice, automatically handles a lot of boilerplate and error conditions).
*
* @param contract The service contract for which to locate implementors
* @param <T> The Java type of the service to locate
* @return All know implementors
*/
public <T> T[] getServiceImpls(Class<T> contract) {
T[] services = (T[]) Array.newInstance( contract, 0 );
final ServiceTracker serviceTracker = getServiceTracker( contract.getName() );
try {
// Yep, this is stupid. But, it's the only way to prevent #getServices from handing us back Object[].
services = (T[]) serviceTracker.getServices( services );
if ( services != null ) {
return services;
}
}
catch (Exception e) {
LOG.unableToDiscoverOsgiService( contract.getName(), e );
}
return services;
}
/**
* Locate the single implementor of the given service contract in the given OSGi buindle context. Utilizes
* {@link ServiceTracker#waitForService(long)}
*
* @param contract The service contract for which to locate implementors
* @param <T> The Java type of the service to locate
* @return All know implementors
*/
public <T> T getServiceImpl(Class<T> contract) {
final ServiceTracker serviceTracker = getServiceTracker( contract.getName() );
try {
return (T) serviceTracker.waitForService( 1000 );
}
catch (Exception e) {
LOG.unableToDiscoverOsgiService( contract.getName(), e );
return null;
}
}
private <T> ServiceTracker getServiceTracker(String contractClassName) {
if ( !serviceTrackers.containsKey( contractClassName ) ) {
final ServiceTracker<T, T> serviceTracker = new ServiceTracker<T, T>( context, contractClassName, null );
serviceTracker.open();
serviceTrackers.put( contractClassName, serviceTracker );
}
return serviceTrackers.get( contractClassName );
}
@Override
public void stop() {
for ( java.util.Map.Entry<String, org.osgi.util.tracker.ServiceTracker> entry : serviceTrackers.entrySet() ) {
entry.getValue().close();
}
serviceTrackers.clear();
}
}

View File

@ -1,155 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader;
import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.CoreMessageLogger;
import org.jboss.logging.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.wiring.BundleWiring;
import java.util.Collection;
import java.util.LinkedHashSet;
/**
* Hibernate 4.2 and 4.3 still heavily rely on TCCL for ClassLoading. Although
* our ClassLoaderService removed some of the reliance, access to the proper ClassLoader
* via TCCL is still required in a few cases where we call out to external libs. An OSGi
* bundle manually creating a SessionFactory would require numerous ClassLoader
* tricks (or may be impossible altogether).
* <p/>
* In order to fully control the TCCL issues and shield users from the
* knowledge, we're requiring that bundles use this OSGi ServiceFactory. It
* configures and provides a SessionFactory as an OSGi service.
* <p/>
* Note that an OSGi ServiceFactory differs from a Service. The ServiceFactory
* allows individual instances of Services to be created and provided to
* multiple client Bundles.
*
* @author Brett Meyer
* @author Tim Ward
*/
public class OsgiSessionFactoryService implements ServiceFactory {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
OsgiSessionFactoryService.class.getName());
private OsgiJtaPlatform osgiJtaPlatform;
private OsgiServiceUtil osgiServiceUtil;
/**
* Constructs a OsgiSessionFactoryService
*
* @param osgiJtaPlatform The OSGi-specific JtaPlatform created in HibernateBundleActivator
* @param osgiServiceUtil Util object built in HibernateBundleActivator
*/
public OsgiSessionFactoryService(OsgiJtaPlatform osgiJtaPlatform, OsgiServiceUtil osgiServiceUtil) {
this.osgiJtaPlatform = osgiJtaPlatform;
this.osgiServiceUtil = osgiServiceUtil;
}
@Override
public Object getService(Bundle requestingBundle, ServiceRegistration registration) {
final OsgiClassLoader osgiClassLoader = new OsgiClassLoader();
// First, add the client bundle that's requesting the OSGi services.
osgiClassLoader.addBundle( requestingBundle );
// Then, automatically add hibernate-core. These are needed to load resources
// contained in the core jar.
osgiClassLoader.addBundle( FrameworkUtil.getBundle(SessionFactory.class) );
// Some "boot time" code does still rely on TCCL. "run time" code should all be using
// ClassLoaderService now.
final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
LinkedHashSet<ClassLoader> newTcclDelegates = new LinkedHashSet<>();
newTcclDelegates.add( osgiClassLoader );
newTcclDelegates.add( originalTccl );
final ClassLoader newTccl = new AggregatedClassLoader(
newTcclDelegates, TcclLookupPrecedence.NEVER
);
Thread.currentThread().setContextClassLoader( newTccl );
try {
return buildSessionFactory( requestingBundle, osgiClassLoader );
}
finally {
Thread.currentThread().setContextClassLoader( originalTccl );
}
}
private Object buildSessionFactory(
Bundle requestingBundle,
OsgiClassLoader osgiClassLoader) {
final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
bsrBuilder.applyClassLoaderService( new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) );
final Integrator[] integrators = osgiServiceUtil.getServiceImpls( Integrator.class );
for ( Integrator integrator : integrators ) {
bsrBuilder.applyIntegrator( integrator );
}
final StrategyRegistrationProvider[] strategyRegistrationProviders
= osgiServiceUtil.getServiceImpls( StrategyRegistrationProvider.class );
for ( StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviders ) {
bsrBuilder.applyStrategySelectors( strategyRegistrationProvider );
}
final BootstrapServiceRegistry bsr = bsrBuilder.build();
final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );
// Allow bundles to put the config file somewhere other than the root level.
final BundleWiring bundleWiring = (BundleWiring) requestingBundle.adapt( BundleWiring.class );
final Collection<String> cfgResources = bundleWiring.listResources(
"/",
"hibernate.cfg.xml",
BundleWiring.LISTRESOURCES_RECURSE
);
if (cfgResources.size() == 0) {
ssrBuilder.configure();
}
else {
if (cfgResources.size() > 1) {
LOG.warn( "Multiple hibernate.cfg.xml files found in the persistence bundle. Using the first one discovered." );
}
String cfgResource = "/" + cfgResources.iterator().next();
ssrBuilder.configure( cfgResource );
}
ssrBuilder.applySetting( AvailableSettings.JTA_PLATFORM, osgiJtaPlatform );
final StandardServiceRegistry ssr = ssrBuilder.build();
final MetadataBuilder metadataBuilder = new MetadataSources( ssr ).getMetadataBuilder();
final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls( TypeContributor.class );
for ( TypeContributor typeContributor : typeContributors ) {
metadataBuilder.applyTypes( typeContributor );
}
return metadataBuilder.build().buildSessionFactory();
}
@Override
public void ungetService(Bundle requestingBundle, ServiceRegistration registration, Object service) {
((SessionFactory) service).close();
}
}

View File

@ -1,11 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
/**
* Main OSGi support classes
*/
package org.hibernate.osgi;

View File

@ -1,410 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Locale;
import java.util.Properties;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.osgi.test.client.AuditedDataPoint;
import org.hibernate.osgi.test.client.DataPoint;
import org.hibernate.osgi.test.client.SomeService;
import org.hibernate.osgi.test.client.TestIntegrator;
import org.hibernate.osgi.test.client.TestStrategyRegistrationProvider;
import org.hibernate.osgi.test.client.TestTypeContributor;
import org.hibernate.type.BasicType;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.apache.karaf.features.BootFinished;
import org.apache.karaf.features.FeaturesService;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.ProbeBuilder;
import org.ops4j.pax.exam.TestProbeBuilder;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.karaf.options.LogLevelOption;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.when;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFileExtend;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
/**
* Tests for hibernate-osgi running within a Karaf container via PaxExam.
*
* @author Steve Ebersole
* @author Brett Meyer
*/
@RunWith( PaxExam.class )
@ExamReactorStrategy( PerClass.class )
public class OsgiIntegrationTest {
private static final boolean DEBUG = false;
private static final String jbossPublicRepository = "https://repository.jboss.org/nexus/content/groups/public-jboss/";
private static final String mavenCentralRepository = "https://repo.maven.apache.org/maven2/";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Prepare the Karaf container
@Configuration
public Option[] config() throws Exception {
final Properties paxExamEnvironment = loadPaxExamEnvironmentProperties();
final boolean debug = ConfigurationHelper.getBoolean(
"org.hibernate.testing.osgi.paxExam.debug",
Environment.getProperties(),
DEBUG
);
return options(
when( debug ).useOptions( debugConfiguration( "5005", true ) ),
karafDistributionConfiguration()
.frameworkUrl( paxExamEnvironment.getProperty( "org.ops4j.pax.exam.container.karaf.distroUrl" ) )
.karafVersion( paxExamEnvironment.getProperty( "org.ops4j.pax.exam.container.karaf.version" ) )
.name( "Apache Karaf" )
.unpackDirectory(
new File(
paxExamEnvironment.getProperty(
"org.ops4j.pax.exam.container.karaf.unpackDir"
)
)
)
.useDeployFolder( false ),
editConfigurationFilePut( // Erase the defaults: Maven Central uses HTTP by default, but HTTPS is required now.
"etc/org.ops4j.pax.url.mvn.cfg",
"org.ops4j.pax.url.mvn.repositories",
mavenCentralRepository
+ "@id=central"
+ ", "
+ jbossPublicRepository
+ "@id=jboss-public-repository"
+ "https://repository.jboss.org/nexus/content/groups/public/"
),
configureConsole().ignoreLocalConsole().ignoreRemoteShell(),
when( debug ).useOptions( keepRuntimeFolder() ),
logLevel( LogLevelOption.LogLevel.INFO ),
// also log to the console, so that the logs are writtten to the test output file
editConfigurationFilePut(
"etc/org.ops4j.pax.logging.cfg",
"log4j2.rootLogger.appenderRef.Console.filter.threshold.level",
"TRACE" // Means "whatever the root logger level is"
),
features( featureXmlUrl( paxExamEnvironment ), "hibernate-orm" ),
features( featureXmlUrl( paxExamEnvironment ), "hibernate-envers" ),
features( testingFeatureXmlUrl(), "hibernate-osgi-testing" )
);
}
private static Properties loadPaxExamEnvironmentProperties() throws IOException {
Properties props = new Properties();
props.load( OsgiIntegrationTest.class.getResourceAsStream( "/pax-exam-environment.properties" ) );
return props;
}
private static String featureXmlUrl(Properties paxExamEnvironment) throws MalformedURLException {
return new File( paxExamEnvironment.getProperty( "org.hibernate.osgi.test.karafFeatureFile" ) ).toURI().toURL().toExternalForm();
}
private String testingFeatureXmlUrl() {
return OsgiIntegrationTest.class.getClassLoader().getResource( "org/hibernate/osgi/test/testing-bundles.xml" )
.toExternalForm();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Prepare the PaxExam probe (the bundle to deploy)
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
System.out.println( "Configuring probe..." );
// Note : I found locally that this part is not needed. But I am leaving this here as I might
// someday have a need for tweaking the probe and I want to remember how it is done...
// // attempt to override PaxExam's default of dynamically importing everything
// probe.setHeader( Constants.DYNAMICIMPORT_PACKAGE, "" );
// // and use defined imports instead
// probe.setHeader(
// Constants.IMPORT_PACKAGE,
// "javax.persistence"
// + ",javax.persistence.spi"
// + ",org.h2"
// + ",org.osgi.framework"
// + ",org.hibernate"
// + ",org.hibernate.envers"
//// + ",org.hibernate.boot.model"
//// + ",org.hibernate.boot.registry.selector"
//// + ",org.hibernate.boot.registry.selector.spi"
//// + ",org.hibernate.cfg"
//// + ",org.hibernate.engine.spi"
//// + ",org.hibernate.integrator.spi"
//// + ",org.hibernate.proxy"
//// + ",org.hibernate.service"
//// + ",org.hibernate.service.spi"
//// + ",org.ops4j.pax.exam.options"
//// + ",org.ops4j.pax.exam"
// );
probe.setHeader( Constants.BUNDLE_ACTIVATOR, "org.hibernate.osgi.test.client.OsgiTestActivator" );
return probe;
}
@BeforeClass
public static void setLocaleToEnglish() {
Locale.setDefault( Locale.ENGLISH );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// The tests
@Inject
protected FeaturesService featuresService;
@Inject
BootFinished bootFinished;
@Inject
@SuppressWarnings("UnusedDeclaration")
private BundleContext bundleContext;
@Test
public void testActivation() throws Exception {
assertTrue( featuresService.isInstalled( featuresService.getFeature( "hibernate-orm" ) ) );
assertTrue( featuresService.isInstalled( featuresService.getFeature( "hibernate-envers" ) ) );
assertActiveBundle( "org.hibernate.orm.core" );
assertActiveBundle( "org.hibernate.orm.envers" );
}
@Test
public void testJpa() throws Exception {
final ServiceReference serviceReference = bundleContext.getServiceReference( PersistenceProvider.class.getName() );
final PersistenceProvider persistenceProvider = (PersistenceProvider) bundleContext.getService( serviceReference );
final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory( "hibernate-osgi-test", null );
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new DataPoint( "Brett" ) );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
DataPoint dp = em.find( DataPoint.class, 1 );
assertNotNull( dp );
assertEquals( "Brett", dp.getName() );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
dp = em.find( DataPoint.class, 1 );
dp.setName( "Brett2" );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
em.createQuery( "delete from DataPoint" ).executeUpdate();
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
dp = em.find( DataPoint.class, 1 );
assertNull( dp );
em.getTransaction().commit();
em.close();
}
@Test
public void testNative() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() );
final SessionFactory sf = (SessionFactory) bundleContext.getService( sr );
Session s = sf.openSession();
s.getTransaction().begin();
s.persist( new DataPoint( "Brett" ) );
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
DataPoint dp = (DataPoint) s.get( DataPoint.class, 1 );
assertNotNull( dp );
assertEquals( "Brett", dp.getName() );
s.getTransaction().commit();
s.close();
dp.setName( "Brett2" );
s = sf.openSession();
s.getTransaction().begin();
s.update( dp );
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
dp = (DataPoint) s.get( DataPoint.class, 1 );
assertNotNull( dp );
assertEquals( "Brett2", dp.getName() );
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
s.createQuery( "delete from DataPoint" ).executeUpdate();
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.getTransaction().begin();
dp = (DataPoint) s.get( DataPoint.class, 1 );
assertNull( dp );
s.getTransaction().commit();
s.close();
}
@Test
public void testNativeEnvers() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() );
final SessionFactory sf = ( SessionFactory )bundleContext.getService( sr );
final Integer adpId;
Session s = sf.openSession();
s.getTransaction().begin();
AuditedDataPoint adp = new AuditedDataPoint( "Chris" );
s.persist( adp );
s.getTransaction().commit();
adpId = adp.getId();
s.close();
s = sf.openSession();
s.getTransaction().begin();
adp = s.get( AuditedDataPoint.class, adpId );
adp.setName( "Chris2" );
s.getTransaction().commit();
s.close();
s = sf.openSession();
AuditReader ar = AuditReaderFactory.get( s );
assertEquals( 2, ar.getRevisions( AuditedDataPoint.class, adpId ).size() );
AuditedDataPoint rev1 = ar.find( AuditedDataPoint.class, adpId, 1 );
AuditedDataPoint rev2 = ar.find( AuditedDataPoint.class, adpId, 2 );
assertEquals( new AuditedDataPoint( adpId, "Chris" ), rev1 );
assertEquals( new AuditedDataPoint( adpId, "Chris2" ), rev2 );
s.close();
}
@Test
public void testJpaEnvers() throws Exception {
final ServiceReference serviceReference = bundleContext.getServiceReference( PersistenceProvider.class.getName() );
final PersistenceProvider persistenceProvider = (PersistenceProvider) bundleContext.getService( serviceReference );
final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory( "hibernate-osgi-test", null );
final Integer adpId;
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
AuditedDataPoint adp = new AuditedDataPoint( "Chris" );
em.persist( adp );
em.getTransaction().commit();
adpId = adp.getId();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
adp = em.find( AuditedDataPoint.class, adpId );
adp.setName( "Chris2" );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
AuditReader ar = AuditReaderFactory.get( em );
assertEquals( 2, ar.getRevisions( AuditedDataPoint.class, adpId ).size() );
AuditedDataPoint rev1 = ar.find( AuditedDataPoint.class, adpId, 1 );
AuditedDataPoint rev2 = ar.find( AuditedDataPoint.class, adpId, 2 );
assertEquals( new AuditedDataPoint( adpId, "Chris" ), rev1 );
assertEquals( new AuditedDataPoint( adpId, "Chris2" ), rev2 );
em.close();
}
@Test
public void testExtensionPoints() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() );
final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService( sr );
assertTrue( TestIntegrator.passed() );
Class impl = sfi.getServiceRegistry().getService( StrategySelector.class ).selectStrategyImplementor( Calendar.class, TestStrategyRegistrationProvider.GREGORIAN );
assertNotNull( impl );
BasicType basicType = sfi.getTypeConfiguration()
.getBasicTypeRegistry()
.getRegisteredType( TestTypeContributor.NAME );
assertNotNull( basicType );
}
@Test
public void testServiceContributorDiscovery() throws Exception {
final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() );
final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService( sr );
assertNotNull( sfi.getServiceRegistry().getService( SomeService.class ) );
}
private void assertActiveBundle(String symbolicName) {
for (Bundle bundle : bundleContext.getBundles()) {
if (bundle.getSymbolicName().equals( symbolicName )) {
Assert.assertEquals(
symbolicName + " was found, but not in an ACTIVE state.", Bundle.ACTIVE, bundle.getState());
return;
}
}
Assert.fail("Could not find bundle: " + symbolicName);
}
}

View File

@ -1,80 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.envers.Audited;
/**
* @author Chris Cranford
*/
@Entity
@Audited
public class AuditedDataPoint {
@Id
@GeneratedValue
private Integer id;
private String name;
AuditedDataPoint() {
}
public AuditedDataPoint(String name) {
this( null, name );
}
public AuditedDataPoint(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
int result;
result = ( id != null ? id.hashCode() : 0 );
result = 31 * result + ( name != null ? name.hashCode() : 0 );
return result;
}
@Override
public boolean equals(Object obj) {
if ( obj == this ) {
return true;
}
if ( !( obj instanceof AuditedDataPoint ) ) {
return false;
}
AuditedDataPoint that = (AuditedDataPoint) obj;
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( name != null ? !name.equals( that.name ) : that.name != null ) {
return false;
}
return true;
}
}

View File

@ -1,51 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
/**
* Entity
*
* @author Brett Meyer
*/
@Entity
public class DataPoint {
@Id
@GeneratedValue( generator = "increment" )
@GenericGenerator( name = "increment", strategy = "increment" )
private Integer id;
private String name;
public DataPoint() {
}
public DataPoint(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,39 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import java.util.Hashtable;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.ServiceContributor;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
/**
* @author Brett Meyer
* @author Steve Ebersole
*/
public class OsgiTestActivator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
// register example extension point services
context.registerService( Integrator.class, new TestIntegrator(), new Hashtable() );
context.registerService( StrategyRegistrationProvider.class, new TestStrategyRegistrationProvider(), new Hashtable() );
context.registerService( TypeContributor.class, new TestTypeContributor(), new Hashtable() );
context.registerService( ServiceContributor.class, new SomeServiceContributor(), new Hashtable() );
}
@Override
public void stop(BundleContext context) throws Exception {
}
}

View File

@ -1,17 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import org.hibernate.service.Service;
/**
* A no-op {@link Service} implementation to verify registration of discovered
* extension points.
*/
public class SomeService implements Service {
}

View File

@ -1,24 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.spi.ServiceContributor;
/**
* A ServiceContributor to register service {@link SomeService}, to test service contributor
* discovery.
*/
public class SomeServiceContributor implements ServiceContributor {
@Override
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
serviceRegistryBuilder.addService( SomeService.class, new SomeService() );
}
}

View File

@ -1,38 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import org.hibernate.boot.Metadata;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
/**
* @author Brett Meyer
*/
public class TestIntegrator implements Integrator {
private static boolean passed = false;
@Override
public void integrate(
Metadata metadata,
SessionFactoryImplementor sessionFactory,
SessionFactoryServiceRegistry serviceRegistry) {
passed = true;
}
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
passed = true;
}
public static boolean passed() {
return passed;
}
}

View File

@ -1,34 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import org.hibernate.boot.registry.selector.SimpleStrategyRegistrationImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
/**
* @author Brett Meyer
*/
public class TestStrategyRegistrationProvider implements StrategyRegistrationProvider {
public static final String GREGORIAN = "gregorian";
@SuppressWarnings("unchecked")
public Iterable<StrategyRegistration> getStrategyRegistrations() {
return Collections.singletonList(
new SimpleStrategyRegistrationImpl(
Calendar.class,
GregorianCalendar.class,
GREGORIAN
)
);
}
}

View File

@ -1,91 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.osgi.test.client;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.usertype.UserType;
/**
* @author Brett Meyer
*/
public class TestTypeContributor implements TypeContributor {
public static final String NAME = "test-type";
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType( new TestType(), NAME );
}
public static class TestType implements UserType {
@Override
public int[] sqlTypes() {
return new int[0];
}
@Override
public Class returnedClass() {
return null;
}
@Override
public boolean equals(Object x, Object y) throws HibernateException {
return false;
}
@Override
public int hashCode(Object x) throws HibernateException {
return 0;
}
@Override
public Object nullSafeGet(ResultSet rs, int position, SharedSessionContractImplementor session, Object owner) throws SQLException {
return null;
}
@Override
public void nullSafeSet(
PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
throws HibernateException, SQLException {
}
@Override
public Object deepCopy(Object value) throws HibernateException {
return null;
}
@Override
public boolean isMutable() {
return false;
}
@Override
public Serializable disassemble(Object value) throws HibernateException {
return null;
}
@Override
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return null;
}
@Override
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return null;
}
}
}

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<persistence-unit name="hibernate-osgi-test">
<class>org.hibernate.osgi.test.client.DataPoint</class>
<class>org.hibernate.osgi.test.client.AuditedDataPoint</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.connection.url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.archive.autodetection" value=""/>
</properties>
</persistence-unit>
</persistence>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<blueprint default-activation="eager"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bean id="service-contributor" class="org.hibernate.osgi.test.client.SomeServiceContributor"/>
<service ref="service-contributor" interface="org.hibernate.service.spi.ServiceContributor" />
</blueprint>

View File

@ -1,4 +0,0 @@
Bundle-SymbolicName: cdi-api
Bundle-Version: 1.1
Include-Resource: @../cdi-api-1.1.jar
-exportcontents: *

View File

@ -1,5 +0,0 @@
Bundle-SymbolicName: el-api
Bundle-Version: 2.2
Include-Resource: @../el-api-2.2.jar
-exportcontents: *

View File

@ -1,7 +0,0 @@
Bundle-SymbolicName: jandex
Bundle-Version: 1.1.0
Include-Resource: @../jandex-1.1.0.Final.jar
Import-Package: org.apache.tools.ant;resolution:=optional, org.apache.tools.ant.types;resolution:=optional, *
-exportcontents: *

View File

@ -1,23 +0,0 @@
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<mapping class="org.hibernate.osgi.test.client.DataPoint"/>
<mapping class="org.hibernate.osgi.test.client.AuditedDataPoint"/>
</session-factory>
</hibernate-configuration>

View File

@ -1,23 +0,0 @@
#
# Hibernate, Relational Persistence for Idiomatic Java
#
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
# Root logger option
log4j.rootLogger=DEBUG, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=target/test.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n
log4j.appender.file.Threshold=DEBUG
# Direct log messages to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n
log4j.appender.console.Threshold=WARN

View File

@ -1,11 +0,0 @@
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<features name="hibernate-osgi-testing-repository" xmlns='http://karaf.apache.org/xmlns/features/v1.2.0'>
<feature name='hibernate-osgi-testing' version='5.0.0-SNAPSHOT'>
<bundle>mvn:com.h2database/h2/1.3.170</bundle>
</feature>
</features>

View File

@ -92,8 +92,6 @@ include 'hibernate-envers'
// todo (6.0): re-enable hibernate-spatial
//include 'hibernate-spatial'
include 'hibernate-osgi'
include 'hibernate-c3p0'
include 'hibernate-proxool'
include 'hibernate-hikaricp'