diff --git a/hibernate-c3p0/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/hibernate-c3p0/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 000000000000..3ade79977f8e --- /dev/null +++ b/hibernate-c3p0/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 383dfd81f33d..433aa11465ea 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -23,12 +23,6 @@ */ package org.hibernate.jpa.boot.internal; -import javax.persistence.AttributeConverter; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityNotFoundException; -import javax.persistence.PersistenceException; -import javax.persistence.spi.PersistenceUnitTransactionType; -import javax.sql.DataSource; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; @@ -47,14 +41,12 @@ import java.util.Set; import java.util.StringTokenizer; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.DotName; -import org.jboss.jandex.Index; -import org.jboss.jandex.IndexView; -import org.jboss.jandex.Indexer; - -import org.jboss.logging.Logger; +import javax.persistence.AttributeConverter; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityNotFoundException; +import javax.persistence.PersistenceException; +import javax.persistence.spi.PersistenceUnitTransactionType; +import javax.sql.DataSource; import org.hibernate.Interceptor; import org.hibernate.InvalidMappingException; @@ -67,6 +59,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; @@ -81,25 +74,26 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.ValueHolder; import org.hibernate.jpa.AvailableSettings; +import org.hibernate.jpa.boot.scan.internal.StandardScanOptions; +import org.hibernate.jpa.boot.scan.internal.StandardScanner; +import org.hibernate.jpa.boot.scan.spi.ScanOptions; +import org.hibernate.jpa.boot.scan.spi.ScanResult; +import org.hibernate.jpa.boot.scan.spi.Scanner; +import org.hibernate.jpa.boot.spi.ClassDescriptor; import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder; +import org.hibernate.jpa.boot.spi.InputStreamAccess; import org.hibernate.jpa.boot.spi.IntegratorProvider; +import org.hibernate.jpa.boot.spi.MappingFileDescriptor; +import org.hibernate.jpa.boot.spi.NamedInputStream; +import org.hibernate.jpa.boot.spi.PackageDescriptor; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; +import org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList; import org.hibernate.jpa.event.spi.JpaIntegrator; import org.hibernate.jpa.internal.EntityManagerFactoryImpl; import org.hibernate.jpa.internal.EntityManagerMessageLogger; import org.hibernate.jpa.internal.schemagen.JpaSchemaGenerator; import org.hibernate.jpa.internal.util.LogHelper; import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper; -import org.hibernate.jpa.boot.scan.internal.StandardScanOptions; -import org.hibernate.jpa.boot.scan.internal.StandardScanner; -import org.hibernate.jpa.boot.spi.ClassDescriptor; -import org.hibernate.jpa.boot.spi.InputStreamAccess; -import org.hibernate.jpa.boot.spi.MappingFileDescriptor; -import org.hibernate.jpa.boot.spi.NamedInputStream; -import org.hibernate.jpa.boot.spi.PackageDescriptor; -import org.hibernate.jpa.boot.scan.spi.ScanOptions; -import org.hibernate.jpa.boot.scan.spi.ScanResult; -import org.hibernate.jpa.boot.scan.spi.Scanner; import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider; import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JandexHelper; @@ -109,6 +103,13 @@ import org.hibernate.service.ConfigLoader; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.Index; +import org.jboss.jandex.IndexView; +import org.jboss.jandex.Indexer; +import org.jboss.logging.Logger; /** * @author Steve Ebersole @@ -129,6 +130,11 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil * Names a {@link IntegratorProvider} */ public static final String INTEGRATOR_PROVIDER = "hibernate.integrator_provider"; + + /** + * Names a {@link StrategyRegistrationProviderList} + */ + public static final String STRATEGY_REGISTRATION_PROVIDERS = "hibernate.strategy_registration_provider"; /** * Names a Jandex {@link Index} instance to use. @@ -471,11 +477,19 @@ private BootstrapServiceRegistry buildBootstrapServiceRegistry(Map integrationSe final IntegratorProvider integratorProvider = (IntegratorProvider) integrationSettings.get( INTEGRATOR_PROVIDER ); if ( integratorProvider != null ) { - integrationSettings.remove( INTEGRATOR_PROVIDER ); for ( Integrator integrator : integratorProvider.getIntegrators() ) { bootstrapServiceRegistryBuilder.with( integrator ); } } + + final StrategyRegistrationProviderList strategyRegistrationProviderList + = (StrategyRegistrationProviderList) integrationSettings.get( STRATEGY_REGISTRATION_PROVIDERS ); + if ( strategyRegistrationProviderList != null ) { + for ( StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviderList + .getStrategyRegistrationProviders() ) { + bootstrapServiceRegistryBuilder.withStrategySelectors( strategyRegistrationProvider ); + } + } // TODO: If providedClassLoader is present (OSGi, etc.) *and* // an APP_CLASSLOADER is provided, should throw an exception or diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/StrategyRegistrationProviderList.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/StrategyRegistrationProviderList.java new file mode 100644 index 000000000000..24ad60470585 --- /dev/null +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/spi/StrategyRegistrationProviderList.java @@ -0,0 +1,37 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.jpa.boot.spi; + +import java.util.List; + +import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; + +/** + * @author Brett Meyer + * + * TODO: Not a fan of this name or entry point into EMFBuilderImpl + */ +public interface StrategyRegistrationProviderList { + public List getStrategyRegistrationProviders(); +} diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java index 885533f74582..01ccff48ee19 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java @@ -30,11 +30,13 @@ import javax.persistence.EntityManagerFactory; import javax.persistence.spi.PersistenceUnitInfo; +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.IntegratorProvider; +import org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList; import org.hibernate.osgi.util.OsgiServiceUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -67,7 +69,7 @@ public OsgiPersistenceProvider(OsgiClassLoader osgiClassLoader, OsgiJtaPlatform @Override public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) { - generateProperties( properties ); + properties = generateProperties( properties ); // TODO: This needs tested. properties.put( org.hibernate.jpa.AvailableSettings.SCANNER, new OsgiScanner( requestingBundle ) ); @@ -82,7 +84,7 @@ public EntityManagerFactory createEntityManagerFactory(String persistenceUnitNam @Override public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { - generateProperties( properties ); + properties = generateProperties( properties ); // OSGi ClassLoaders must implement BundleReference properties.put( org.hibernate.jpa.AvailableSettings.SCANNER, @@ -93,7 +95,7 @@ public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitI return super.createContainerEntityManagerFactory( info, properties ); } - private void generateProperties(Map properties) { + private Map generateProperties(Map properties) { if ( properties == null ) { properties = new HashMap(); } @@ -109,6 +111,17 @@ public List getIntegrators() { }; properties.put( EntityManagerFactoryBuilderImpl.INTEGRATOR_PROVIDER, integratorProvider ); - // TODO: other types of services? + final List strategyRegistrationProviders = OsgiServiceUtil.getServiceImpls( + StrategyRegistrationProvider.class, context ); + StrategyRegistrationProviderList strategyRegistrationProviderList = new StrategyRegistrationProviderList() { + @Override + public List getStrategyRegistrationProviders() { + return strategyRegistrationProviders; + } + }; + properties.put( EntityManagerFactoryBuilderImpl.STRATEGY_REGISTRATION_PROVIDERS, + strategyRegistrationProviderList ); + + return properties; } } diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java index 8770e552313f..c8781367114b 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java @@ -25,6 +25,7 @@ import org.hibernate.SessionFactory; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; import org.hibernate.integrator.spi.Integrator; @@ -84,6 +85,12 @@ public Object getService(Bundle requestingBundle, ServiceRegistration registrati builder.with( integrator ); } + List strategyRegistrationProviders + = OsgiServiceUtil.getServiceImpls( StrategyRegistrationProvider.class, context ); + for (StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviders) { + builder.withStrategySelectors( strategyRegistrationProvider ); + } + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder( builder.build() ) .applySettings(configuration.getProperties()).build(); return configuration.buildSessionFactory(serviceRegistry); diff --git a/hibernate-proxool/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/hibernate-proxool/src/main/resources/OSGI-INF/blueprint/blueprint.xml new file mode 100644 index 000000000000..b0e0c5c44dd4 --- /dev/null +++ b/hibernate-proxool/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -0,0 +1,10 @@ + + + + + + + +