HHH-7580 - Complete 2-phase SessionFactory building design

This commit is contained in:
Steve Ebersole 2012-09-12 15:47:36 -05:00
parent ea2b9a899f
commit 7042790a53
63 changed files with 601 additions and 291 deletions

View File

@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import javax.naming.Referenceable;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.metadata.ClassMetadata;
@ -55,6 +56,7 @@ import org.hibernate.stat.Statistics;
public interface SessionFactory extends Referenceable, Serializable {
public interface SessionFactoryOptions {
public StandardServiceRegistry getServiceRegistry();
public Interceptor getInterceptor();
public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy();
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();

View File

@ -23,7 +23,9 @@
*/
package org.hibernate.boot.registry;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
import org.hibernate.boot.registry.selector.Availability;
@ -43,10 +45,7 @@ import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
*/
public class BootstrapServiceRegistryBuilder {
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
private ClassLoader applicationClassLoader;
private ClassLoader resourcesClassLoader;
private ClassLoader hibernateClassLoader;
private ClassLoader environmentClassLoader;
private List<ClassLoader> providedClassLoaders;
private StrategySelectorBuilder strategySelectorBuilder = new StrategySelectorBuilder();
@ -61,16 +60,33 @@ public class BootstrapServiceRegistryBuilder {
return this;
}
/**
* Adds a provided {@link ClassLoader} for use in class-loading and resource-lookup
*
* @param classLoader The class loader to use
*
* @return {@code this}, for method chaining
*/
public BootstrapServiceRegistryBuilder with(ClassLoader classLoader) {
if ( providedClassLoaders == null ) {
providedClassLoaders = new ArrayList<ClassLoader>();
}
providedClassLoaders.add( classLoader );
return this;
}
/**
* Applies the specified {@link ClassLoader} as the application class loader for the bootstrap registry
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
*
* @deprecated Use {@link #with(ClassLoader)} instead
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public BootstrapServiceRegistryBuilder withApplicationClassLoader(ClassLoader classLoader) {
this.applicationClassLoader = classLoader;
return this;
return with( classLoader );
}
/**
@ -78,11 +94,13 @@ public class BootstrapServiceRegistryBuilder {
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
*
* @deprecated Use {@link #with(ClassLoader)} instead
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public BootstrapServiceRegistryBuilder withResourceClassLoader(ClassLoader classLoader) {
this.resourcesClassLoader = classLoader;
return this;
return with( classLoader );
}
/**
@ -90,11 +108,13 @@ public class BootstrapServiceRegistryBuilder {
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
*
* @deprecated Use {@link #with(ClassLoader)} instead
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public BootstrapServiceRegistryBuilder withHibernateClassLoader(ClassLoader classLoader) {
this.hibernateClassLoader = classLoader;
return this;
return with( classLoader );
}
/**
@ -102,11 +122,13 @@ public class BootstrapServiceRegistryBuilder {
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
*
* @deprecated Use {@link #with(ClassLoader)} instead
*/
@Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public BootstrapServiceRegistryBuilder withEnvironmentClassLoader(ClassLoader classLoader) {
this.environmentClassLoader = classLoader;
return this;
return with( classLoader );
}
/**
@ -149,12 +171,7 @@ public class BootstrapServiceRegistryBuilder {
* @return The built bootstrap registry
*/
public BootstrapServiceRegistry build() {
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
applicationClassLoader,
resourcesClassLoader,
hibernateClassLoader,
environmentClassLoader
);
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl( providedClassLoaders );
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
providedIntegrators,

View File

@ -0,0 +1,34 @@
/*
* 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.boot.registry;
import org.hibernate.service.ServiceRegistry;
/**
* Specialization of the {@link org.hibernate.service.ServiceRegistry} contract mainly for type safety.
*
* @author Steve Ebersole
*/
public interface StandardServiceRegistry extends ServiceRegistry {
}

View File

@ -25,14 +25,15 @@ package org.hibernate.boot.registry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.Environment;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;
import org.hibernate.integrator.spi.ServiceContributingIntegrator;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
@ -42,6 +43,7 @@ import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.StandardServiceInitiators;
import org.hibernate.service.internal.ProvidedService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.service.spi.ServiceContributor;
/**
* Builder for standard {@link org.hibernate.service.ServiceRegistry} instances.
@ -65,7 +67,7 @@ public class StandardServiceRegistryBuilder {
* Create a default builder
*/
public StandardServiceRegistryBuilder() {
this( new BootstrapServiceRegistryImpl() );
this( new BootstrapServiceRegistryBuilder().build() );
}
/**
@ -193,26 +195,35 @@ public class StandardServiceRegistryBuilder {
return this;
}
/**
* Build the service registry accounting for all settings and service initiators and services.
*
* @return The built service registry
*/
public ServiceRegistry buildServiceRegistry() {
public StandardServiceRegistry build() {
Map<?,?> settingsCopy = new HashMap();
settingsCopy.putAll( settings );
Environment.verifyProperties( settingsCopy );
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
if ( ServiceContributingIntegrator.class.isInstance( integrator ) ) {
ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this );
}
}
applyServiceContributingIntegrators();
applyServiceContributors();
return new StandardServiceRegistryImpl( bootstrapServiceRegistry, initiators, providedServices, settingsCopy );
}
@SuppressWarnings("deprecation")
private void applyServiceContributingIntegrators() {
for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
if ( org.hibernate.integrator.spi.ServiceContributingIntegrator.class.isInstance( integrator ) ) {
org.hibernate.integrator.spi.ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this );
}
}
}
private void applyServiceContributors() {
LinkedHashSet<ServiceContributor> serviceContributors =
bootstrapServiceRegistry.getService( ClassLoaderService.class ).loadJavaServices( ServiceContributor.class );
for ( ServiceContributor serviceContributor : serviceContributors ) {
serviceContributor.contribute( this );
}
}
/**
* Destroy a service registry. Applications should only destroy registries they have explicitly created.
*

View File

@ -27,6 +27,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
@ -49,75 +51,71 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
public class ClassLoaderServiceImpl implements ClassLoaderService {
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
private final ClassLoader classClassLoader;
private final ClassLoader resourcesClassLoader;
private final ClassLoader serviceLoaderClassLoader;
private final ClassLoader aggregatedClassLoader;
public ClassLoaderServiceImpl() {
this( ClassLoaderServiceImpl.class.getClassLoader() );
}
public ClassLoaderServiceImpl(ClassLoader classLoader) {
this( classLoader, classLoader, classLoader, classLoader );
this( Collections.singletonList( classLoader ) );
}
public ClassLoaderServiceImpl(
ClassLoader applicationClassLoader,
ClassLoader resourcesClassLoader,
ClassLoader hibernateClassLoader,
ClassLoader environmentClassLoader) {
// Normalize missing loaders
if ( hibernateClassLoader == null ) {
hibernateClassLoader = ClassLoaderServiceImpl.class.getClassLoader();
}
public ClassLoaderServiceImpl(List<ClassLoader> providedClassLoaders) {
final LinkedHashSet<ClassLoader> orderedClassLoaderSet = new LinkedHashSet<ClassLoader>();
if ( environmentClassLoader == null || applicationClassLoader == null ) {
ClassLoader sysClassLoader = locateSystemClassLoader();
ClassLoader tccl = locateTCCL();
if ( environmentClassLoader == null ) {
environmentClassLoader = sysClassLoader != null ? sysClassLoader : hibernateClassLoader;
}
if ( applicationClassLoader == null ) {
applicationClassLoader = tccl != null ? tccl : hibernateClassLoader;
}
}
if ( resourcesClassLoader == null ) {
resourcesClassLoader = applicationClassLoader;
}
final LinkedHashSet<ClassLoader> classLoadingClassLoaders = new LinkedHashSet<ClassLoader>();
classLoadingClassLoaders.add( applicationClassLoader );
classLoadingClassLoaders.add( hibernateClassLoader );
classLoadingClassLoaders.add( environmentClassLoader );
this.classClassLoader = new ClassLoader(null) {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
for ( ClassLoader loader : classLoadingClassLoaders ) {
try {
return loader.loadClass( name );
}
catch (Exception ignore) {
}
// first add all provided class loaders, if any
if ( providedClassLoaders != null ) {
for ( ClassLoader classLoader : providedClassLoaders ) {
if ( classLoader != null ) {
orderedClassLoaderSet.add( classLoader );
}
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
};
}
this.resourcesClassLoader = resourcesClassLoader;
// normalize adding known class-loaders...
// first the Hibernate class loader
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );
// then the TCCL, if one...
final ClassLoader tccl = locateTCCL();
if ( tccl != null ) {
orderedClassLoaderSet.add( tccl );
}
// finally the system classloader
final ClassLoader sysClassLoader = locateSystemClassLoader();
if ( sysClassLoader != null ) {
orderedClassLoaderSet.add( sysClassLoader );
}
this.serviceLoaderClassLoader = buildServiceLoaderClassLoader();
// now build the aggregated class loader...
this.aggregatedClassLoader = new AggregatedClassLoader( orderedClassLoaderSet );
}
@SuppressWarnings( {"UnusedDeclaration"})
@SuppressWarnings({"UnusedDeclaration", "unchecked", "deprecation"})
@Deprecated
public static ClassLoaderServiceImpl fromConfigSettings(Map configVales) {
return new ClassLoaderServiceImpl(
(ClassLoader) configVales.get( AvailableSettings.APP_CLASSLOADER ),
(ClassLoader) configVales.get( AvailableSettings.RESOURCES_CLASSLOADER ),
(ClassLoader) configVales.get( AvailableSettings.HIBERNATE_CLASSLOADER ),
(ClassLoader) configVales.get( AvailableSettings.ENVIRONMENT_CLASSLOADER )
);
final List<ClassLoader> providedClassLoaders = new ArrayList<ClassLoader>();
final Collection<ClassLoader> classLoaders = (Collection<ClassLoader>) configVales.get( AvailableSettings.CLASSLOADERS );
if ( classLoaders != null ) {
for ( ClassLoader classLoader : classLoaders ) {
providedClassLoaders.add( classLoader );
}
}
addIfSet( providedClassLoaders, AvailableSettings.APP_CLASSLOADER, configVales );
addIfSet( providedClassLoaders, AvailableSettings.RESOURCES_CLASSLOADER, configVales );
addIfSet( providedClassLoaders, AvailableSettings.HIBERNATE_CLASSLOADER, configVales );
addIfSet( providedClassLoaders, AvailableSettings.ENVIRONMENT_CLASSLOADER, configVales );
return new ClassLoaderServiceImpl( providedClassLoaders );
}
private static void addIfSet(List<ClassLoader> providedClassLoaders, String name, Map configVales) {
final ClassLoader providedClassLoader = (ClassLoader) configVales.get( name );
if ( providedClassLoader != null ) {
providedClassLoaders.add( providedClassLoader );
}
}
private static ClassLoader locateSystemClassLoader() {
@ -138,73 +136,69 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
}
}
private ClassLoader buildServiceLoaderClassLoader() {
return new ClassLoader(null) {
final ClassLoader[] classLoaderArray = new ClassLoader[] {
// first look on the hibernate class loader
getClass().getClassLoader(),
// next look on the resource class loader
resourcesClassLoader,
// finally look on the combined class class loader
classClassLoader
private static class AggregatedClassLoader extends ClassLoader {
private final ClassLoader[] individualClassLoaders;
private AggregatedClassLoader(final LinkedHashSet<ClassLoader> orderedClassLoaderSet) {
super( null );
individualClassLoaders = orderedClassLoaderSet.toArray( new ClassLoader[ orderedClassLoaderSet.size() ] );
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
final HashSet<URL> resourceUrls = new HashSet<URL>();
for ( ClassLoader classLoader : individualClassLoaders ) {
final Enumeration<URL> urls = classLoader.getResources( name );
while ( urls.hasMoreElements() ) {
resourceUrls.add( urls.nextElement() );
}
}
return new Enumeration<URL>() {
final Iterator<URL> resourceUrlIterator = resourceUrls.iterator();
@Override
public boolean hasMoreElements() {
return resourceUrlIterator.hasNext();
}
@Override
public URL nextElement() {
return resourceUrlIterator.next();
}
};
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
final HashSet<URL> resourceUrls = new HashSet<URL>();
for ( ClassLoader classLoader : classLoaderArray ) {
final Enumeration<URL> urls = classLoader.getResources( name );
while ( urls.hasMoreElements() ) {
resourceUrls.add( urls.nextElement() );
}
@Override
protected URL findResource(String name) {
for ( ClassLoader classLoader : individualClassLoaders ) {
final URL resource = classLoader.getResource( name );
if ( resource != null ) {
return resource;
}
}
return super.findResource( name );
}
return new Enumeration<URL>() {
final Iterator<URL> resourceUrlIterator = resourceUrls.iterator();
@Override
public boolean hasMoreElements() {
return resourceUrlIterator.hasNext();
}
@Override
public URL nextElement() {
return resourceUrlIterator.next();
}
};
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
for ( ClassLoader classLoader : individualClassLoaders ) {
try {
return classLoader.loadClass( name );
}
catch (Exception ignore) {
}
}
@Override
protected URL findResource(String name) {
for ( ClassLoader classLoader : classLoaderArray ) {
final URL resource = classLoader.getResource( name );
if ( resource != null ) {
return resource;
}
}
return super.findResource( name );
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
for ( ClassLoader classLoader : classLoaderArray ) {
try {
return classLoader.loadClass( name );
}
catch (Exception ignore) {
}
}
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
};
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
}
@Override
@SuppressWarnings( {"unchecked"})
public <T> Class<T> classForName(String className) {
try {
return (Class<T>) Class.forName( className, true, classClassLoader );
return (Class<T>) Class.forName( className, true, aggregatedClassLoader );
}
catch (Exception e) {
throw new ClassLoadingException( "Unable to load class [" + className + "]", e );
@ -221,7 +215,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
}
try {
return resourcesClassLoader.getResource( name );
return aggregatedClassLoader.getResource( name );
}
catch ( Exception ignore ) {
}
@ -241,7 +235,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
try {
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", name );
InputStream stream = resourcesClassLoader.getResourceAsStream( name );
InputStream stream = aggregatedClassLoader.getResourceAsStream( name );
if ( stream != null ) {
return stream;
}
@ -261,7 +255,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
try {
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", stripped );
InputStream stream = resourcesClassLoader.getResourceAsStream( stripped );
InputStream stream = aggregatedClassLoader.getResourceAsStream( stripped );
if ( stream != null ) {
return stream;
}
@ -277,7 +271,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
public List<URL> locateResources(String name) {
ArrayList<URL> urls = new ArrayList<URL>();
try {
Enumeration<URL> urlEnumeration = resourcesClassLoader.getResources( name );
Enumeration<URL> urlEnumeration = aggregatedClassLoader.getResources( name );
if ( urlEnumeration != null && urlEnumeration.hasMoreElements() ) {
while ( urlEnumeration.hasMoreElements() ) {
urls.add( urlEnumeration.nextElement() );
@ -292,7 +286,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
@Override
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
final ServiceLoader<S> loader = ServiceLoader.load( serviceContract, serviceLoaderClassLoader );
final ServiceLoader<S> loader = ServiceLoader.load( serviceContract, aggregatedClassLoader );
final LinkedHashSet<S> services = new LinkedHashSet<S>();
for ( S service : loader ) {
services.add( service );
@ -315,7 +309,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
boolean set = false;
try {
Thread.currentThread().setContextClassLoader( serviceLoaderClassLoader);
Thread.currentThread().setContextClassLoader( aggregatedClassLoader );
set = true;
}
catch (Exception ignore) {

View File

@ -28,8 +28,8 @@ import java.util.Map;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.internal.AbstractServiceRegistryImpl;
import org.hibernate.service.internal.ProvidedService;
import org.hibernate.service.spi.Configurable;
@ -41,7 +41,7 @@ import org.hibernate.service.spi.ServiceInitiator;
*
* @author Steve Ebersole
*/
public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl implements ServiceRegistry {
public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl implements StandardServiceRegistry {
private final Map configurationValues;
@SuppressWarnings( {"unchecked"})

View File

@ -471,30 +471,47 @@ public interface AvailableSettings {
*/
public static final String NON_CONTEXTUAL_LOB_CREATION = "hibernate.jdbc.lob.non_contextual_creation";
/**
* Used to define a {@link java.util.Collection} of the {@link ClassLoader} instances Hibernate should use for
* class-loading and resource-lookups.
*
* @since 5.0
*/
public static final String CLASSLOADERS = "hibernate.classLoaders";
/**
* Names the {@link ClassLoader} used to load user application classes.
* @since 4.0
*
* @deprecated Use {@link #CLASSLOADERS} instead
*/
@Deprecated
public static final String APP_CLASSLOADER = "hibernate.classLoader.application";
/**
* Names the {@link ClassLoader} Hibernate should use to perform resource loading.
* @since 4.0
* @deprecated Use {@link #CLASSLOADERS} instead
*/
@Deprecated
public static final String RESOURCES_CLASSLOADER = "hibernate.classLoader.resources";
/**
* Names the {@link ClassLoader} responsible for loading Hibernate classes. By default this is
* the {@link ClassLoader} that loaded this class.
* @since 4.0
* @deprecated Use {@link #CLASSLOADERS} instead
*/
@Deprecated
public static final String HIBERNATE_CLASSLOADER = "hibernate.classLoader.hibernate";
/**
* Names the {@link ClassLoader} used when Hibernate is unable to locates classes on the
* {@link #APP_CLASSLOADER} or {@link #HIBERNATE_CLASSLOADER}.
* @since 4.0
* @deprecated Use {@link #CLASSLOADERS} instead
*/
@Deprecated
public static final String ENVIRONMENT_CLASSLOADER = "hibernate.classLoader.environment";

View File

@ -1776,7 +1776,7 @@ public class Configuration implements Serializable {
ConfigurationHelper.resolvePlaceHolders( properties );
final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( properties )
.buildServiceRegistry();
.build();
setSessionFactoryObserver(
new SessionFactoryObserver() {
@Override

View File

@ -66,7 +66,7 @@ import org.hibernate.internal.util.config.ConfigurationHelper;
* Properties may be either be <tt>System</tt> properties, properties
* defined in a resource named <tt>/hibernate.properties</tt> or an instance of
* <tt>java.util.Properties</tt> passed to
* <tt>Configuration.buildSessionFactory()</tt><br>
* <tt>Configuration.build()</tt><br>
* <br>
* <table>
* <tr><td><b>property</b></td><td><b>meaning</b></td></tr>

View File

@ -3014,7 +3014,7 @@ public final class HbmBinder {
//TODO: bad implementation, cos it depends upon ordering of mapping doc
// fixing this requires that Collection/PersistentClass gain access
// to the Mappings reference from Configuration (or the filterDefinitions
// map directly) sometime during Configuration.buildSessionFactory
// map directly) sometime during Configuration.build
// (after all the types/filter-defs are known and before building
// persisters).
if ( StringHelper.isEmpty(condition) ) {

View File

@ -62,6 +62,7 @@ import org.hibernate.SessionFactoryObserver;
import org.hibernate.StatelessSession;
import org.hibernate.StatelessSessionBuilder;
import org.hibernate.TypeHelper;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cache.internal.CacheDataDescriptionImpl;
import org.hibernate.cache.spi.CollectionRegion;
@ -258,6 +259,10 @@ public final class SessionFactoryImpl
}
@Override
public StandardServiceRegistry getServiceRegistry() {
return (StandardServiceRegistry) serviceRegistry;
}
@Override
public Interceptor getInterceptor() {
@ -634,7 +639,7 @@ public final class SessionFactoryImpl
);
this.serviceRegistry =
metadata.getServiceRegistry()
sessionFactoryOptions.getServiceRegistry()
.getService( SessionFactoryServiceRegistryFactory.class )
.buildServiceRegistry( this, metadata );

View File

@ -78,17 +78,18 @@ public class JaxbMappingProcessor {
private final boolean validateXml;
public JaxbMappingProcessor(ServiceRegistry serviceRegistry) {
this(
serviceRegistry,
serviceRegistry.getService( ConfigurationService.class ).getSetting(
VALIDATE_XML_SETTING,
StandardConverters.BOOLEAN,
true
)
);
this( serviceRegistry, true );
// this(
// serviceRegistry,
// serviceRegistry.getService( ConfigurationService.class ).getSetting(
// VALIDATE_XML_SETTING,
// StandardConverters.BOOLEAN,
// true
// )
// );
}
public JaxbMappingProcessor(ServiceRegistry serviceRegistry, Boolean validateXml) {
public JaxbMappingProcessor(ServiceRegistry serviceRegistry, boolean validateXml) {
this.serviceRegistry = serviceRegistry;
this.validateXml = validateXml;
}

View File

@ -31,6 +31,7 @@ import org.xml.sax.EntityResolver;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.engine.ResultSetMappingDefinition;
@ -51,6 +52,8 @@ public interface Metadata {
* Exposes the options used to produce a {@link Metadata} instance.
*/
public static interface Options {
public StandardServiceRegistry getServiceRegistry();
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
public NamingStrategy getNamingStrategy();
public EntityResolver getEntityResolver();

View File

@ -50,5 +50,5 @@ public interface MetadataBuilder {
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
public Metadata buildMetadata();
public Metadata build();
}

View File

@ -44,6 +44,8 @@ import org.jboss.logging.Logger;
import org.w3c.dom.Document;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.CacheRegionDefinition;
import org.hibernate.jaxb.internal.JaxbMappingProcessor;
import org.hibernate.jaxb.spi.JaxbRoot;
@ -54,8 +56,8 @@ import org.hibernate.metamodel.internal.MetadataBuilderImpl;
import org.hibernate.metamodel.internal.source.annotations.xml.mocker.EntityMappingsMocker;
import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.MappingNotFoundException;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.service.ServiceRegistry;
/**
* Entry point into working with sources of metadata information ({@code hbm.xml}, annotations). Tell Hibernate
@ -66,10 +68,9 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
public class MetadataSources {
private static final Logger LOG = Logger.getLogger( MetadataSources.class );
private final List<CacheRegionDefinition> externalCacheRegionDefinitions = new ArrayList<CacheRegionDefinition>();
private final JaxbMappingProcessor jaxbProcessor;
private final ServiceRegistry serviceRegistry;
private final MetadataBuilderImpl metadataBuilder;
private final JaxbMappingProcessor jaxbProcessor;
private final List<CacheRegionDefinition> externalCacheRegionDefinitions = new ArrayList<CacheRegionDefinition>();
private List<JaxbRoot> jaxbRootList = new ArrayList<JaxbRoot>();
private LinkedHashSet<Class<?>> annotatedClasses = new LinkedHashSet<Class<?>>();
@ -84,10 +85,21 @@ public class MetadataSources {
* @param serviceRegistry The service registry to use.
*/
public MetadataSources(ServiceRegistry serviceRegistry) {
// service registry really should be either BootstrapServiceRegistry or StandardServiceRegistry type...
if ( ! isExpectedServiceRegistryType( serviceRegistry ) ) {
LOG.debugf(
"Unexpected ServiceRegistry type [%s] encountered during building of MetadataSources; may cause " +
"problems later attempting to construct MetadataBuilder",
serviceRegistry.getClass().getName()
);
}
this.serviceRegistry = serviceRegistry;
this.jaxbProcessor = new JaxbMappingProcessor( serviceRegistry );
this.metadataBuilder = new MetadataBuilderImpl( this );
}
protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry) {
return BootstrapServiceRegistry.class.isInstance( serviceRegistry )
|| StandardServiceRegistry.class.isInstance( serviceRegistry );
}
public List<JaxbRoot> getJaxbRootList() {
@ -118,25 +130,37 @@ public class MetadataSources {
return hasOrmXmlJaxbRoots;
}
/**
* Get a builder for metadata where non-default options can be specified.
*
* @return The built metadata.
*/
public MetadataBuilder getMetadataBuilder() {
return metadataBuilder;
return new MetadataBuilderImpl( this );
}
/**
* Get a builder for metadata where non-default options can be specified.
*
* @return The built metadata.
*/
public MetadataBuilder getMetadataBuilder(StandardServiceRegistry serviceRegistry) {
return new MetadataBuilderImpl( this, serviceRegistry );
}
/**
* Short-hand form of calling {@link #getMetadataBuilder()} and using its
* {@link org.hibernate.metamodel.MetadataBuilder#buildMetadata()} method in cases where the application wants
* {@link org.hibernate.metamodel.MetadataBuilder#build()} method in cases where the application wants
* to accept the defaults.
*
* @return The built metadata.
*/
public Metadata buildMetadata() {
return getMetadataBuilder().buildMetadata();
return getMetadataBuilder().build();
}
public Metadata buildMetadata(StandardServiceRegistry serviceRegistry) {
return getMetadataBuilder( serviceRegistry ).build();
}
/**

View File

@ -107,7 +107,7 @@ public interface SessionFactoryBuilder {
/**
* After all options have been set, build the SessionFactory.
*
* @return The built Sessionfactory.
* @return The built SessionFactory.
*/
public SessionFactory buildSessionFactory();
public SessionFactory build();
}

View File

@ -28,7 +28,13 @@ import javax.persistence.SharedCacheMode;
import org.jboss.jandex.IndexView;
import org.xml.sax.EntityResolver;
import org.jboss.logging.Logger;
import org.hibernate.HibernateException;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AvailableSettings;
@ -40,25 +46,60 @@ import org.hibernate.metamodel.MetadataBuilder;
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.spi.MetadataSourcesContributor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.service.ServiceRegistry;
/**
* @author Steve Ebersole
*/
public class MetadataBuilderImpl implements MetadataBuilder {
private static final Logger log = Logger.getLogger( MetadataBuilderImpl.class );
private final MetadataSources sources;
private final OptionsImpl options;
public MetadataBuilderImpl(MetadataSources sources) {
this(
sources,
getStandardServiceRegistry( sources.getServiceRegistry() )
);
}
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
if ( serviceRegistry == null ) {
throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
}
if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
return ( StandardServiceRegistry ) serviceRegistry;
}
else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
log.debugf(
"ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
"if attempt is made to build SessionFactory"
);
return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
}
else {
throw new HibernateException(
String.format(
"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
serviceRegistry.getClass().getName()
)
);
}
}
public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serviceRegistry) {
this.sources = sources;
for ( MetadataSourcesContributor contributor :
sources.getServiceRegistry().getService( ClassLoaderService.class )
.loadJavaServices( MetadataSourcesContributor.class ) ) {
contributor.contribute( sources, null );
}
this.options = new OptionsImpl( sources.getServiceRegistry() );
this.options = new OptionsImpl( serviceRegistry );
}
@Override
@ -104,11 +145,13 @@ public class MetadataBuilderImpl implements MetadataBuilder {
}
@Override
public Metadata buildMetadata() {
public Metadata build() {
return new MetadataImpl( sources, options );
}
public static class OptionsImpl implements Metadata.Options {
private final StandardServiceRegistry serviceRegistry;
private MetadataSourceProcessingOrder metadataSourceProcessingOrder = MetadataSourceProcessingOrder.HBM_FIRST;
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
// todo : entity-resolver maybe needed for ServiceRegistry building also
@ -123,7 +166,9 @@ public class MetadataBuilderImpl implements MetadataBuilder {
private MultiTenancyStrategy multiTenancyStrategy;
public IndexView jandexView;
public OptionsImpl(ServiceRegistry serviceRegistry) {
public OptionsImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
// cache access type
@ -164,6 +209,10 @@ public class MetadataBuilderImpl implements MetadataBuilder {
multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );
}
@Override
public StandardServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder() {

View File

@ -130,7 +130,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
private boolean globallyQuotedIdentifiers = false;
public MetadataImpl(MetadataSources metadataSources, Options options) {
this.serviceRegistry = metadataSources.getServiceRegistry();
this.serviceRegistry = options.getServiceRegistry();
this.options = options;
this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class );
this.database = new Database( options, serviceRegistry.getService( JdbcServices.class ).getJdbcEnvironment() );
@ -195,7 +195,6 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
final List<JaxbRoot> jaxbRoots = new ArrayList<JaxbRoot>();
for ( AdditionalJaxbRootProducer producer : classLoaderService.loadJavaServices( AdditionalJaxbRootProducer.class ) ) {
// todo : handle Jandex index here...
jaxbRoots.addAll( producer.produceRoots( this, jandexView ) );
}
final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( this, jaxbRoots );
@ -603,7 +602,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
@Override
public SessionFactory buildSessionFactory() {
return getSessionFactoryBuilder().buildSessionFactory();
return getSessionFactoryBuilder().build();
}
@Override

View File

@ -36,6 +36,7 @@ import org.hibernate.Interceptor;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
@ -45,7 +46,6 @@ import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.metamodel.SessionFactoryBuilder;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.proxy.EntityNotFoundDelegate;
import org.hibernate.service.ServiceRegistry;
/**
* @author Gail Badner
@ -57,7 +57,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
SessionFactoryBuilderImpl(MetadataImplementor metadata) {
this.metadata = metadata;
options = new SessionFactoryOptionsImpl( metadata.getServiceRegistry() );
options = new SessionFactoryOptionsImpl( metadata.getOptions().getServiceRegistry() );
}
@Override
@ -97,11 +97,13 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
}
@Override
public SessionFactory buildSessionFactory() {
public SessionFactory build() {
return new SessionFactoryImpl( metadata, options );
}
private static class SessionFactoryOptionsImpl implements SessionFactory.SessionFactoryOptions {
private final StandardServiceRegistry serviceRegistry;
private Interceptor interceptor;
private CustomEntityDirtinessStrategy customEntityDirtinessStrategy;
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
@ -109,7 +111,9 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
private List<EntityNameResolver> entityNameResolvers = new ArrayList<EntityNameResolver>();
private EntityNotFoundDelegate entityNotFoundDelegate;
public SessionFactoryOptionsImpl(ServiceRegistry serviceRegistry) {
public SessionFactoryOptionsImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
final Map configurationSettings = serviceRegistry.getService( ConfigurationService.class ).getSettings();
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
@ -139,6 +143,11 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
);
}
@Override
public StandardServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
public Interceptor getInterceptor() {
return interceptor;

View File

@ -26,6 +26,7 @@ package org.hibernate.service;
import java.util.Map;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.StandardServiceRegistry;
/**
* @deprecated Use {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
@ -82,8 +83,7 @@ public class ServiceRegistryBuilder extends org.hibernate.boot.registry.Standard
return this;
}
@Override
public ServiceRegistry buildServiceRegistry() {
return super.buildServiceRegistry();
public StandardServiceRegistry build() {
return super.build();
}
}

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.service.spi;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
/**
* Contract for contributing services.
@ -36,5 +36,5 @@ public interface ServiceContributor {
*
* @param serviceRegistryBuilder The builder to which services (or initiators) should be contributed.
*/
public void contribute(ServiceRegistryBuilder serviceRegistryBuilder);
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder);
}

View File

@ -62,7 +62,7 @@ class ManagedProviderConnectionHelper implements ConnectionHelper {
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
}
public Connection getConnection() throws SQLException {

View File

@ -553,7 +553,7 @@ public class SchemaExport {
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
}
public static void main(String[] args) {

View File

@ -110,7 +110,7 @@ public class SchemaUpdate {
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
}
public static void main(String[] args) {

View File

@ -79,7 +79,7 @@ public class SchemaValidator {
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
}
public static void main(String[] args) {

View File

@ -161,7 +161,7 @@ public class ApplySchemaConstraintTest {
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
final BootstrapServiceRegistry bootstrapServiceRegistry = builder.build();
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry );
return ( StandardServiceRegistryImpl ) registryBuilder.buildServiceRegistry();
return ( StandardServiceRegistryImpl ) registryBuilder.build();
}
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry, Class<?>... classes) {

View File

@ -28,6 +28,8 @@ import java.util.Iterator;
import org.junit.Test;
import org.hibernate.EntityMode;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.id.EntityIdentifierNature;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
@ -45,8 +47,6 @@ import org.hibernate.metamodel.spi.source.SimpleIdentifierSource;
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
import org.hibernate.metamodel.spi.source.TableSource;
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
@ -59,7 +59,7 @@ import static org.junit.Assert.assertTrue;
* @author Steve Ebersole
*/
public class AssertSourcesTest extends BaseUnitTestCase {
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry() ;
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build() ;
@Test
public void testUserEntitySources() {

View File

@ -51,28 +51,28 @@ public class MetadataImplTest extends BaseUnitTestCase {
@Test(expected = IllegalArgumentException.class)
public void testAddingNullClass() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addClass( null );
sources.buildMetadata();
}
@Test(expected = IllegalArgumentException.class)
public void testAddingNullPackageName() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addPackage( null );
sources.buildMetadata();
}
@Test(expected = HibernateException.class)
public void testAddingNonExistingPackageName() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addPackage( "not.a.package" );
sources.buildMetadata();
}
@Test
public void testAddingPackageName() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addPackage( "org.hibernate.metamodel.internal.source" );
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
@ -81,7 +81,7 @@ public class MetadataImplTest extends BaseUnitTestCase {
@Test
public void testAddingPackageNameWithTrailingDot() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addPackage( "org.hibernate.metamodel.internal.source." );
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
@ -90,7 +90,7 @@ public class MetadataImplTest extends BaseUnitTestCase {
@Test
public void testGettingSessionFactoryBuilder() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
Metadata metadata = sources.buildMetadata();
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();

View File

@ -64,7 +64,7 @@ public class SessionFactoryBuilderImplTest extends BaseUnitTestCase {
@Test
public void testBuildSessionFactoryWithDefaultOptions() {
SessionFactoryBuilder sessionFactoryBuilder = getSessionFactoryBuilder();
SessionFactory sessionFactory = sessionFactoryBuilder.buildSessionFactory();
SessionFactory sessionFactory = sessionFactoryBuilder.build();
assertSame( EmptyInterceptor.INSTANCE, sessionFactory.getSessionFactoryOptions().getInterceptor() );
assertTrue( EntityNotFoundDelegate.class.isInstance(
sessionFactory.getSessionFactoryOptions().getEntityNotFoundDelegate()
@ -84,14 +84,14 @@ public class SessionFactoryBuilderImplTest extends BaseUnitTestCase {
};
sessionFactoryBuilder.with( interceptor );
sessionFactoryBuilder.with( entityNotFoundDelegate );
SessionFactory sessionFactory = sessionFactoryBuilder.buildSessionFactory();
SessionFactory sessionFactory = sessionFactoryBuilder.build();
assertSame( interceptor, sessionFactory.getSessionFactoryOptions().getInterceptor() );
assertSame( entityNotFoundDelegate, sessionFactory.getSessionFactoryOptions().getEntityNotFoundDelegate() );
sessionFactory.close();
}
private SessionFactoryBuilder getSessionFactoryBuilder() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addAnnotatedClass( SimpleEntity.class );
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
return metadata.getSessionFactoryBuilder();

View File

@ -152,7 +152,7 @@ public class IdentifierGeneratorTest extends BaseAnnotationBindingTestCase {
@Test
public void testUndefinedGenerator() {
try {
sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addAnnotatedClass( NamedGeneratorEntity.class );
sources.buildMetadata();
fail();

View File

@ -74,7 +74,7 @@ public class MapsIdTest extends BaseAnnotationBindingTestCase {
@Test
public void testMapsIsOnOneToManyThrowsException() {
try {
sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addAnnotatedClass( DependentId.class );
sources.addAnnotatedClass( Dependent.class );
sources.addAnnotatedClass( Employee.class );

View File

@ -59,7 +59,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
service = serviceRegistry.getService( ClassLoaderService.class );
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
}

View File

@ -58,7 +58,7 @@ public class QueryBinderTest extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
service = serviceRegistry.getService( ClassLoaderService.class );
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
}

View File

@ -50,7 +50,7 @@ public abstract class BaseAnnotationIndexTestCase extends BaseUnitTestCase {
@Before
public void setUp() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
meta = (MetadataImpl) sources.buildMetadata();
}

View File

@ -64,7 +64,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
}

View File

@ -40,7 +40,7 @@ import static junit.framework.Assert.assertNotNull;
public class OrmXmlParserTests extends BaseUnitTestCase {
@Test
public void testSimpleOrmVersion2() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addResource( "org/hibernate/metamodel/internal/source/annotations/xml/orm-father.xml" );
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
@ -50,7 +50,7 @@ public class OrmXmlParserTests extends BaseUnitTestCase {
@Test
public void testSimpleOrmVersion1() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addResource( "org/hibernate/metamodel/internal/source/annotations/xml/orm-star.xml" );
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
@ -60,7 +60,7 @@ public class OrmXmlParserTests extends BaseUnitTestCase {
@Test(expected = MappingException.class)
public void testInvalidOrmXmlThrowsException() {
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
sources.addResource( "org/hibernate/metamodel/internal/source/annotations/xml/orm-invalid.xml" );
sources.buildMetadata();
}

View File

@ -70,7 +70,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
}
@After

View File

@ -55,7 +55,7 @@ public abstract class AbstractUnsavedValueTests extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
}
@After

View File

@ -48,7 +48,7 @@ public class JoinedSubclassBindingTests extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
}
@After

View File

@ -48,7 +48,7 @@ public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
}
@After
@ -71,7 +71,7 @@ public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase {
MetadataSources sources = new MetadataSources( serviceRegistry );
sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml" );
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.hbm.xml" );
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).build();
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToMany.class.getName() );
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );

View File

@ -70,10 +70,10 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa
@Before
public void setUp() {
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().build();
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
addSources( metadataSources );
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().buildMetadata();
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().build();
}
@After

View File

@ -71,10 +71,10 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn
@Before
public void setUp() {
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().build();
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
addSources( metadataSources );
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().buildMetadata();
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().build();
}
@After

View File

@ -53,7 +53,7 @@ public abstract class AbstractGeneratedIdColumnTests extends BaseUnitTestCase {
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
}
@After

View File

@ -57,7 +57,7 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
public void testWithoutIntegrator() {
ServiceRegistry reg = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryImpl())
.buildServiceRegistry();
.build();
SessionFactory sf = new Configuration()
.addAnnotatedClass( Investor.class )
@ -82,7 +82,7 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
public void testWithIntegrator() {
ServiceRegistry reg = new StandardServiceRegistryBuilder(
new BootstrapServiceRegistryBuilder().with( new InvestorIntegrator() ).build()
).buildServiceRegistry();
).build();
SessionFactory sf = new Configuration()
.addAnnotatedClass( Investor.class )

View File

@ -45,7 +45,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
cfg.addAnnotatedClass( Gate.class );
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.buildServiceRegistry();
.build();
//no exception as the GoofyPersisterClassProvider is not set
SessionFactory sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close();
@ -54,7 +54,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
.buildServiceRegistry();
.build();
cfg = new Configuration();
cfg.addAnnotatedClass( Gate.class );
try {
@ -79,7 +79,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
.buildServiceRegistry();
.build();
try {
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close();
@ -102,7 +102,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
.buildServiceRegistry();
.build();
try {
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close();

View File

@ -69,7 +69,7 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
public void setUp() throws Exception {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
.build();
}
@After

View File

@ -26,7 +26,7 @@ public class ConfigurationValidationTest extends BaseUnitTestCase {
cfg.setProperty( Environment.MULTI_TENANT_CONNECTION_PROVIDER, "class.not.present.in.classpath" );
cfg.buildMappings();
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() ).buildServiceRegistry();
.applySettings( cfg.getProperties() ).build();
cfg.buildSessionFactory( serviceRegistry );
}
@ -48,7 +48,7 @@ public class ConfigurationValidationTest extends BaseUnitTestCase {
)
)
)
.buildServiceRegistry();
.build();
cfg.buildSessionFactory( serviceRegistry );
}

View File

@ -69,7 +69,7 @@ public class SchemaBasedMultiTenancyTest extends BaseUnitTestCase {
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() )
.addService( MultiTenantConnectionProvider.class, multiTenantConnectionProvider )
.buildServiceRegistry();
.build();
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
}

View File

@ -37,7 +37,6 @@ import org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProv
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.env.ConnectionProviderBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
@ -51,7 +50,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
public void testBasicBuild() {
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
.build();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
@ -68,7 +67,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( props )
.buildServiceRegistry();
.build();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
@ -83,7 +82,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
public void testBuildWithServiceOverride() {
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
.build();
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
@ -95,7 +94,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( props )
.addService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() )
.buildServiceRegistry();
.build();
jdbcServices = serviceRegistry.getService( JdbcServices.class );
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );

View File

@ -56,7 +56,7 @@ public class ExistingDatabaseMetaDataImplTest extends BaseUnitTestCase {
@Before
public void prepare() throws SQLException {
Properties props = Environment.getProperties();
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder().applySettings( props ).buildServiceRegistry();
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder().applySettings( props ).build();
connection = DriverManager.getConnection(
props.getProperty( Environment.URL ),
props.getProperty( Environment.USER ),

View File

@ -0,0 +1,144 @@
/*
* 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.test.smoke;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
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.cfg.AvailableSettings;
import org.hibernate.metamodel.Metadata;
import org.hibernate.metamodel.MetadataSources;
import org.junit.Test;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
/**
* @author Steve Ebersole
*/
@TestForIssue( jiraKey = "HHH-7580" )
public class SessionFactoryBuildingUseCasesTest extends BaseUnitTestCase {
@Test
public void testTheSimplestUseCase() {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
MetadataSources metadataSources = new MetadataSources( registry ).addAnnotatedClass( MyEntity.class );
SessionFactory sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
useSessionFactory( sessionFactory );
sessionFactory.close();
StandardServiceRegistryBuilder.destroy( registry );
}
private void useSessionFactory(SessionFactory sessionFactory) {
Session session = sessionFactory.openSession();
session.beginTransaction();
session.createQuery( "from MyEntity" ).list();
session.getTransaction().commit();
session.close();
}
@Test
public void testStillSimpleOnePhaseUseCase() {
BootstrapServiceRegistry bootRegistry = new BootstrapServiceRegistryBuilder().build();
StandardServiceRegistry registry = new StandardServiceRegistryBuilder( bootRegistry )
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
MetadataSources metadataSources = new MetadataSources( registry ).addAnnotatedClass( MyEntity.class );
SessionFactory sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
useSessionFactory( sessionFactory );
sessionFactory.close();
StandardServiceRegistryBuilder.destroy( registry );
}
@Test
public void testSimpleTwoPhaseUseCase() {
BootstrapServiceRegistry bootRegistry = new BootstrapServiceRegistryBuilder().build();
MetadataSources metadataSources = new MetadataSources( bootRegistry ).addAnnotatedClass( MyEntity.class );
StandardServiceRegistry registry = new StandardServiceRegistryBuilder( bootRegistry )
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
SessionFactory sessionFactory = metadataSources.buildMetadata( registry ).buildSessionFactory();
useSessionFactory( sessionFactory );
sessionFactory.close();
StandardServiceRegistryBuilder.destroy( registry );
}
@Test
public void testFullTwoPhaseUseCase() {
BootstrapServiceRegistry bootRegistry = new BootstrapServiceRegistryBuilder().build();
MetadataSources metadataSources = new MetadataSources( bootRegistry ).addAnnotatedClass( MyEntity.class );
StandardServiceRegistry registry = new StandardServiceRegistryBuilder( bootRegistry )
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
Metadata metadata = metadataSources.getMetadataBuilder( registry ).build();
SessionFactory sessionFactory = metadata.getSessionFactoryBuilder().build(); // todo rename
useSessionFactory( sessionFactory );
sessionFactory.close();
StandardServiceRegistryBuilder.destroy( registry );
}
@Test
@FailureExpected( jiraKey = "HHH-7580" )
public void testInvalidQuasiUseCase() {
BootstrapServiceRegistry bootRegistry = new BootstrapServiceRegistryBuilder().build();
MetadataSources metadataSources = new MetadataSources( bootRegistry ).addAnnotatedClass( MyEntity.class );
StandardServiceRegistry registry = new StandardServiceRegistryBuilder( bootRegistry )
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build();
SessionFactory sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
useSessionFactory( sessionFactory );
sessionFactory.close();
StandardServiceRegistryBuilder.destroy( registry );
}
@Entity( name = "MyEntity" )
@Table( name = "TST_ENT" )
public static class MyEntity {
@Id
private Long id;
}
}

View File

@ -60,7 +60,7 @@ public class TestExpectedUsage extends BaseUnitTestCase {
public void setUp() throws Exception {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
.buildServiceRegistry();
.build();
}
@After

View File

@ -72,7 +72,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
TestingJtaBootstrap.prepare( configValues );
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( configValues )
.buildServiceRegistry();
.build();
}
@After

View File

@ -76,7 +76,7 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( configValues )
.buildServiceRegistry();
.build();
}
@After

View File

@ -81,7 +81,6 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.jpa.boot.spi.IntegratorProvider;
@ -850,7 +849,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
}
public ServiceRegistry buildServiceRegistry() {
return serviceRegistryBuilder.buildServiceRegistry();
return serviceRegistryBuilder.build();
}
public Configuration buildHibernateConfiguration(ServiceRegistry serviceRegistry) {

View File

@ -166,12 +166,12 @@ public class EntityManagerFactoryBuilderUsingMetamodelImpl implements EntityMana
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
prepareMetadataBuilder( metadataBuilder, specialProperties );
final Metadata metadata = metadataBuilder.buildMetadata();
final Metadata metadata = metadataBuilder.build();
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
prepareSessionFactoryBuilder( sessionFactoryBuilder, specialProperties );
sessionFactoryBuilder.add( new ServiceRegistryCloser() );
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.buildSessionFactory();
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.build();
final Settings emfCreationSettings = prepareEntitytManagerFactoryCreationSettings( specialProperties );

View File

@ -78,7 +78,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
@ -94,7 +94,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
@ -148,7 +148,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveAllTest(String configName) throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
@ -166,7 +166,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);

View File

@ -115,7 +115,7 @@ public class NodeEnvironment {
public void prepare() throws Exception {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( configuration.getProperties() )
.buildServiceRegistry();
.build();
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
}

View File

@ -113,7 +113,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void putDoesNotBlockGetTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
@ -213,7 +213,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
private void getDoesNotBlockPutTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);

View File

@ -82,7 +82,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
public void testClearTimestampsRegionInIsolated() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
@ -91,7 +91,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
Configuration cfg2 = createConfiguration();
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg2,
getCacheTestSupport()
);

View File

@ -41,7 +41,7 @@ public class ServiceRegistryBuilder {
public static StandardServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySettings( serviceRegistryConfig )
.buildServiceRegistry();
.build();
}
public static void destroy(ServiceRegistry serviceRegistry) {

View File

@ -1,7 +1,7 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* 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.
@ -34,6 +34,7 @@ import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.metamodel.MetadataBuilder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.spi.binding.EntityBinding;
@ -106,10 +107,11 @@ public abstract class BaseAnnotationBindingTestCase extends BaseUnitTestCase {
private void createBindings() {
try {
sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
MetadataBuilder metadataBuilder = sources.getMetadataBuilder();
Resources resourcesAnnotation = description.getAnnotation( Resources.class );
if ( resourcesAnnotation != null ) {
sources.getMetadataBuilder().with( resourcesAnnotation.cacheMode() );
metadataBuilder.with( resourcesAnnotation.cacheMode() );
for ( Class<?> annotatedClass : resourcesAnnotation.annotatedClasses() ) {
annotatedClasses.add( annotatedClass );
@ -119,7 +121,7 @@ public abstract class BaseAnnotationBindingTestCase extends BaseUnitTestCase {
sources.addResource( resourcesAnnotation.ormXmlPath() );
}
}
meta = ( MetadataImpl ) sources.buildMetadata();
meta = ( MetadataImpl ) metadataBuilder.build();
}
catch ( final Throwable t ) {
setupError = t;

View File

@ -34,13 +34,13 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.junit.After;
import org.junit.Before;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
@ -48,6 +48,7 @@ import org.hibernate.cfg.Environment;
import org.hibernate.cfg.Mappings;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.StringHelper;
@ -59,23 +60,22 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.metamodel.spi.MetadataImplementor;
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
import org.hibernate.metamodel.spi.binding.AttributeBinding;
import org.hibernate.metamodel.spi.binding.Caching;
import org.hibernate.metamodel.spi.binding.EntityBinding;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.type.Type;
import org.junit.After;
import org.junit.Before;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.BeforeClassOnce;
import org.hibernate.testing.OnExpectedFailure;
import org.hibernate.testing.OnFailure;
import org.hibernate.testing.SkipLog;
import org.hibernate.testing.cache.CachingRegionFactory;
import org.hibernate.type.Type;
import static org.junit.Assert.fail;
@ -132,7 +132,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
protected void buildSessionFactory() {
// for now, build the configuration to get all the property settings
configuration = constructAndConfigureConfiguration();
serviceRegistry = buildServiceRegistry( configuration );
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
isMetadataUsed = serviceRegistry.getService( ConfigurationService.class ).getSetting(
USE_NEW_METADATA_MAPPINGS,
new ConfigurationService.Converter<Boolean>() {
@ -144,7 +145,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
true
);
if ( isMetadataUsed ) {
MetadataImplementor metadataImplementor = buildMetadata( serviceRegistry );
MetadataImplementor metadataImplementor = buildMetadata( bootRegistry, serviceRegistry );
afterConstructAndConfigureMetadata( metadataImplementor );
applyCacheSettings(metadataImplementor);
sessionFactory = ( SessionFactoryImplementor ) metadataImplementor.buildSessionFactory();
@ -169,10 +170,12 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
}
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry) {
MetadataSources sources = new MetadataSources( serviceRegistry );
addMappings( sources );
return (MetadataImplementor) sources.buildMetadata();
private MetadataImplementor buildMetadata(
BootstrapServiceRegistry bootRegistry,
StandardServiceRegistryImpl serviceRegistry) {
MetadataSources sources = new MetadataSources( bootRegistry );
addMappings( sources );
return (MetadataImplementor) sources.getMetadataBuilder( serviceRegistry ).build();
}
// TODO: is this still needed?
@ -392,20 +395,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
protected void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
}
protected StandardServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
Properties properties = new Properties();
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
final BootstrapServiceRegistry bootstrapServiceRegistry = generateBootstrapRegistry( properties );
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry )
.applySettings( properties );
prepareBasicRegistryBuilder( registryBuilder );
return (StandardServiceRegistryImpl) registryBuilder.buildServiceRegistry();
}
protected BootstrapServiceRegistry generateBootstrapRegistry(Properties properties) {
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
prepareBootstrapRegistryBuilder( builder );
return builder.build();
@ -414,6 +404,17 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
}
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
Properties properties = new Properties();
properties.putAll( configuration.getProperties() );
Environment.verifyProperties( properties );
ConfigurationHelper.resolvePlaceHolders( properties );
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry ).applySettings( properties );
prepareBasicRegistryBuilder( registryBuilder );
return (StandardServiceRegistryImpl) registryBuilder.build();
}
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
}