HHH-5943 - Make ServiceRegistry mutable
This commit is contained in:
parent
73ff2534e2
commit
2a64bcf9a7
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, 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.cfg.internal;
|
|
||||||
|
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
|
||||||
import org.hibernate.service.spi.StandardServiceInitiators;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The standard bootstrap process for Hibernate services
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class ServicesRegistryBootstrap {
|
|
||||||
public ServiceRegistryImpl initiateServicesRegistry(Map configurationValues) {
|
|
||||||
return new ServiceRegistryImpl( StandardServiceInitiators.LIST, configurationValues );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.internal.ServicesRegistryBootstrap;
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
import org.hibernate.internal.util.jndi.JndiHelper;
|
import org.hibernate.internal.util.jndi.JndiHelper;
|
||||||
import org.hibernate.util.ExternalSessionFactoryConfig;
|
import org.hibernate.util.ExternalSessionFactoryConfig;
|
||||||
|
@ -61,9 +61,7 @@ public class HibernateService extends ExternalSessionFactoryConfig implements Hi
|
||||||
SessionFactory buildSessionFactory() throws HibernateException {
|
SessionFactory buildSessionFactory() throws HibernateException {
|
||||||
log.info( "starting service at JNDI name: " + boundName );
|
log.info( "starting service at JNDI name: " + boundName );
|
||||||
log.info( "service properties: " + properties );
|
log.info( "service properties: " + properties );
|
||||||
return buildConfiguration().buildSessionFactory(
|
return buildConfiguration().buildSessionFactory( new ServiceRegistryImpl( properties ) );
|
||||||
new ServicesRegistryBootstrap().initiateServicesRegistry( properties )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map getExtraProperties() {
|
protected Map getExtraProperties() {
|
||||||
|
|
|
@ -28,6 +28,8 @@ import org.hibernate.service.spi.proxy.ServiceProxyFactoryFactory;
|
||||||
import org.hibernate.service.spi.proxy.ServiceProxyTargetSource;
|
import org.hibernate.service.spi.proxy.ServiceProxyTargetSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Javassist-based implementation of a {@link ServiceProxyFactoryFactory}
|
||||||
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ServiceProxyFactoryFactoryImpl implements ServiceProxyFactoryFactory {
|
public class ServiceProxyFactoryFactoryImpl implements ServiceProxyFactoryFactory {
|
||||||
|
|
|
@ -38,6 +38,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Javassist-based implementation of a {@link ServiceProxyFactory}
|
||||||
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class ServiceProxyFactoryImpl implements ServiceProxyFactory {
|
public class ServiceProxyFactoryImpl implements ServiceProxyFactory {
|
||||||
|
|
|
@ -26,8 +26,18 @@ package org.hibernate.service.spi.proxy;
|
||||||
import org.hibernate.service.spi.Service;
|
import org.hibernate.service.spi.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Contract for creating proxy instances for {@link Service} instances.
|
||||||
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface ServiceProxyFactory {
|
public interface ServiceProxyFactory {
|
||||||
|
/**
|
||||||
|
* Create a proxy for the given service role.
|
||||||
|
*
|
||||||
|
* @param serviceRole The service role for which to create a proxy.
|
||||||
|
* @param <T> The type of the service
|
||||||
|
*
|
||||||
|
* @return The service proxy
|
||||||
|
*/
|
||||||
public <T extends Service> T makeProxy(Class<T> serviceRole);
|
public <T extends Service> T makeProxy(Class<T> serviceRole);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,17 @@
|
||||||
package org.hibernate.service.spi.proxy;
|
package org.hibernate.service.spi.proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Contract for making a {@link ServiceProxyFactory}.
|
||||||
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface ServiceProxyFactoryFactory {
|
public interface ServiceProxyFactoryFactory {
|
||||||
|
/**
|
||||||
|
* Make an instance of the service proxy factory.
|
||||||
|
*
|
||||||
|
* @param registry The registry of actual service instances
|
||||||
|
*
|
||||||
|
* @return The created service proxy factory
|
||||||
|
*/
|
||||||
public ServiceProxyFactory makeServiceProxyFactory(ServiceProxyTargetSource registry);
|
public ServiceProxyFactory makeServiceProxyFactory(ServiceProxyTargetSource registry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,7 @@ import org.hibernate.service.spi.ServiceRegistry;
|
||||||
*/
|
*/
|
||||||
public interface ServiceProxyTargetSource extends ServiceRegistry {
|
public interface ServiceProxyTargetSource extends ServiceRegistry {
|
||||||
/**
|
/**
|
||||||
* Retrieve a service by role. Unlike {@link org.hibernate.service.spi.ServiceRegistry#getService}, this version
|
* Retrieve a service by role. Unlike {@link ServiceRegistry#getService}, this version will never return a proxy.
|
||||||
* will never return a proxy.
|
|
||||||
*
|
*
|
||||||
* @param serviceRole The service role
|
* @param serviceRole The service role
|
||||||
* @param <T> The type of the service
|
* @param <T> The type of the service
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, 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.test.cfg.internal;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.internal.ServicesRegistryBootstrap;
|
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
|
||||||
import org.hibernate.test.common.ConnectionProviderBuilder;
|
|
||||||
import org.hibernate.testing.junit.UnitTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO : javadoc
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class TestServicesRegistryBootstrapping extends UnitTestCase {
|
|
||||||
|
|
||||||
public TestServicesRegistryBootstrapping(String string) {
|
|
||||||
super( string );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testBasicBootstrapping() {
|
|
||||||
ServiceRegistryImpl servicesRegistry = new ServicesRegistryBootstrap().initiateServicesRegistry(
|
|
||||||
ConnectionProviderBuilder.getConnectionProviderProperties()
|
|
||||||
);
|
|
||||||
|
|
||||||
assertNotNull( servicesRegistry.getService( JdbcServices.class ) );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,7 +27,6 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.internal.ServicesRegistryBootstrap;
|
|
||||||
import org.hibernate.engine.jdbc.internal.JdbcServicesImpl;
|
import org.hibernate.engine.jdbc.internal.JdbcServicesImpl;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
|
@ -47,7 +46,7 @@ public class ServiceRegistryHolder {
|
||||||
properties.putAll( props );
|
properties.putAll( props );
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
serviceRegistry = new ServicesRegistryBootstrap().initiateServicesRegistry( properties );
|
serviceRegistry = new ServiceRegistryImpl( properties );
|
||||||
properties.putAll( serviceRegistry.getService( JdbcServices.class ).getDialect().getDefaultProperties() );
|
properties.putAll( serviceRegistry.getService( JdbcServices.class ).getDialect().getDefaultProperties() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,15 @@
|
||||||
* 51 Franklin Street, Fifth Floor
|
* 51 Franklin Street, Fifth Floor
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.cfg.internal;
|
package org.hibernate.test.service;
|
||||||
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.service.internal.ServiceRegistryImpl;
|
import org.hibernate.service.internal.ServiceRegistryImpl;
|
||||||
import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
import org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||||
|
import org.hibernate.service.jdbc.connections.internal.UserSuppliedConnectionProviderImpl;
|
||||||
|
import org.hibernate.service.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.test.common.ConnectionProviderBuilder;
|
import org.hibernate.test.common.ConnectionProviderBuilder;
|
||||||
import org.hibernate.testing.junit.UnitTestCase;
|
import org.hibernate.testing.junit.UnitTestCase;
|
||||||
|
|
||||||
|
@ -67,4 +69,21 @@ public class ServiceBootstrappingTest extends UnitTestCase {
|
||||||
|
|
||||||
serviceRegistry.destroy();
|
serviceRegistry.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBuildWithServiceOverride() {
|
||||||
|
Properties props = ConnectionProviderBuilder.getConnectionProviderProperties();
|
||||||
|
|
||||||
|
ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl( props );
|
||||||
|
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||||
|
|
||||||
|
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
||||||
|
assertTrue( jdbcServices.getConnectionProvider().isUnwrappableAs( DriverManagerConnectionProviderImpl.class ) );
|
||||||
|
|
||||||
|
serviceRegistry.registerService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() );
|
||||||
|
|
||||||
|
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
||||||
|
assertTrue( jdbcServices.getConnectionProvider().isUnwrappableAs( UserSuppliedConnectionProviderImpl.class ) );
|
||||||
|
|
||||||
|
serviceRegistry.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -39,7 +39,6 @@ import javax.persistence.spi.LoadState;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
import org.hibernate.cfg.internal.ServicesRegistryBootstrap;
|
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.engine.SessionFactoryImplementor;
|
import org.hibernate.engine.SessionFactoryImplementor;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
|
@ -83,7 +82,7 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
||||||
);
|
);
|
||||||
serviceRegistryProperties.putAll( cfg.getProperties() );
|
serviceRegistryProperties.putAll( cfg.getProperties() );
|
||||||
serviceRegistryProperties.putAll( connectionProviderInjectionData );
|
serviceRegistryProperties.putAll( connectionProviderInjectionData );
|
||||||
this.serviceRegistry = new ServicesRegistryBootstrap().initiateServicesRegistry( serviceRegistryProperties );
|
this.serviceRegistry = new ServiceRegistryImpl( serviceRegistryProperties );
|
||||||
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
this.sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||||
this.transactionType = transactionType;
|
this.transactionType = transactionType;
|
||||||
this.discardOnClose = discardOnClose;
|
this.discardOnClose = discardOnClose;
|
||||||
|
|
Loading…
Reference in New Issue