HHH-7580 - Complete 2-phase SessionFactory building design
This commit is contained in:
parent
ea2b9a899f
commit
7042790a53
|
@ -29,6 +29,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.naming.Referenceable;
|
import javax.naming.Referenceable;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
import org.hibernate.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
|
@ -55,6 +56,7 @@ import org.hibernate.stat.Statistics;
|
||||||
public interface SessionFactory extends Referenceable, Serializable {
|
public interface SessionFactory extends Referenceable, Serializable {
|
||||||
|
|
||||||
public interface SessionFactoryOptions {
|
public interface SessionFactoryOptions {
|
||||||
|
public StandardServiceRegistry getServiceRegistry();
|
||||||
public Interceptor getInterceptor();
|
public Interceptor getInterceptor();
|
||||||
public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy();
|
public CustomEntityDirtinessStrategy getCustomEntityDirtinessStrategy();
|
||||||
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
|
public CurrentTenantIdentifierResolver getCurrentTenantIdentifierResolver();
|
||||||
|
|
|
@ -23,7 +23,9 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.boot.registry;
|
package org.hibernate.boot.registry;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
||||||
import org.hibernate.boot.registry.selector.Availability;
|
import org.hibernate.boot.registry.selector.Availability;
|
||||||
|
@ -43,10 +45,7 @@ import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
|
||||||
*/
|
*/
|
||||||
public class BootstrapServiceRegistryBuilder {
|
public class BootstrapServiceRegistryBuilder {
|
||||||
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
|
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
|
||||||
private ClassLoader applicationClassLoader;
|
private List<ClassLoader> providedClassLoaders;
|
||||||
private ClassLoader resourcesClassLoader;
|
|
||||||
private ClassLoader hibernateClassLoader;
|
|
||||||
private ClassLoader environmentClassLoader;
|
|
||||||
|
|
||||||
private StrategySelectorBuilder strategySelectorBuilder = new StrategySelectorBuilder();
|
private StrategySelectorBuilder strategySelectorBuilder = new StrategySelectorBuilder();
|
||||||
|
|
||||||
|
@ -61,16 +60,33 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
return this;
|
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
|
* Applies the specified {@link ClassLoader} as the application class loader for the bootstrap registry
|
||||||
*
|
*
|
||||||
* @param classLoader The class loader to use
|
* @param classLoader The class loader to use
|
||||||
* @return {@code this}, for method chaining
|
* @return {@code this}, for method chaining
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #with(ClassLoader)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@SuppressWarnings( {"UnusedDeclaration"})
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
public BootstrapServiceRegistryBuilder withApplicationClassLoader(ClassLoader classLoader) {
|
public BootstrapServiceRegistryBuilder withApplicationClassLoader(ClassLoader classLoader) {
|
||||||
this.applicationClassLoader = classLoader;
|
return with( classLoader );
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,11 +94,13 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
*
|
*
|
||||||
* @param classLoader The class loader to use
|
* @param classLoader The class loader to use
|
||||||
* @return {@code this}, for method chaining
|
* @return {@code this}, for method chaining
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #with(ClassLoader)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@SuppressWarnings( {"UnusedDeclaration"})
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
public BootstrapServiceRegistryBuilder withResourceClassLoader(ClassLoader classLoader) {
|
public BootstrapServiceRegistryBuilder withResourceClassLoader(ClassLoader classLoader) {
|
||||||
this.resourcesClassLoader = classLoader;
|
return with( classLoader );
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,11 +108,13 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
*
|
*
|
||||||
* @param classLoader The class loader to use
|
* @param classLoader The class loader to use
|
||||||
* @return {@code this}, for method chaining
|
* @return {@code this}, for method chaining
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #with(ClassLoader)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@SuppressWarnings( {"UnusedDeclaration"})
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
public BootstrapServiceRegistryBuilder withHibernateClassLoader(ClassLoader classLoader) {
|
public BootstrapServiceRegistryBuilder withHibernateClassLoader(ClassLoader classLoader) {
|
||||||
this.hibernateClassLoader = classLoader;
|
return with( classLoader );
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,11 +122,13 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
*
|
*
|
||||||
* @param classLoader The class loader to use
|
* @param classLoader The class loader to use
|
||||||
* @return {@code this}, for method chaining
|
* @return {@code this}, for method chaining
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #with(ClassLoader)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@SuppressWarnings( {"UnusedDeclaration"})
|
@SuppressWarnings( {"UnusedDeclaration"})
|
||||||
public BootstrapServiceRegistryBuilder withEnvironmentClassLoader(ClassLoader classLoader) {
|
public BootstrapServiceRegistryBuilder withEnvironmentClassLoader(ClassLoader classLoader) {
|
||||||
this.environmentClassLoader = classLoader;
|
return with( classLoader );
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,12 +171,7 @@ public class BootstrapServiceRegistryBuilder {
|
||||||
* @return The built bootstrap registry
|
* @return The built bootstrap registry
|
||||||
*/
|
*/
|
||||||
public BootstrapServiceRegistry build() {
|
public BootstrapServiceRegistry build() {
|
||||||
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
|
final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl( providedClassLoaders );
|
||||||
applicationClassLoader,
|
|
||||||
resourcesClassLoader,
|
|
||||||
hibernateClassLoader,
|
|
||||||
environmentClassLoader
|
|
||||||
);
|
|
||||||
|
|
||||||
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
|
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
|
||||||
providedIntegrators,
|
providedIntegrators,
|
||||||
|
|
|
@ -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 {
|
||||||
|
}
|
|
@ -25,14 +25,15 @@ package org.hibernate.boot.registry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.integrator.spi.IntegratorService;
|
import org.hibernate.integrator.spi.IntegratorService;
|
||||||
import org.hibernate.integrator.spi.ServiceContributingIntegrator;
|
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
||||||
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
|
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.StandardServiceInitiators;
|
||||||
import org.hibernate.service.internal.ProvidedService;
|
import org.hibernate.service.internal.ProvidedService;
|
||||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||||
|
import org.hibernate.service.spi.ServiceContributor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for standard {@link org.hibernate.service.ServiceRegistry} instances.
|
* Builder for standard {@link org.hibernate.service.ServiceRegistry} instances.
|
||||||
|
@ -65,7 +67,7 @@ public class StandardServiceRegistryBuilder {
|
||||||
* Create a default builder
|
* Create a default builder
|
||||||
*/
|
*/
|
||||||
public StandardServiceRegistryBuilder() {
|
public StandardServiceRegistryBuilder() {
|
||||||
this( new BootstrapServiceRegistryImpl() );
|
this( new BootstrapServiceRegistryBuilder().build() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,26 +195,35 @@ public class StandardServiceRegistryBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public StandardServiceRegistry build() {
|
||||||
* Build the service registry accounting for all settings and service initiators and services.
|
|
||||||
*
|
|
||||||
* @return The built service registry
|
|
||||||
*/
|
|
||||||
public ServiceRegistry buildServiceRegistry() {
|
|
||||||
Map<?,?> settingsCopy = new HashMap();
|
Map<?,?> settingsCopy = new HashMap();
|
||||||
settingsCopy.putAll( settings );
|
settingsCopy.putAll( settings );
|
||||||
Environment.verifyProperties( settingsCopy );
|
Environment.verifyProperties( settingsCopy );
|
||||||
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
|
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
|
||||||
|
|
||||||
for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
|
applyServiceContributingIntegrators();
|
||||||
if ( ServiceContributingIntegrator.class.isInstance( integrator ) ) {
|
applyServiceContributors();
|
||||||
ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new StandardServiceRegistryImpl( bootstrapServiceRegistry, initiators, providedServices, settingsCopy );
|
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.
|
* Destroy a service registry. Applications should only destroy registries they have explicitly created.
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,6 +27,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -49,75 +51,71 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
public class ClassLoaderServiceImpl implements ClassLoaderService {
|
public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
|
||||||
|
|
||||||
private final ClassLoader classClassLoader;
|
private final ClassLoader aggregatedClassLoader;
|
||||||
private final ClassLoader resourcesClassLoader;
|
|
||||||
private final ClassLoader serviceLoaderClassLoader;
|
|
||||||
|
|
||||||
public ClassLoaderServiceImpl() {
|
public ClassLoaderServiceImpl() {
|
||||||
this( ClassLoaderServiceImpl.class.getClassLoader() );
|
this( ClassLoaderServiceImpl.class.getClassLoader() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoaderServiceImpl(ClassLoader classLoader) {
|
public ClassLoaderServiceImpl(ClassLoader classLoader) {
|
||||||
this( classLoader, classLoader, classLoader, classLoader );
|
this( Collections.singletonList( classLoader ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoaderServiceImpl(
|
public ClassLoaderServiceImpl(List<ClassLoader> providedClassLoaders) {
|
||||||
ClassLoader applicationClassLoader,
|
final LinkedHashSet<ClassLoader> orderedClassLoaderSet = new LinkedHashSet<ClassLoader>();
|
||||||
ClassLoader resourcesClassLoader,
|
|
||||||
ClassLoader hibernateClassLoader,
|
|
||||||
ClassLoader environmentClassLoader) {
|
|
||||||
// Normalize missing loaders
|
|
||||||
if ( hibernateClassLoader == null ) {
|
|
||||||
hibernateClassLoader = ClassLoaderServiceImpl.class.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( environmentClassLoader == null || applicationClassLoader == null ) {
|
// first add all provided class loaders, if any
|
||||||
ClassLoader sysClassLoader = locateSystemClassLoader();
|
if ( providedClassLoaders != null ) {
|
||||||
ClassLoader tccl = locateTCCL();
|
for ( ClassLoader classLoader : providedClassLoaders ) {
|
||||||
if ( environmentClassLoader == null ) {
|
if ( classLoader != null ) {
|
||||||
environmentClassLoader = sysClassLoader != null ? sysClassLoader : hibernateClassLoader;
|
orderedClassLoaderSet.add( classLoader );
|
||||||
}
|
|
||||||
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) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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) {
|
public static ClassLoaderServiceImpl fromConfigSettings(Map configVales) {
|
||||||
return new ClassLoaderServiceImpl(
|
final List<ClassLoader> providedClassLoaders = new ArrayList<ClassLoader>();
|
||||||
(ClassLoader) configVales.get( AvailableSettings.APP_CLASSLOADER ),
|
|
||||||
(ClassLoader) configVales.get( AvailableSettings.RESOURCES_CLASSLOADER ),
|
final Collection<ClassLoader> classLoaders = (Collection<ClassLoader>) configVales.get( AvailableSettings.CLASSLOADERS );
|
||||||
(ClassLoader) configVales.get( AvailableSettings.HIBERNATE_CLASSLOADER ),
|
if ( classLoaders != null ) {
|
||||||
(ClassLoader) configVales.get( AvailableSettings.ENVIRONMENT_CLASSLOADER )
|
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() {
|
private static ClassLoader locateSystemClassLoader() {
|
||||||
|
@ -138,73 +136,69 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassLoader buildServiceLoaderClassLoader() {
|
private static class AggregatedClassLoader extends ClassLoader {
|
||||||
return new ClassLoader(null) {
|
private final ClassLoader[] individualClassLoaders;
|
||||||
final ClassLoader[] classLoaderArray = new ClassLoader[] {
|
|
||||||
// first look on the hibernate class loader
|
private AggregatedClassLoader(final LinkedHashSet<ClassLoader> orderedClassLoaderSet) {
|
||||||
getClass().getClassLoader(),
|
super( null );
|
||||||
// next look on the resource class loader
|
individualClassLoaders = orderedClassLoaderSet.toArray( new ClassLoader[ orderedClassLoaderSet.size() ] );
|
||||||
resourcesClassLoader,
|
}
|
||||||
// finally look on the combined class class loader
|
|
||||||
classClassLoader
|
@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
|
@Override
|
||||||
public Enumeration<URL> getResources(String name) throws IOException {
|
protected URL findResource(String name) {
|
||||||
final HashSet<URL> resourceUrls = new HashSet<URL>();
|
for ( ClassLoader classLoader : individualClassLoaders ) {
|
||||||
|
final URL resource = classLoader.getResource( name );
|
||||||
for ( ClassLoader classLoader : classLoaderArray ) {
|
if ( resource != null ) {
|
||||||
final Enumeration<URL> urls = classLoader.getResources( name );
|
return resource;
|
||||||
while ( urls.hasMoreElements() ) {
|
|
||||||
resourceUrls.add( urls.nextElement() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return super.findResource( name );
|
||||||
|
}
|
||||||
|
|
||||||
return new Enumeration<URL>() {
|
@Override
|
||||||
final Iterator<URL> resourceUrlIterator = resourceUrls.iterator();
|
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
@Override
|
for ( ClassLoader classLoader : individualClassLoaders ) {
|
||||||
public boolean hasMoreElements() {
|
try {
|
||||||
return resourceUrlIterator.hasNext();
|
return classLoader.loadClass( name );
|
||||||
}
|
}
|
||||||
|
catch (Exception ignore) {
|
||||||
@Override
|
}
|
||||||
public URL nextElement() {
|
|
||||||
return resourceUrlIterator.next();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
throw new ClassNotFoundException( "Could not load requested class : " + name );
|
||||||
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 );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
public <T> Class<T> classForName(String className) {
|
public <T> Class<T> classForName(String className) {
|
||||||
try {
|
try {
|
||||||
return (Class<T>) Class.forName( className, true, classClassLoader );
|
return (Class<T>) Class.forName( className, true, aggregatedClassLoader );
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new ClassLoadingException( "Unable to load class [" + className + "]", e );
|
throw new ClassLoadingException( "Unable to load class [" + className + "]", e );
|
||||||
|
@ -221,7 +215,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return resourcesClassLoader.getResource( name );
|
return aggregatedClassLoader.getResource( name );
|
||||||
}
|
}
|
||||||
catch ( Exception ignore ) {
|
catch ( Exception ignore ) {
|
||||||
}
|
}
|
||||||
|
@ -241,7 +235,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", name );
|
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", name );
|
||||||
InputStream stream = resourcesClassLoader.getResourceAsStream( name );
|
InputStream stream = aggregatedClassLoader.getResourceAsStream( name );
|
||||||
if ( stream != null ) {
|
if ( stream != null ) {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +255,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", stripped );
|
log.tracef( "trying via [ClassLoader.getResourceAsStream(\"%s\")]", stripped );
|
||||||
InputStream stream = resourcesClassLoader.getResourceAsStream( stripped );
|
InputStream stream = aggregatedClassLoader.getResourceAsStream( stripped );
|
||||||
if ( stream != null ) {
|
if ( stream != null ) {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +271,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
public List<URL> locateResources(String name) {
|
public List<URL> locateResources(String name) {
|
||||||
ArrayList<URL> urls = new ArrayList<URL>();
|
ArrayList<URL> urls = new ArrayList<URL>();
|
||||||
try {
|
try {
|
||||||
Enumeration<URL> urlEnumeration = resourcesClassLoader.getResources( name );
|
Enumeration<URL> urlEnumeration = aggregatedClassLoader.getResources( name );
|
||||||
if ( urlEnumeration != null && urlEnumeration.hasMoreElements() ) {
|
if ( urlEnumeration != null && urlEnumeration.hasMoreElements() ) {
|
||||||
while ( urlEnumeration.hasMoreElements() ) {
|
while ( urlEnumeration.hasMoreElements() ) {
|
||||||
urls.add( urlEnumeration.nextElement() );
|
urls.add( urlEnumeration.nextElement() );
|
||||||
|
@ -292,7 +286,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
|
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>();
|
final LinkedHashSet<S> services = new LinkedHashSet<S>();
|
||||||
for ( S service : loader ) {
|
for ( S service : loader ) {
|
||||||
services.add( service );
|
services.add( service );
|
||||||
|
@ -315,7 +309,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
boolean set = false;
|
boolean set = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader( serviceLoaderClassLoader);
|
Thread.currentThread().setContextClassLoader( aggregatedClassLoader );
|
||||||
set = true;
|
set = true;
|
||||||
}
|
}
|
||||||
catch (Exception ignore) {
|
catch (Exception ignore) {
|
||||||
|
|
|
@ -28,8 +28,8 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.service.internal.AbstractServiceRegistryImpl;
|
import org.hibernate.service.internal.AbstractServiceRegistryImpl;
|
||||||
import org.hibernate.service.internal.ProvidedService;
|
import org.hibernate.service.internal.ProvidedService;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
|
@ -41,7 +41,7 @@ import org.hibernate.service.spi.ServiceInitiator;
|
||||||
*
|
*
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl implements ServiceRegistry {
|
public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl implements StandardServiceRegistry {
|
||||||
private final Map configurationValues;
|
private final Map configurationValues;
|
||||||
|
|
||||||
@SuppressWarnings( {"unchecked"})
|
@SuppressWarnings( {"unchecked"})
|
||||||
|
|
|
@ -471,30 +471,47 @@ public interface AvailableSettings {
|
||||||
*/
|
*/
|
||||||
public static final String NON_CONTEXTUAL_LOB_CREATION = "hibernate.jdbc.lob.non_contextual_creation";
|
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.
|
* Names the {@link ClassLoader} used to load user application classes.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link #CLASSLOADERS} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String APP_CLASSLOADER = "hibernate.classLoader.application";
|
public static final String APP_CLASSLOADER = "hibernate.classLoader.application";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Names the {@link ClassLoader} Hibernate should use to perform resource loading.
|
* Names the {@link ClassLoader} Hibernate should use to perform resource loading.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
* @deprecated Use {@link #CLASSLOADERS} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String RESOURCES_CLASSLOADER = "hibernate.classLoader.resources";
|
public static final String RESOURCES_CLASSLOADER = "hibernate.classLoader.resources";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Names the {@link ClassLoader} responsible for loading Hibernate classes. By default this is
|
* Names the {@link ClassLoader} responsible for loading Hibernate classes. By default this is
|
||||||
* the {@link ClassLoader} that loaded this class.
|
* the {@link ClassLoader} that loaded this class.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
* @deprecated Use {@link #CLASSLOADERS} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String HIBERNATE_CLASSLOADER = "hibernate.classLoader.hibernate";
|
public static final String HIBERNATE_CLASSLOADER = "hibernate.classLoader.hibernate";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Names the {@link ClassLoader} used when Hibernate is unable to locates classes on the
|
* Names the {@link ClassLoader} used when Hibernate is unable to locates classes on the
|
||||||
* {@link #APP_CLASSLOADER} or {@link #HIBERNATE_CLASSLOADER}.
|
* {@link #APP_CLASSLOADER} or {@link #HIBERNATE_CLASSLOADER}.
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
* @deprecated Use {@link #CLASSLOADERS} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static final String ENVIRONMENT_CLASSLOADER = "hibernate.classLoader.environment";
|
public static final String ENVIRONMENT_CLASSLOADER = "hibernate.classLoader.environment";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1776,7 +1776,7 @@ public class Configuration implements Serializable {
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySettings( properties )
|
.applySettings( properties )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
setSessionFactoryObserver(
|
setSessionFactoryObserver(
|
||||||
new SessionFactoryObserver() {
|
new SessionFactoryObserver() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -66,7 +66,7 @@ import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
* Properties may be either be <tt>System</tt> properties, properties
|
* Properties may be either be <tt>System</tt> properties, properties
|
||||||
* defined in a resource named <tt>/hibernate.properties</tt> or an instance of
|
* defined in a resource named <tt>/hibernate.properties</tt> or an instance of
|
||||||
* <tt>java.util.Properties</tt> passed to
|
* <tt>java.util.Properties</tt> passed to
|
||||||
* <tt>Configuration.buildSessionFactory()</tt><br>
|
* <tt>Configuration.build()</tt><br>
|
||||||
* <br>
|
* <br>
|
||||||
* <table>
|
* <table>
|
||||||
* <tr><td><b>property</b></td><td><b>meaning</b></td></tr>
|
* <tr><td><b>property</b></td><td><b>meaning</b></td></tr>
|
||||||
|
|
|
@ -3014,7 +3014,7 @@ public final class HbmBinder {
|
||||||
//TODO: bad implementation, cos it depends upon ordering of mapping doc
|
//TODO: bad implementation, cos it depends upon ordering of mapping doc
|
||||||
// fixing this requires that Collection/PersistentClass gain access
|
// fixing this requires that Collection/PersistentClass gain access
|
||||||
// to the Mappings reference from Configuration (or the filterDefinitions
|
// 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
|
// (after all the types/filter-defs are known and before building
|
||||||
// persisters).
|
// persisters).
|
||||||
if ( StringHelper.isEmpty(condition) ) {
|
if ( StringHelper.isEmpty(condition) ) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ import org.hibernate.SessionFactoryObserver;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
import org.hibernate.StatelessSessionBuilder;
|
import org.hibernate.StatelessSessionBuilder;
|
||||||
import org.hibernate.TypeHelper;
|
import org.hibernate.TypeHelper;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.cache.internal.CacheDataDescriptionImpl;
|
import org.hibernate.cache.internal.CacheDataDescriptionImpl;
|
||||||
import org.hibernate.cache.spi.CollectionRegion;
|
import org.hibernate.cache.spi.CollectionRegion;
|
||||||
|
@ -258,6 +259,10 @@ public final class SessionFactoryImpl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StandardServiceRegistry getServiceRegistry() {
|
||||||
|
return (StandardServiceRegistry) serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Interceptor getInterceptor() {
|
public Interceptor getInterceptor() {
|
||||||
|
@ -634,7 +639,7 @@ public final class SessionFactoryImpl
|
||||||
);
|
);
|
||||||
|
|
||||||
this.serviceRegistry =
|
this.serviceRegistry =
|
||||||
metadata.getServiceRegistry()
|
sessionFactoryOptions.getServiceRegistry()
|
||||||
.getService( SessionFactoryServiceRegistryFactory.class )
|
.getService( SessionFactoryServiceRegistryFactory.class )
|
||||||
.buildServiceRegistry( this, metadata );
|
.buildServiceRegistry( this, metadata );
|
||||||
|
|
||||||
|
|
|
@ -78,17 +78,18 @@ public class JaxbMappingProcessor {
|
||||||
private final boolean validateXml;
|
private final boolean validateXml;
|
||||||
|
|
||||||
public JaxbMappingProcessor(ServiceRegistry serviceRegistry) {
|
public JaxbMappingProcessor(ServiceRegistry serviceRegistry) {
|
||||||
this(
|
this( serviceRegistry, true );
|
||||||
serviceRegistry,
|
// this(
|
||||||
serviceRegistry.getService( ConfigurationService.class ).getSetting(
|
// serviceRegistry,
|
||||||
VALIDATE_XML_SETTING,
|
// serviceRegistry.getService( ConfigurationService.class ).getSetting(
|
||||||
StandardConverters.BOOLEAN,
|
// VALIDATE_XML_SETTING,
|
||||||
true
|
// StandardConverters.BOOLEAN,
|
||||||
)
|
// true
|
||||||
);
|
// )
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
public JaxbMappingProcessor(ServiceRegistry serviceRegistry, Boolean validateXml) {
|
public JaxbMappingProcessor(ServiceRegistry serviceRegistry, boolean validateXml) {
|
||||||
this.serviceRegistry = serviceRegistry;
|
this.serviceRegistry = serviceRegistry;
|
||||||
this.validateXml = validateXml;
|
this.validateXml = validateXml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.xml.sax.EntityResolver;
|
||||||
|
|
||||||
import org.hibernate.MultiTenancyStrategy;
|
import org.hibernate.MultiTenancyStrategy;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||||
|
@ -51,6 +52,8 @@ public interface Metadata {
|
||||||
* Exposes the options used to produce a {@link Metadata} instance.
|
* Exposes the options used to produce a {@link Metadata} instance.
|
||||||
*/
|
*/
|
||||||
public static interface Options {
|
public static interface Options {
|
||||||
|
public StandardServiceRegistry getServiceRegistry();
|
||||||
|
|
||||||
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
|
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder();
|
||||||
public NamingStrategy getNamingStrategy();
|
public NamingStrategy getNamingStrategy();
|
||||||
public EntityResolver getEntityResolver();
|
public EntityResolver getEntityResolver();
|
||||||
|
|
|
@ -50,5 +50,5 @@ public interface MetadataBuilder {
|
||||||
|
|
||||||
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
|
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
|
||||||
|
|
||||||
public Metadata buildMetadata();
|
public Metadata build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ import org.jboss.logging.Logger;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
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.boot.spi.CacheRegionDefinition;
|
||||||
import org.hibernate.jaxb.internal.JaxbMappingProcessor;
|
import org.hibernate.jaxb.internal.JaxbMappingProcessor;
|
||||||
import org.hibernate.jaxb.spi.JaxbRoot;
|
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.internal.source.annotations.xml.mocker.EntityMappingsMocker;
|
||||||
import org.hibernate.metamodel.spi.source.MappingException;
|
import org.hibernate.metamodel.spi.source.MappingException;
|
||||||
import org.hibernate.metamodel.spi.source.MappingNotFoundException;
|
import org.hibernate.metamodel.spi.source.MappingNotFoundException;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
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
|
* 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 {
|
public class MetadataSources {
|
||||||
private static final Logger LOG = Logger.getLogger( MetadataSources.class );
|
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 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 List<JaxbRoot> jaxbRootList = new ArrayList<JaxbRoot>();
|
||||||
private LinkedHashSet<Class<?>> annotatedClasses = new LinkedHashSet<Class<?>>();
|
private LinkedHashSet<Class<?>> annotatedClasses = new LinkedHashSet<Class<?>>();
|
||||||
|
@ -84,10 +85,21 @@ public class MetadataSources {
|
||||||
* @param serviceRegistry The service registry to use.
|
* @param serviceRegistry The service registry to use.
|
||||||
*/
|
*/
|
||||||
public MetadataSources(ServiceRegistry serviceRegistry) {
|
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.serviceRegistry = serviceRegistry;
|
||||||
|
|
||||||
this.jaxbProcessor = new JaxbMappingProcessor( 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() {
|
public List<JaxbRoot> getJaxbRootList() {
|
||||||
|
@ -118,25 +130,37 @@ public class MetadataSources {
|
||||||
return hasOrmXmlJaxbRoots;
|
return hasOrmXmlJaxbRoots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a builder for metadata where non-default options can be specified.
|
* Get a builder for metadata where non-default options can be specified.
|
||||||
*
|
*
|
||||||
* @return The built metadata.
|
* @return The built metadata.
|
||||||
*/
|
*/
|
||||||
public MetadataBuilder getMetadataBuilder() {
|
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
|
* 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.
|
* to accept the defaults.
|
||||||
*
|
*
|
||||||
* @return The built metadata.
|
* @return The built metadata.
|
||||||
*/
|
*/
|
||||||
public Metadata buildMetadata() {
|
public Metadata buildMetadata() {
|
||||||
return getMetadataBuilder().buildMetadata();
|
return getMetadataBuilder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Metadata buildMetadata(StandardServiceRegistry serviceRegistry) {
|
||||||
|
return getMetadataBuilder( serviceRegistry ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -107,7 +107,7 @@ public interface SessionFactoryBuilder {
|
||||||
/**
|
/**
|
||||||
* After all options have been set, build the SessionFactory.
|
* After all options have been set, build the SessionFactory.
|
||||||
*
|
*
|
||||||
* @return The built Sessionfactory.
|
* @return The built SessionFactory.
|
||||||
*/
|
*/
|
||||||
public SessionFactory buildSessionFactory();
|
public SessionFactory build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,13 @@ import javax.persistence.SharedCacheMode;
|
||||||
import org.jboss.jandex.IndexView;
|
import org.jboss.jandex.IndexView;
|
||||||
import org.xml.sax.EntityResolver;
|
import org.xml.sax.EntityResolver;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MultiTenancyStrategy;
|
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.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
@ -40,25 +46,60 @@ import org.hibernate.metamodel.MetadataBuilder;
|
||||||
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
|
import org.hibernate.metamodel.MetadataSourceProcessingOrder;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.spi.MetadataSourcesContributor;
|
import org.hibernate.metamodel.spi.MetadataSourcesContributor;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
import org.hibernate.engine.config.spi.StandardConverters;
|
import org.hibernate.engine.config.spi.StandardConverters;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class MetadataBuilderImpl implements MetadataBuilder {
|
public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
|
private static final Logger log = Logger.getLogger( MetadataBuilderImpl.class );
|
||||||
|
|
||||||
private final MetadataSources sources;
|
private final MetadataSources sources;
|
||||||
private final OptionsImpl options;
|
private final OptionsImpl options;
|
||||||
|
|
||||||
public MetadataBuilderImpl(MetadataSources sources) {
|
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;
|
this.sources = sources;
|
||||||
|
|
||||||
for ( MetadataSourcesContributor contributor :
|
for ( MetadataSourcesContributor contributor :
|
||||||
sources.getServiceRegistry().getService( ClassLoaderService.class )
|
sources.getServiceRegistry().getService( ClassLoaderService.class )
|
||||||
.loadJavaServices( MetadataSourcesContributor.class ) ) {
|
.loadJavaServices( MetadataSourcesContributor.class ) ) {
|
||||||
contributor.contribute( sources, null );
|
contributor.contribute( sources, null );
|
||||||
}
|
}
|
||||||
this.options = new OptionsImpl( sources.getServiceRegistry() );
|
this.options = new OptionsImpl( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,11 +145,13 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Metadata buildMetadata() {
|
public Metadata build() {
|
||||||
return new MetadataImpl( sources, options );
|
return new MetadataImpl( sources, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OptionsImpl implements Metadata.Options {
|
public static class OptionsImpl implements Metadata.Options {
|
||||||
|
private final StandardServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
private MetadataSourceProcessingOrder metadataSourceProcessingOrder = MetadataSourceProcessingOrder.HBM_FIRST;
|
private MetadataSourceProcessingOrder metadataSourceProcessingOrder = MetadataSourceProcessingOrder.HBM_FIRST;
|
||||||
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
|
private NamingStrategy namingStrategy = EJB3NamingStrategy.INSTANCE;
|
||||||
// todo : entity-resolver maybe needed for ServiceRegistry building also
|
// todo : entity-resolver maybe needed for ServiceRegistry building also
|
||||||
|
@ -123,7 +166,9 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
private MultiTenancyStrategy multiTenancyStrategy;
|
private MultiTenancyStrategy multiTenancyStrategy;
|
||||||
public IndexView jandexView;
|
public IndexView jandexView;
|
||||||
|
|
||||||
public OptionsImpl(ServiceRegistry serviceRegistry) {
|
public OptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
|
||||||
ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
||||||
|
|
||||||
// cache access type
|
// cache access type
|
||||||
|
@ -164,6 +209,10 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );
|
multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StandardServiceRegistry getServiceRegistry() {
|
||||||
|
return serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder() {
|
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder() {
|
||||||
|
|
|
@ -130,7 +130,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
private boolean globallyQuotedIdentifiers = false;
|
private boolean globallyQuotedIdentifiers = false;
|
||||||
|
|
||||||
public MetadataImpl(MetadataSources metadataSources, Options options) {
|
public MetadataImpl(MetadataSources metadataSources, Options options) {
|
||||||
this.serviceRegistry = metadataSources.getServiceRegistry();
|
this.serviceRegistry = options.getServiceRegistry();
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class );
|
this.identifierGeneratorFactory = serviceRegistry.getService( MutableIdentifierGeneratorFactory.class );
|
||||||
this.database = new Database( options, serviceRegistry.getService( JdbcServices.class ).getJdbcEnvironment() );
|
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>();
|
final List<JaxbRoot> jaxbRoots = new ArrayList<JaxbRoot>();
|
||||||
for ( AdditionalJaxbRootProducer producer : classLoaderService.loadJavaServices( AdditionalJaxbRootProducer.class ) ) {
|
for ( AdditionalJaxbRootProducer producer : classLoaderService.loadJavaServices( AdditionalJaxbRootProducer.class ) ) {
|
||||||
// todo : handle Jandex index here...
|
|
||||||
jaxbRoots.addAll( producer.produceRoots( this, jandexView ) );
|
jaxbRoots.addAll( producer.produceRoots( this, jandexView ) );
|
||||||
}
|
}
|
||||||
final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( this, jaxbRoots );
|
final HbmMetadataSourceProcessorImpl processor = new HbmMetadataSourceProcessorImpl( this, jaxbRoots );
|
||||||
|
@ -603,7 +602,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionFactory buildSessionFactory() {
|
public SessionFactory buildSessionFactory() {
|
||||||
return getSessionFactoryBuilder().buildSessionFactory();
|
return getSessionFactoryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.hibernate.Interceptor;
|
||||||
import org.hibernate.ObjectNotFoundException;
|
import org.hibernate.ObjectNotFoundException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.SessionFactoryObserver;
|
import org.hibernate.SessionFactoryObserver;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
|
@ -45,7 +46,6 @@ import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -57,7 +57,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
|
|
||||||
SessionFactoryBuilderImpl(MetadataImplementor metadata) {
|
SessionFactoryBuilderImpl(MetadataImplementor metadata) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
options = new SessionFactoryOptionsImpl( metadata.getServiceRegistry() );
|
options = new SessionFactoryOptionsImpl( metadata.getOptions().getServiceRegistry() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,11 +97,13 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionFactory buildSessionFactory() {
|
public SessionFactory build() {
|
||||||
return new SessionFactoryImpl( metadata, options );
|
return new SessionFactoryImpl( metadata, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SessionFactoryOptionsImpl implements SessionFactory.SessionFactoryOptions {
|
private static class SessionFactoryOptionsImpl implements SessionFactory.SessionFactoryOptions {
|
||||||
|
private final StandardServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
private Interceptor interceptor;
|
private Interceptor interceptor;
|
||||||
private CustomEntityDirtinessStrategy customEntityDirtinessStrategy;
|
private CustomEntityDirtinessStrategy customEntityDirtinessStrategy;
|
||||||
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
|
private CurrentTenantIdentifierResolver currentTenantIdentifierResolver;
|
||||||
|
@ -109,7 +111,9 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
private List<EntityNameResolver> entityNameResolvers = new ArrayList<EntityNameResolver>();
|
private List<EntityNameResolver> entityNameResolvers = new ArrayList<EntityNameResolver>();
|
||||||
private EntityNotFoundDelegate entityNotFoundDelegate;
|
private EntityNotFoundDelegate entityNotFoundDelegate;
|
||||||
|
|
||||||
public SessionFactoryOptionsImpl(ServiceRegistry serviceRegistry) {
|
public SessionFactoryOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
|
||||||
final Map configurationSettings = serviceRegistry.getService( ConfigurationService.class ).getSettings();
|
final Map configurationSettings = serviceRegistry.getService( ConfigurationService.class ).getSettings();
|
||||||
|
|
||||||
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
|
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
|
||||||
|
@ -139,6 +143,11 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StandardServiceRegistry getServiceRegistry() {
|
||||||
|
return serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Interceptor getInterceptor() {
|
public Interceptor getInterceptor() {
|
||||||
return interceptor;
|
return interceptor;
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.service;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
|
* @deprecated Use {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
|
||||||
|
@ -82,8 +83,7 @@ public class ServiceRegistryBuilder extends org.hibernate.boot.registry.Standard
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public StandardServiceRegistry build() {
|
||||||
public ServiceRegistry buildServiceRegistry() {
|
return super.build();
|
||||||
return super.buildServiceRegistry();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.service.spi;
|
package org.hibernate.service.spi;
|
||||||
|
|
||||||
import org.hibernate.service.ServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract for contributing services.
|
* Contract for contributing services.
|
||||||
|
@ -36,5 +36,5 @@ public interface ServiceContributor {
|
||||||
*
|
*
|
||||||
* @param serviceRegistryBuilder The builder to which services (or initiators) should be contributed.
|
* @param serviceRegistryBuilder The builder to which services (or initiators) should be contributed.
|
||||||
*/
|
*/
|
||||||
public void contribute(ServiceRegistryBuilder serviceRegistryBuilder);
|
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ManagedProviderConnectionHelper implements ConnectionHelper {
|
||||||
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
|
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
|
|
|
@ -553,7 +553,7 @@ public class SchemaExport {
|
||||||
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
|
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class SchemaUpdate {
|
||||||
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
|
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class SchemaValidator {
|
||||||
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
private static StandardServiceRegistryImpl createServiceRegistry(Properties properties) {
|
||||||
Environment.verifyProperties( properties );
|
Environment.verifyProperties( properties );
|
||||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||||
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).buildServiceRegistry();
|
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().applySettings( properties ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class ApplySchemaConstraintTest {
|
||||||
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||||
final BootstrapServiceRegistry bootstrapServiceRegistry = builder.build();
|
final BootstrapServiceRegistry bootstrapServiceRegistry = builder.build();
|
||||||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry );
|
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootstrapServiceRegistry );
|
||||||
return ( StandardServiceRegistryImpl ) registryBuilder.buildServiceRegistry();
|
return ( StandardServiceRegistryImpl ) registryBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry, Class<?>... classes) {
|
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry, Class<?>... classes) {
|
||||||
|
|
|
@ -28,6 +28,8 @@ import java.util.Iterator;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.EntityMode;
|
import org.hibernate.EntityMode;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.id.EntityIdentifierNature;
|
import org.hibernate.id.EntityIdentifierNature;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
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.SingularAttributeSource;
|
||||||
import org.hibernate.metamodel.spi.source.TableSource;
|
import org.hibernate.metamodel.spi.source.TableSource;
|
||||||
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
import org.hibernate.metamodel.spi.source.TableSpecificationSource;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.service.ServiceRegistryBuilder;
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -59,7 +59,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class AssertSourcesTest extends BaseUnitTestCase {
|
public class AssertSourcesTest extends BaseUnitTestCase {
|
||||||
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().buildServiceRegistry() ;
|
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build() ;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserEntitySources() {
|
public void testUserEntitySources() {
|
||||||
|
|
|
@ -51,28 +51,28 @@ public class MetadataImplTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testAddingNullClass() {
|
public void testAddingNullClass() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addClass( null );
|
sources.addClass( null );
|
||||||
sources.buildMetadata();
|
sources.buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testAddingNullPackageName() {
|
public void testAddingNullPackageName() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addPackage( null );
|
sources.addPackage( null );
|
||||||
sources.buildMetadata();
|
sources.buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HibernateException.class)
|
@Test(expected = HibernateException.class)
|
||||||
public void testAddingNonExistingPackageName() {
|
public void testAddingNonExistingPackageName() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addPackage( "not.a.package" );
|
sources.addPackage( "not.a.package" );
|
||||||
sources.buildMetadata();
|
sources.buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddingPackageName() {
|
public void testAddingPackageName() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addPackage( "org.hibernate.metamodel.internal.source" );
|
sources.addPackage( "org.hibernate.metamodel.internal.source" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class MetadataImplTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddingPackageNameWithTrailingDot() {
|
public void testAddingPackageNameWithTrailingDot() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addPackage( "org.hibernate.metamodel.internal.source." );
|
sources.addPackage( "org.hibernate.metamodel.internal.source." );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class MetadataImplTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGettingSessionFactoryBuilder() {
|
public void testGettingSessionFactoryBuilder() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
Metadata metadata = sources.buildMetadata();
|
Metadata metadata = sources.buildMetadata();
|
||||||
|
|
||||||
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class SessionFactoryBuilderImplTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testBuildSessionFactoryWithDefaultOptions() {
|
public void testBuildSessionFactoryWithDefaultOptions() {
|
||||||
SessionFactoryBuilder sessionFactoryBuilder = getSessionFactoryBuilder();
|
SessionFactoryBuilder sessionFactoryBuilder = getSessionFactoryBuilder();
|
||||||
SessionFactory sessionFactory = sessionFactoryBuilder.buildSessionFactory();
|
SessionFactory sessionFactory = sessionFactoryBuilder.build();
|
||||||
assertSame( EmptyInterceptor.INSTANCE, sessionFactory.getSessionFactoryOptions().getInterceptor() );
|
assertSame( EmptyInterceptor.INSTANCE, sessionFactory.getSessionFactoryOptions().getInterceptor() );
|
||||||
assertTrue( EntityNotFoundDelegate.class.isInstance(
|
assertTrue( EntityNotFoundDelegate.class.isInstance(
|
||||||
sessionFactory.getSessionFactoryOptions().getEntityNotFoundDelegate()
|
sessionFactory.getSessionFactoryOptions().getEntityNotFoundDelegate()
|
||||||
|
@ -84,14 +84,14 @@ public class SessionFactoryBuilderImplTest extends BaseUnitTestCase {
|
||||||
};
|
};
|
||||||
sessionFactoryBuilder.with( interceptor );
|
sessionFactoryBuilder.with( interceptor );
|
||||||
sessionFactoryBuilder.with( entityNotFoundDelegate );
|
sessionFactoryBuilder.with( entityNotFoundDelegate );
|
||||||
SessionFactory sessionFactory = sessionFactoryBuilder.buildSessionFactory();
|
SessionFactory sessionFactory = sessionFactoryBuilder.build();
|
||||||
assertSame( interceptor, sessionFactory.getSessionFactoryOptions().getInterceptor() );
|
assertSame( interceptor, sessionFactory.getSessionFactoryOptions().getInterceptor() );
|
||||||
assertSame( entityNotFoundDelegate, sessionFactory.getSessionFactoryOptions().getEntityNotFoundDelegate() );
|
assertSame( entityNotFoundDelegate, sessionFactory.getSessionFactoryOptions().getEntityNotFoundDelegate() );
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SessionFactoryBuilder getSessionFactoryBuilder() {
|
private SessionFactoryBuilder getSessionFactoryBuilder() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addAnnotatedClass( SimpleEntity.class );
|
sources.addAnnotatedClass( SimpleEntity.class );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
return metadata.getSessionFactoryBuilder();
|
return metadata.getSessionFactoryBuilder();
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class IdentifierGeneratorTest extends BaseAnnotationBindingTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testUndefinedGenerator() {
|
public void testUndefinedGenerator() {
|
||||||
try {
|
try {
|
||||||
sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addAnnotatedClass( NamedGeneratorEntity.class );
|
sources.addAnnotatedClass( NamedGeneratorEntity.class );
|
||||||
sources.buildMetadata();
|
sources.buildMetadata();
|
||||||
fail();
|
fail();
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class MapsIdTest extends BaseAnnotationBindingTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testMapsIsOnOneToManyThrowsException() {
|
public void testMapsIsOnOneToManyThrowsException() {
|
||||||
try {
|
try {
|
||||||
sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
sources.addAnnotatedClass( DependentId.class );
|
sources.addAnnotatedClass( DependentId.class );
|
||||||
sources.addAnnotatedClass( Dependent.class );
|
sources.addAnnotatedClass( Dependent.class );
|
||||||
sources.addAnnotatedClass( Employee.class );
|
sources.addAnnotatedClass( Employee.class );
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class FetchProfileBinderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
service = serviceRegistry.getService( ClassLoaderService.class );
|
service = serviceRegistry.getService( ClassLoaderService.class );
|
||||||
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
|
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class QueryBinderTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
service = serviceRegistry.getService( ClassLoaderService.class );
|
service = serviceRegistry.getService( ClassLoaderService.class );
|
||||||
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
|
meta = (MetadataImpl) new MetadataSources( serviceRegistry ).buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public abstract class BaseAnnotationIndexTestCase extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
MetadataSources sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
meta = (MetadataImpl) sources.buildMetadata();
|
meta = (MetadataImpl) sources.buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class JandexHelperTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ import static junit.framework.Assert.assertNotNull;
|
||||||
public class OrmXmlParserTests extends BaseUnitTestCase {
|
public class OrmXmlParserTests extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleOrmVersion2() {
|
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" );
|
sources.addResource( "org/hibernate/metamodel/internal/source/annotations/xml/orm-father.xml" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class OrmXmlParserTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleOrmVersion1() {
|
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" );
|
sources.addResource( "org/hibernate/metamodel/internal/source/annotations/xml/orm-star.xml" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class OrmXmlParserTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test(expected = MappingException.class)
|
@Test(expected = MappingException.class)
|
||||||
public void testInvalidOrmXmlThrowsException() {
|
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.addResource( "org/hibernate/metamodel/internal/source/annotations/xml/orm-invalid.xml" );
|
||||||
sources.buildMetadata();
|
sources.buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractUnsavedValueTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class JoinedSubclassBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -71,7 +71,7 @@ public class UnidirectionalManyToManyBindingTests extends BaseUnitTestCase {
|
||||||
MetadataSources sources = new MetadataSources( serviceRegistry );
|
MetadataSources sources = new MetadataSources( serviceRegistry );
|
||||||
sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml" );
|
sources.addResource( "org/hibernate/metamodel/spi/binding/EntityWithUnidirectionalManyToManys.hbm.xml" );
|
||||||
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntity.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 entityBinding = metadata.getEntityBinding( EntityWithUnidirectionalManyToMany.class.getName() );
|
||||||
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
|
final EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
|
||||||
|
|
|
@ -70,10 +70,10 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().build();
|
||||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||||
addSources( metadataSources );
|
addSources( metadataSources );
|
||||||
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().buildMetadata();
|
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -71,10 +71,10 @@ public abstract class AbstractUnidirectionalOneToManyBindingTests extends BaseUn
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = ( StandardServiceRegistryImpl ) new StandardServiceRegistryBuilder().build();
|
||||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||||
addSources( metadataSources );
|
addSources( metadataSources );
|
||||||
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().buildMetadata();
|
metadata = ( MetadataImpl ) metadataSources.getMetadataBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -53,7 +53,7 @@ public abstract class AbstractGeneratedIdColumnTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
||||||
public void testWithoutIntegrator() {
|
public void testWithoutIntegrator() {
|
||||||
|
|
||||||
ServiceRegistry reg = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryImpl())
|
ServiceRegistry reg = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryImpl())
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
|
|
||||||
SessionFactory sf = new Configuration()
|
SessionFactory sf = new Configuration()
|
||||||
.addAnnotatedClass( Investor.class )
|
.addAnnotatedClass( Investor.class )
|
||||||
|
@ -82,7 +82,7 @@ public class EmbeddableIntegratorTest extends BaseUnitTestCase {
|
||||||
public void testWithIntegrator() {
|
public void testWithIntegrator() {
|
||||||
ServiceRegistry reg = new StandardServiceRegistryBuilder(
|
ServiceRegistry reg = new StandardServiceRegistryBuilder(
|
||||||
new BootstrapServiceRegistryBuilder().with( new InvestorIntegrator() ).build()
|
new BootstrapServiceRegistryBuilder().with( new InvestorIntegrator() ).build()
|
||||||
).buildServiceRegistry();
|
).build();
|
||||||
|
|
||||||
SessionFactory sf = new Configuration()
|
SessionFactory sf = new Configuration()
|
||||||
.addAnnotatedClass( Investor.class )
|
.addAnnotatedClass( Investor.class )
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
|
||||||
cfg.addAnnotatedClass( Gate.class );
|
cfg.addAnnotatedClass( Gate.class );
|
||||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
//no exception as the GoofyPersisterClassProvider is not set
|
//no exception as the GoofyPersisterClassProvider is not set
|
||||||
SessionFactory sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
SessionFactory sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
|
@ -54,7 +54,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
|
||||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
|
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
cfg = new Configuration();
|
cfg = new Configuration();
|
||||||
cfg.addAnnotatedClass( Gate.class );
|
cfg.addAnnotatedClass( Gate.class );
|
||||||
try {
|
try {
|
||||||
|
@ -79,7 +79,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
|
||||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
|
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
try {
|
try {
|
||||||
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
|
@ -102,7 +102,7 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
|
||||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
|
.addService( PersisterClassResolver.class, new GoofyPersisterClassProvider() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
try {
|
try {
|
||||||
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
|
||||||
sessionFactory.close();
|
sessionFactory.close();
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class BatchingTest extends BaseUnitTestCase implements BatchKey {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class ConfigurationValidationTest extends BaseUnitTestCase {
|
||||||
cfg.setProperty( Environment.MULTI_TENANT_CONNECTION_PROVIDER, "class.not.present.in.classpath" );
|
cfg.setProperty( Environment.MULTI_TENANT_CONNECTION_PROVIDER, "class.not.present.in.classpath" );
|
||||||
cfg.buildMappings();
|
cfg.buildMappings();
|
||||||
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( cfg.getProperties() ).buildServiceRegistry();
|
.applySettings( cfg.getProperties() ).build();
|
||||||
cfg.buildSessionFactory( serviceRegistry );
|
cfg.buildSessionFactory( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class ConfigurationValidationTest extends BaseUnitTestCase {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
|
|
||||||
cfg.buildSessionFactory( serviceRegistry );
|
cfg.buildSessionFactory( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class SchemaBasedMultiTenancyTest extends BaseUnitTestCase {
|
||||||
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( cfg.getProperties() )
|
.applySettings( cfg.getProperties() )
|
||||||
.addService( MultiTenantConnectionProvider.class, multiTenantConnectionProvider )
|
.addService( MultiTenantConnectionProvider.class, multiTenantConnectionProvider )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
|
|
||||||
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.RequiresDialect;
|
|
||||||
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
import org.hibernate.testing.env.ConnectionProviderBuilder;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -51,7 +50,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
|
||||||
public void testBasicBuild() {
|
public void testBasicBuild() {
|
||||||
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||||
|
|
||||||
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
||||||
|
@ -68,7 +67,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( props )
|
.applySettings( props )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
|
|
||||||
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
|
||||||
public void testBuildWithServiceOverride() {
|
public void testBuildWithServiceOverride() {
|
||||||
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
StandardServiceRegistryImpl serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||||
|
|
||||||
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
||||||
|
@ -95,7 +94,7 @@ public class ServiceBootstrappingTest extends BaseUnitTestCase {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( props )
|
.applySettings( props )
|
||||||
.addService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() )
|
.addService( ConnectionProvider.class, new UserSuppliedConnectionProviderImpl() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||||
|
|
||||||
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
assertTrue( jdbcServices.getDialect() instanceof H2Dialect );
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class ExistingDatabaseMetaDataImplTest extends BaseUnitTestCase {
|
||||||
@Before
|
@Before
|
||||||
public void prepare() throws SQLException {
|
public void prepare() throws SQLException {
|
||||||
Properties props = Environment.getProperties();
|
Properties props = Environment.getProperties();
|
||||||
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder().applySettings( props ).buildServiceRegistry();
|
serviceRegistry = (ServiceRegistryImplementor) new ServiceRegistryBuilder().applySettings( props ).build();
|
||||||
connection = DriverManager.getConnection(
|
connection = DriverManager.getConnection(
|
||||||
props.getProperty( Environment.URL ),
|
props.getProperty( Environment.URL ),
|
||||||
props.getProperty( Environment.USER ),
|
props.getProperty( Environment.USER ),
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,7 +60,7 @@ public class TestExpectedUsage extends BaseUnitTestCase {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
.applySettings( ConnectionProviderBuilder.getConnectionProviderProperties() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class BasicDrivingTest extends BaseUnitTestCase {
|
||||||
TestingJtaBootstrap.prepare( configValues );
|
TestingJtaBootstrap.prepare( configValues );
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( configValues )
|
.applySettings( configValues )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class ManagedDrivingTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( configValues )
|
.applySettings( configValues )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -81,7 +81,6 @@ import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
||||||
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
|
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.jaxb.spi.cfg.JaxbHibernateConfiguration;
|
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
import org.hibernate.jpa.AvailableSettings;
|
||||||
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
|
||||||
import org.hibernate.jpa.boot.spi.IntegratorProvider;
|
import org.hibernate.jpa.boot.spi.IntegratorProvider;
|
||||||
|
@ -850,7 +849,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceRegistry buildServiceRegistry() {
|
public ServiceRegistry buildServiceRegistry() {
|
||||||
return serviceRegistryBuilder.buildServiceRegistry();
|
return serviceRegistryBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Configuration buildHibernateConfiguration(ServiceRegistry serviceRegistry) {
|
public Configuration buildHibernateConfiguration(ServiceRegistry serviceRegistry) {
|
||||||
|
|
|
@ -166,12 +166,12 @@ public class EntityManagerFactoryBuilderUsingMetamodelImpl implements EntityMana
|
||||||
|
|
||||||
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
|
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
|
||||||
prepareMetadataBuilder( metadataBuilder, specialProperties );
|
prepareMetadataBuilder( metadataBuilder, specialProperties );
|
||||||
final Metadata metadata = metadataBuilder.buildMetadata();
|
final Metadata metadata = metadataBuilder.build();
|
||||||
|
|
||||||
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
|
||||||
prepareSessionFactoryBuilder( sessionFactoryBuilder, specialProperties );
|
prepareSessionFactoryBuilder( sessionFactoryBuilder, specialProperties );
|
||||||
sessionFactoryBuilder.add( new ServiceRegistryCloser() );
|
sessionFactoryBuilder.add( new ServiceRegistryCloser() );
|
||||||
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.buildSessionFactory();
|
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.build();
|
||||||
|
|
||||||
final Settings emfCreationSettings = prepareEntitytManagerFactoryCreationSettings( specialProperties );
|
final Settings emfCreationSettings = prepareEntitytManagerFactoryCreationSettings( specialProperties );
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
||||||
private void evictOrRemoveTest() throws Exception {
|
private void evictOrRemoveTest() throws Exception {
|
||||||
Configuration cfg = createConfiguration();
|
Configuration cfg = createConfiguration();
|
||||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
@ -94,7 +94,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
||||||
|
|
||||||
cfg = createConfiguration();
|
cfg = createConfiguration();
|
||||||
regionFactory = CacheTestUtil.startRegionFactory(
|
regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
@ -148,7 +148,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
||||||
private void evictOrRemoveAllTest(String configName) throws Exception {
|
private void evictOrRemoveAllTest(String configName) throws Exception {
|
||||||
Configuration cfg = createConfiguration();
|
Configuration cfg = createConfiguration();
|
||||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
@ -166,7 +166,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
||||||
|
|
||||||
cfg = createConfiguration();
|
cfg = createConfiguration();
|
||||||
regionFactory = CacheTestUtil.startRegionFactory(
|
regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class NodeEnvironment {
|
||||||
public void prepare() throws Exception {
|
public void prepare() throws Exception {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( configuration.getProperties() )
|
.applySettings( configuration.getProperties() )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
|
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
|
||||||
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
|
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
||||||
private void putDoesNotBlockGetTest() throws Exception {
|
private void putDoesNotBlockGetTest() throws Exception {
|
||||||
Configuration cfg = createConfiguration();
|
Configuration cfg = createConfiguration();
|
||||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
@ -213,7 +213,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
||||||
private void getDoesNotBlockPutTest() throws Exception {
|
private void getDoesNotBlockPutTest() throws Exception {
|
||||||
Configuration cfg = createConfiguration();
|
Configuration cfg = createConfiguration();
|
||||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
|
||||||
public void testClearTimestampsRegionInIsolated() throws Exception {
|
public void testClearTimestampsRegionInIsolated() throws Exception {
|
||||||
Configuration cfg = createConfiguration();
|
Configuration cfg = createConfiguration();
|
||||||
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg,
|
cfg,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
@ -91,7 +91,7 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC
|
||||||
|
|
||||||
Configuration cfg2 = createConfiguration();
|
Configuration cfg2 = createConfiguration();
|
||||||
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
|
InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory(
|
||||||
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).buildServiceRegistry(),
|
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
|
||||||
cfg2,
|
cfg2,
|
||||||
getCacheTestSupport()
|
getCacheTestSupport()
|
||||||
);
|
);
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ServiceRegistryBuilder {
|
||||||
public static StandardServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
|
public static StandardServiceRegistryImpl buildServiceRegistry(Map serviceRegistryConfig) {
|
||||||
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
return (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
|
||||||
.applySettings( serviceRegistryConfig )
|
.applySettings( serviceRegistryConfig )
|
||||||
.buildServiceRegistry();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void destroy(ServiceRegistry serviceRegistry) {
|
public static void destroy(ServiceRegistry serviceRegistry) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* 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
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Inc.
|
* distributed under license by Red Hat Inc.
|
||||||
|
@ -34,6 +34,7 @@ import org.junit.runner.Description;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.metamodel.MetadataBuilder;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.internal.MetadataImpl;
|
import org.hibernate.metamodel.internal.MetadataImpl;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
|
@ -106,10 +107,11 @@ public abstract class BaseAnnotationBindingTestCase extends BaseUnitTestCase {
|
||||||
|
|
||||||
private void createBindings() {
|
private void createBindings() {
|
||||||
try {
|
try {
|
||||||
sources = new MetadataSources( new StandardServiceRegistryBuilder().buildServiceRegistry() );
|
sources = new MetadataSources( new StandardServiceRegistryBuilder().build() );
|
||||||
|
MetadataBuilder metadataBuilder = sources.getMetadataBuilder();
|
||||||
Resources resourcesAnnotation = description.getAnnotation( Resources.class );
|
Resources resourcesAnnotation = description.getAnnotation( Resources.class );
|
||||||
if ( resourcesAnnotation != null ) {
|
if ( resourcesAnnotation != null ) {
|
||||||
sources.getMetadataBuilder().with( resourcesAnnotation.cacheMode() );
|
metadataBuilder.with( resourcesAnnotation.cacheMode() );
|
||||||
|
|
||||||
for ( Class<?> annotatedClass : resourcesAnnotation.annotatedClasses() ) {
|
for ( Class<?> annotatedClass : resourcesAnnotation.annotatedClasses() ) {
|
||||||
annotatedClasses.add( annotatedClass );
|
annotatedClasses.add( annotatedClass );
|
||||||
|
@ -119,7 +121,7 @@ public abstract class BaseAnnotationBindingTestCase extends BaseUnitTestCase {
|
||||||
sources.addResource( resourcesAnnotation.ormXmlPath() );
|
sources.addResource( resourcesAnnotation.ormXmlPath() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
meta = ( MetadataImpl ) sources.buildMetadata();
|
meta = ( MetadataImpl ) metadataBuilder.build();
|
||||||
}
|
}
|
||||||
catch ( final Throwable t ) {
|
catch ( final Throwable t ) {
|
||||||
setupError = t;
|
setupError = t;
|
||||||
|
|
|
@ -34,13 +34,13 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.Session;
|
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.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
@ -48,6 +48,7 @@ import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.Mappings;
|
import org.hibernate.cfg.Mappings;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
@ -59,23 +60,22 @@ import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
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.MetadataImplementor;
|
||||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
import org.hibernate.metamodel.spi.binding.Caching;
|
import org.hibernate.metamodel.spi.binding.Caching;
|
||||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.type.Type;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
|
||||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
import org.hibernate.testing.AfterClassOnce;
|
import org.hibernate.testing.AfterClassOnce;
|
||||||
import org.hibernate.testing.BeforeClassOnce;
|
import org.hibernate.testing.BeforeClassOnce;
|
||||||
import org.hibernate.testing.OnExpectedFailure;
|
import org.hibernate.testing.OnExpectedFailure;
|
||||||
import org.hibernate.testing.OnFailure;
|
import org.hibernate.testing.OnFailure;
|
||||||
import org.hibernate.testing.SkipLog;
|
import org.hibernate.testing.SkipLog;
|
||||||
import org.hibernate.testing.cache.CachingRegionFactory;
|
import org.hibernate.testing.cache.CachingRegionFactory;
|
||||||
import org.hibernate.type.Type;
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -132,7 +132,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
protected void buildSessionFactory() {
|
protected void buildSessionFactory() {
|
||||||
// for now, build the configuration to get all the property settings
|
// for now, build the configuration to get all the property settings
|
||||||
configuration = constructAndConfigureConfiguration();
|
configuration = constructAndConfigureConfiguration();
|
||||||
serviceRegistry = buildServiceRegistry( configuration );
|
BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry();
|
||||||
|
serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
||||||
isMetadataUsed = serviceRegistry.getService( ConfigurationService.class ).getSetting(
|
isMetadataUsed = serviceRegistry.getService( ConfigurationService.class ).getSetting(
|
||||||
USE_NEW_METADATA_MAPPINGS,
|
USE_NEW_METADATA_MAPPINGS,
|
||||||
new ConfigurationService.Converter<Boolean>() {
|
new ConfigurationService.Converter<Boolean>() {
|
||||||
|
@ -144,7 +145,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
if ( isMetadataUsed ) {
|
if ( isMetadataUsed ) {
|
||||||
MetadataImplementor metadataImplementor = buildMetadata( serviceRegistry );
|
MetadataImplementor metadataImplementor = buildMetadata( bootRegistry, serviceRegistry );
|
||||||
afterConstructAndConfigureMetadata( metadataImplementor );
|
afterConstructAndConfigureMetadata( metadataImplementor );
|
||||||
applyCacheSettings(metadataImplementor);
|
applyCacheSettings(metadataImplementor);
|
||||||
sessionFactory = ( SessionFactoryImplementor ) metadataImplementor.buildSessionFactory();
|
sessionFactory = ( SessionFactoryImplementor ) metadataImplementor.buildSessionFactory();
|
||||||
|
@ -169,10 +170,12 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry) {
|
private MetadataImplementor buildMetadata(
|
||||||
MetadataSources sources = new MetadataSources( serviceRegistry );
|
BootstrapServiceRegistry bootRegistry,
|
||||||
addMappings( sources );
|
StandardServiceRegistryImpl serviceRegistry) {
|
||||||
return (MetadataImplementor) sources.buildMetadata();
|
MetadataSources sources = new MetadataSources( bootRegistry );
|
||||||
|
addMappings( sources );
|
||||||
|
return (MetadataImplementor) sources.getMetadataBuilder( serviceRegistry ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: is this still needed?
|
// TODO: is this still needed?
|
||||||
|
@ -392,20 +395,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
protected void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
|
protected void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected StandardServiceRegistryImpl buildServiceRegistry(Configuration configuration) {
|
protected BootstrapServiceRegistry buildBootstrapServiceRegistry() {
|
||||||
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) {
|
|
||||||
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||||
prepareBootstrapRegistryBuilder( builder );
|
prepareBootstrapRegistryBuilder( builder );
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
@ -414,6 +404,17 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
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) {
|
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder serviceRegistryBuilder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue