HHH-7580 - Complete 2-phase SessionFactory building design
Conflicts: hibernate-core/src/main/java/org/hibernate/SessionFactory.java hibernate-core/src/main/java/org/hibernate/boot/registry/StandardServiceRegistryBuilder.java hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java hibernate-core/src/main/java/org/hibernate/metamodel/MetadataSources.java hibernate-core/src/main/java/org/hibernate/metamodel/SessionFactoryBuilder.java hibernate-core/src/main/java/org/hibernate/metamodel/internal/SessionFactoryBuilderImpl.java hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/JaxbHelper.java hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataBuilderImpl.java hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java hibernate-core/src/main/java/org/hibernate/service/spi/ServiceContributor.java hibernate-core/src/test/java/org/hibernate/cfg/beanvalidation/ApplySchemaConstraintTest.java hibernate-core/src/test/java/org/hibernate/metamodel/binding/BasicCollectionBindingTests.java hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/AssertSourcesTest.java hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/BaseAnnotationBindingTestCase.java hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/xml/OrmXmlParserTests.java hibernate-core/src/test/java/org/hibernate/metamodel/source/internal/MetadataImplTest.java hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractUnsavedValueTests.java hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/JoinedSubclassBindingTests.java hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/basiccollections/AbstractBasicCollectionBindingTests.java hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/onetomany/AbstractUnidirectionalOneToManyBindingTests.java hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/AbstractGeneratedIdColumnTests.java hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BatchingTest.java hibernate-core/src/test/java/org/hibernate/test/service/schema/internal/ExistingDatabaseMetaDataImplTest.java hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java hibernate-entitymanager/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderUsingMetamodelImpl.java hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/NodeEnvironment.java hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java
This commit is contained in:
parent
c05238bad3
commit
7976e2396a
|
@ -27,8 +27,10 @@ import java.io.Serializable;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Map;
|
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.engine.spi.FilterDefinition;
|
import org.hibernate.engine.spi.FilterDefinition;
|
||||||
import org.hibernate.metadata.ClassMetadata;
|
import org.hibernate.metadata.ClassMetadata;
|
||||||
import org.hibernate.metadata.CollectionMetadata;
|
import org.hibernate.metadata.CollectionMetadata;
|
||||||
|
@ -54,8 +56,9 @@ import org.hibernate.stat.Statistics;
|
||||||
public interface SessionFactory extends Referenceable, Serializable {
|
public interface SessionFactory extends Referenceable, Serializable {
|
||||||
|
|
||||||
public interface SessionFactoryOptions {
|
public interface SessionFactoryOptions {
|
||||||
Interceptor getInterceptor();
|
public StandardServiceRegistry getServiceRegistry();
|
||||||
EntityNotFoundDelegate getEntityNotFoundDelegate();
|
public Interceptor getInterceptor();
|
||||||
|
public EntityNotFoundDelegate getEntityNotFoundDelegate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionFactoryOptions getSessionFactoryOptions();
|
public SessionFactoryOptions getSessionFactoryOptions();
|
||||||
|
|
|
@ -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,23 +25,24 @@ 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.boot.registry.internal.StandardServiceRegistryImpl;
|
||||||
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.jaxb.cfg.JaxbHibernateConfiguration;
|
import org.hibernate.internal.jaxb.cfg.JaxbHibernateConfiguration;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
|
||||||
import org.hibernate.service.ConfigLoader;
|
import org.hibernate.service.ConfigLoader;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
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.service.spi.ServiceContributor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for standard {@link org.hibernate.service.ServiceRegistry} instances.
|
* Builder for standard {@link org.hibernate.service.ServiceRegistry} instances.
|
||||||
|
@ -65,7 +66,7 @@ public class StandardServiceRegistryBuilder {
|
||||||
* Create a default builder
|
* Create a default builder
|
||||||
*/
|
*/
|
||||||
public StandardServiceRegistryBuilder() {
|
public StandardServiceRegistryBuilder() {
|
||||||
this( new BootstrapServiceRegistryImpl() );
|
this( new BootstrapServiceRegistryBuilder().build() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,24 +198,33 @@ 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 );
|
||||||
|
|
||||||
|
applyServiceContributingIntegrators();
|
||||||
|
applyServiceContributors();
|
||||||
|
|
||||||
|
return new StandardServiceRegistryImpl( bootstrapServiceRegistry, initiators, providedServices, settingsCopy );
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
private void applyServiceContributingIntegrators() {
|
||||||
for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
|
for ( Integrator integrator : bootstrapServiceRegistry.getService( IntegratorService.class ).getIntegrators() ) {
|
||||||
if ( ServiceContributingIntegrator.class.isInstance( integrator ) ) {
|
if ( org.hibernate.integrator.spi.ServiceContributingIntegrator.class.isInstance( integrator ) ) {
|
||||||
ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this );
|
org.hibernate.integrator.spi.ServiceContributingIntegrator.class.cast( integrator ).prepareServices( this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StandardServiceRegistryImpl( bootstrapServiceRegistry, initiators, providedServices, settingsCopy );
|
private void applyServiceContributors() {
|
||||||
|
LinkedHashSet<ServiceContributor> serviceContributors =
|
||||||
|
bootstrapServiceRegistry.getService( ClassLoaderService.class ).loadJavaServices( ServiceContributor.class );
|
||||||
|
for ( ServiceContributor serviceContributor : serviceContributors ) {
|
||||||
|
serviceContributor.contribute( this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 ) {
|
// normalize adding known class-loaders...
|
||||||
resourcesClassLoader = applicationClassLoader;
|
// 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
final LinkedHashSet<ClassLoader> classLoadingClassLoaders = new LinkedHashSet<ClassLoader>();
|
// now build the aggregated class loader...
|
||||||
classLoadingClassLoaders.add( applicationClassLoader );
|
this.aggregatedClassLoader = new AggregatedClassLoader( orderedClassLoaderSet );
|
||||||
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;
|
|
||||||
|
|
||||||
this.serviceLoaderClassLoader = buildServiceLoaderClassLoader();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,22 +136,19 @@ 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
|
@Override
|
||||||
public Enumeration<URL> getResources(String name) throws IOException {
|
public Enumeration<URL> getResources(String name) throws IOException {
|
||||||
final HashSet<URL> resourceUrls = new HashSet<URL>();
|
final HashSet<URL> resourceUrls = new HashSet<URL>();
|
||||||
|
|
||||||
for ( ClassLoader classLoader : classLoaderArray ) {
|
for ( ClassLoader classLoader : individualClassLoaders ) {
|
||||||
final Enumeration<URL> urls = classLoader.getResources( name );
|
final Enumeration<URL> urls = classLoader.getResources( name );
|
||||||
while ( urls.hasMoreElements() ) {
|
while ( urls.hasMoreElements() ) {
|
||||||
resourceUrls.add( urls.nextElement() );
|
resourceUrls.add( urls.nextElement() );
|
||||||
|
@ -176,7 +171,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URL findResource(String name) {
|
protected URL findResource(String name) {
|
||||||
for ( ClassLoader classLoader : classLoaderArray ) {
|
for ( ClassLoader classLoader : individualClassLoaders ) {
|
||||||
final URL resource = classLoader.getResource( name );
|
final URL resource = classLoader.getResource( name );
|
||||||
if ( resource != null ) {
|
if ( resource != null ) {
|
||||||
return resource;
|
return resource;
|
||||||
|
@ -187,7 +182,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
for ( ClassLoader classLoader : classLoaderArray ) {
|
for ( ClassLoader classLoader : individualClassLoaders ) {
|
||||||
try {
|
try {
|
||||||
return classLoader.loadClass( name );
|
return classLoader.loadClass( name );
|
||||||
}
|
}
|
||||||
|
@ -197,14 +192,13 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
|
||||||
|
|
||||||
throw new ClassNotFoundException( "Could not load requested class : " + name );
|
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"})
|
||||||
|
|
|
@ -477,30 +477,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";
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1768,7 +1768,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>
|
||||||
|
|
|
@ -3040,7 +3040,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) ) {
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.internal;
|
package org.hibernate.internal;
|
||||||
|
|
||||||
import javax.naming.Reference;
|
|
||||||
import javax.naming.StringRefAddr;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InvalidObjectException;
|
import java.io.InvalidObjectException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
|
@ -42,7 +40,8 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import javax.naming.Reference;
|
||||||
|
import javax.naming.StringRefAddr;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.Cache;
|
import org.hibernate.Cache;
|
||||||
|
@ -63,6 +62,9 @@ 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.classloading.spi.ClassLoaderService;
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
import org.hibernate.cache.internal.CacheDataDescriptionImpl;
|
import org.hibernate.cache.internal.CacheDataDescriptionImpl;
|
||||||
import org.hibernate.cache.spi.CollectionRegion;
|
import org.hibernate.cache.spi.CollectionRegion;
|
||||||
import org.hibernate.cache.spi.EntityRegion;
|
import org.hibernate.cache.spi.EntityRegion;
|
||||||
|
@ -90,10 +92,13 @@ import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.function.SQLFunction;
|
import org.hibernate.dialect.function.SQLFunction;
|
||||||
import org.hibernate.dialect.function.SQLFunctionRegistry;
|
import org.hibernate.dialect.function.SQLFunctionRegistry;
|
||||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||||
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
|
||||||
|
import org.hibernate.engine.jndi.spi.JndiService;
|
||||||
import org.hibernate.engine.profile.Association;
|
import org.hibernate.engine.profile.Association;
|
||||||
import org.hibernate.engine.profile.Fetch;
|
import org.hibernate.engine.profile.Fetch;
|
||||||
import org.hibernate.engine.profile.FetchProfile;
|
import org.hibernate.engine.profile.FetchProfile;
|
||||||
|
@ -108,6 +113,7 @@ import org.hibernate.engine.spi.SessionBuilderImplementor;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SessionOwner;
|
import org.hibernate.engine.spi.SessionOwner;
|
||||||
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
import org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl;
|
||||||
|
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||||
import org.hibernate.engine.transaction.spi.TransactionEnvironment;
|
import org.hibernate.engine.transaction.spi.TransactionEnvironment;
|
||||||
import org.hibernate.engine.transaction.spi.TransactionFactory;
|
import org.hibernate.engine.transaction.spi.TransactionFactory;
|
||||||
import org.hibernate.exception.spi.SQLExceptionConverter;
|
import org.hibernate.exception.spi.SQLExceptionConverter;
|
||||||
|
@ -131,12 +137,6 @@ import org.hibernate.persister.entity.Queryable;
|
||||||
import org.hibernate.persister.spi.PersisterFactory;
|
import org.hibernate.persister.spi.PersisterFactory;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
|
||||||
import org.hibernate.engine.jndi.spi.JndiService;
|
|
||||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||||
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
|
import org.hibernate.service.spi.SessionFactoryServiceRegistryFactory;
|
||||||
|
@ -150,6 +150,7 @@ import org.hibernate.tuple.entity.EntityTuplizer;
|
||||||
import org.hibernate.type.AssociationType;
|
import org.hibernate.type.AssociationType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
import org.hibernate.type.TypeResolver;
|
import org.hibernate.type.TypeResolver;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,7 +221,7 @@ public final class SessionFactoryImpl
|
||||||
public SessionFactoryImpl(
|
public SessionFactoryImpl(
|
||||||
final Configuration cfg,
|
final Configuration cfg,
|
||||||
Mapping mapping,
|
Mapping mapping,
|
||||||
ServiceRegistry serviceRegistry,
|
final ServiceRegistry serviceRegistry,
|
||||||
Settings settings,
|
Settings settings,
|
||||||
SessionFactoryObserver observer) throws HibernateException {
|
SessionFactoryObserver observer) throws HibernateException {
|
||||||
LOG.debug( "Building session factory" );
|
LOG.debug( "Building session factory" );
|
||||||
|
@ -228,6 +229,11 @@ public final class SessionFactoryImpl
|
||||||
sessionFactoryOptions = new SessionFactoryOptions() {
|
sessionFactoryOptions = new SessionFactoryOptions() {
|
||||||
private EntityNotFoundDelegate entityNotFoundDelegate;
|
private EntityNotFoundDelegate entityNotFoundDelegate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StandardServiceRegistry getServiceRegistry() {
|
||||||
|
return (StandardServiceRegistry) serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Interceptor getInterceptor() {
|
public Interceptor getInterceptor() {
|
||||||
return cfg.getInterceptor();
|
return cfg.getInterceptor();
|
||||||
|
@ -666,7 +672,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 );
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Map;
|
||||||
import javax.persistence.SharedCacheMode;
|
import javax.persistence.SharedCacheMode;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -48,6 +49,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 SharedCacheMode getSharedCacheMode();
|
public SharedCacheMode getSharedCacheMode();
|
||||||
|
|
|
@ -43,5 +43,5 @@ public interface MetadataBuilder {
|
||||||
|
|
||||||
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
|
public MetadataBuilder withNewIdentifierGeneratorsEnabled(boolean enabled);
|
||||||
|
|
||||||
public Metadata buildMetadata();
|
public Metadata build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,9 @@ import java.util.List;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
import org.w3c.dom.Document;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.xml.sax.EntityResolver;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
|
|
||||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||||
import org.hibernate.cfg.EJB3NamingStrategy;
|
import org.hibernate.cfg.EJB3NamingStrategy;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
@ -51,7 +50,9 @@ import org.hibernate.metamodel.source.MappingNotFoundException;
|
||||||
import org.hibernate.metamodel.source.internal.JaxbHelper;
|
import org.hibernate.metamodel.source.internal.JaxbHelper;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataBuilderImpl;
|
import org.hibernate.metamodel.source.internal.MetadataBuilderImpl;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.jboss.logging.Logger;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.EntityResolver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -59,13 +60,14 @@ 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 ServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
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<?>>();
|
||||||
private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>();
|
private LinkedHashSet<String> annotatedPackages = new LinkedHashSet<String>();
|
||||||
|
|
||||||
private final JaxbHelper jaxbHelper;
|
private final JaxbHelper jaxbHelper;
|
||||||
|
|
||||||
private final ServiceRegistry serviceRegistry;
|
|
||||||
private final EntityResolver entityResolver;
|
private final EntityResolver entityResolver;
|
||||||
private final NamingStrategy namingStrategy;
|
private final NamingStrategy namingStrategy;
|
||||||
|
|
||||||
|
@ -82,6 +84,20 @@ public class MetadataSources {
|
||||||
|
|
||||||
this.jaxbHelper = new JaxbHelper( this );
|
this.jaxbHelper = new JaxbHelper( this );
|
||||||
this.metadataBuilder = new MetadataBuilderImpl( this );
|
this.metadataBuilder = new MetadataBuilderImpl( this );
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean isExpectedServiceRegistryType(ServiceRegistry serviceRegistry) {
|
||||||
|
return BootstrapServiceRegistry.class.isInstance( serviceRegistry )
|
||||||
|
|| StandardServiceRegistry.class.isInstance( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JaxbRoot> getJaxbRootList() {
|
public List<JaxbRoot> getJaxbRootList() {
|
||||||
|
@ -104,12 +120,37 @@ public class MetadataSources {
|
||||||
return namingStrategy;
|
return namingStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a builder for metadata where non-default options can be specified.
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* {@link org.hibernate.metamodel.MetadataBuilder#build()} method in cases where the application wants
|
||||||
|
* to accept the defaults.
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,5 +35,10 @@ public interface SessionFactoryBuilder {
|
||||||
|
|
||||||
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate);
|
public SessionFactoryBuilder with(EntityNotFoundDelegate entityNotFoundDelegate);
|
||||||
|
|
||||||
public SessionFactory buildSessionFactory();
|
/**
|
||||||
|
* After all options have been set, build the SessionFactory.
|
||||||
|
*
|
||||||
|
* @return The built SessionFactory.
|
||||||
|
*/
|
||||||
|
public SessionFactory build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ package org.hibernate.metamodel.source.internal;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
@ -45,11 +46,7 @@ import javax.xml.transform.stream.StreamSource;
|
||||||
import javax.xml.validation.Schema;
|
import javax.xml.validation.Schema;
|
||||||
import javax.xml.validation.SchemaFactory;
|
import javax.xml.validation.SchemaFactory;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import org.hibernate.internal.jaxb.JaxbRoot;
|
import org.hibernate.internal.jaxb.JaxbRoot;
|
||||||
import org.hibernate.internal.jaxb.Origin;
|
import org.hibernate.internal.jaxb.Origin;
|
||||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
|
import org.hibernate.internal.jaxb.mapping.hbm.JaxbHibernateMapping;
|
||||||
|
@ -57,7 +54,10 @@ import org.hibernate.internal.jaxb.mapping.orm.JaxbEntityMappings;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.source.MappingException;
|
import org.hibernate.metamodel.source.MappingException;
|
||||||
import org.hibernate.metamodel.source.XsdException;
|
import org.hibernate.metamodel.source.XsdException;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.jboss.logging.Logger;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for unmarshalling xml configuration using StAX and JAXB.
|
* Helper class for unmarshalling xml configuration using StAX and JAXB.
|
||||||
|
|
|
@ -25,27 +25,66 @@ package org.hibernate.metamodel.source.internal;
|
||||||
|
|
||||||
import javax.persistence.SharedCacheMode;
|
import javax.persistence.SharedCacheMode;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
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.EJB3NamingStrategy;
|
import org.hibernate.cfg.EJB3NamingStrategy;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
import org.hibernate.metamodel.Metadata;
|
import org.hibernate.metamodel.Metadata;
|
||||||
import org.hibernate.metamodel.MetadataBuilder;
|
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.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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;
|
||||||
this.options = new OptionsImpl( sources.getServiceRegistry() );
|
this.options = new OptionsImpl( serviceRegistry );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,11 +118,13 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Metadata buildMetadata() {
|
public Metadata build() {
|
||||||
return new MetadataImpl( sources, options );
|
return new MetadataImpl( sources, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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;
|
||||||
private SharedCacheMode sharedCacheMode = SharedCacheMode.ENABLE_SELECTIVE;
|
private SharedCacheMode sharedCacheMode = SharedCacheMode.ENABLE_SELECTIVE;
|
||||||
|
@ -93,7 +134,9 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
private String defaultSchemaName;
|
private String defaultSchemaName;
|
||||||
private String defaultCatalogName;
|
private String defaultCatalogName;
|
||||||
|
|
||||||
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
|
||||||
|
@ -152,6 +195,10 @@ public class MetadataBuilderImpl implements MetadataBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StandardServiceRegistry getServiceRegistry() {
|
||||||
|
return serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder() {
|
public MetadataSourceProcessingOrder getMetadataSourceProcessingOrder() {
|
||||||
|
|
|
@ -29,12 +29,11 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.DuplicateMappingException;
|
import org.hibernate.DuplicateMappingException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cache.spi.RegionFactory;
|
import org.hibernate.cache.spi.RegionFactory;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
|
@ -66,8 +65,8 @@ import org.hibernate.metamodel.source.annotations.AnnotationMetadataSourceProces
|
||||||
import org.hibernate.metamodel.source.hbm.HbmMetadataSourceProcessorImpl;
|
import org.hibernate.metamodel.source.hbm.HbmMetadataSourceProcessorImpl;
|
||||||
import org.hibernate.persister.spi.PersisterClassResolver;
|
import org.hibernate.persister.spi.PersisterClassResolver;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|
||||||
import org.hibernate.type.TypeResolver;
|
import org.hibernate.type.TypeResolver;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for configuration data collected during binding the metamodel.
|
* Container for configuration data collected during binding the metamodel.
|
||||||
|
@ -117,7 +116,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 );
|
||||||
//new DefaultIdentifierGeneratorFactory( dialect );
|
//new DefaultIdentifierGeneratorFactory( dialect );
|
||||||
|
@ -335,11 +334,6 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SessionFactory buildSessionFactory() {
|
|
||||||
return sessionFactoryBuilder.buildSessionFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceRegistry getServiceRegistry() {
|
public ServiceRegistry getServiceRegistry() {
|
||||||
return serviceRegistry;
|
return serviceRegistry;
|
||||||
|
@ -461,6 +455,11 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
|
||||||
return sessionFactoryBuilder;
|
return sessionFactoryBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SessionFactory buildSessionFactory() {
|
||||||
|
return getSessionFactoryBuilder().build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamingStrategy getNamingStrategy() {
|
public NamingStrategy getNamingStrategy() {
|
||||||
return options.getNamingStrategy();
|
return options.getNamingStrategy();
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.hibernate.EmptyInterceptor;
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.ObjectNotFoundException;
|
import org.hibernate.ObjectNotFoundException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.internal.SessionFactoryImpl;
|
import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||||
import org.hibernate.metamodel.source.MetadataImplementor;
|
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||||
|
@ -45,7 +46,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
/* package-protected */
|
/* package-protected */
|
||||||
SessionFactoryBuilderImpl(MetadataImplementor metadata) {
|
SessionFactoryBuilderImpl(MetadataImplementor metadata) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
options = new SessionFactoryOptionsImpl();
|
options = new SessionFactoryOptionsImpl( metadata.getOptions().getServiceRegistry() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -61,13 +62,18 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionFactory buildSessionFactory() {
|
public SessionFactory build() {
|
||||||
return new SessionFactoryImpl(metadata, options, null );
|
return new SessionFactoryImpl(metadata, options, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SessionFactoryOptionsImpl implements SessionFactory.SessionFactoryOptions {
|
private static class SessionFactoryOptionsImpl implements SessionFactory.SessionFactoryOptions {
|
||||||
|
private final StandardServiceRegistry serviceRegistry;
|
||||||
private Interceptor interceptor = EmptyInterceptor.INSTANCE;
|
private Interceptor interceptor = EmptyInterceptor.INSTANCE;
|
||||||
|
|
||||||
|
public SessionFactoryOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: should there be a DefaultEntityNotFoundDelegate.INSTANCE?
|
// TODO: should there be a DefaultEntityNotFoundDelegate.INSTANCE?
|
||||||
private EntityNotFoundDelegate entityNotFoundDelegate = new EntityNotFoundDelegate() {
|
private EntityNotFoundDelegate entityNotFoundDelegate = new EntityNotFoundDelegate() {
|
||||||
public void handleEntityNotFound(String entityName, Serializable id) {
|
public void handleEntityNotFound(String entityName, Serializable id) {
|
||||||
|
@ -75,6 +81,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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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.service.spi;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contract for contributing services.
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*/
|
||||||
|
public interface ServiceContributor {
|
||||||
|
/**
|
||||||
|
* Contribute services to the indicated registry builder.
|
||||||
|
*
|
||||||
|
* @param serviceRegistryBuilder The builder to which services (or initiators) should be contributed.
|
||||||
|
*/
|
||||||
|
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 {
|
||||||
|
|
|
@ -504,7 +504,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) {
|
||||||
|
|
|
@ -64,7 +64,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
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class BasicCollectionBindingTests extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().buildServiceRegistry();
|
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
@ -68,7 +68,7 @@ public class BasicCollectionBindingTests extends BaseUnitTestCase {
|
||||||
MetadataSources sources = new MetadataSources( serviceRegistry );
|
MetadataSources sources = new MetadataSources( serviceRegistry );
|
||||||
// sources.addAnnotatedClass( EntityWithBasicCollections.class );
|
// sources.addAnnotatedClass( EntityWithBasicCollections.class );
|
||||||
sources.addResource( "org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml" );
|
sources.addResource( "org/hibernate/metamodel/binding/EntityWithBasicCollections.hbm.xml" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.getMetadataBuilder().with( processingOrder ).build();
|
||||||
|
|
||||||
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithBasicCollections.class.getName() );
|
final EntityBinding entityBinding = metadata.getEntityBinding( EntityWithBasicCollections.class.getName() );
|
||||||
assertNotNull( entityBinding );
|
assertNotNull( entityBinding );
|
||||||
|
|
|
@ -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.
|
||||||
|
@ -23,6 +23,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.annotations.entity;
|
package org.hibernate.metamodel.source.annotations.entity;
|
||||||
|
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.metamodel.MetadataBuilder;
|
||||||
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -30,13 +36,6 @@ import org.junit.rules.MethodRule;
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
import org.junit.runners.model.FrameworkMethod;
|
||||||
import org.junit.runners.model.Statement;
|
import org.junit.runners.model.Statement;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
|
@ -100,10 +99,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 = origFrameworkMethod.getAnnotation( Resources.class );
|
Resources resourcesAnnotation = origFrameworkMethod.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() ) {
|
||||||
sources.addAnnotatedClass( annotatedClass );
|
sources.addAnnotatedClass( annotatedClass );
|
||||||
|
@ -112,7 +112,8 @@ 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;
|
||||||
|
|
|
@ -149,7 +149,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();
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class MapsIdTest extends BaseAnnotationBindingTestCase {
|
||||||
@Resources(annotatedClasses = DependentId.class)
|
@Resources(annotatedClasses = DependentId.class)
|
||||||
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 );
|
||||||
|
|
|
@ -58,7 +58,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,17 +23,15 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.annotations.xml;
|
package org.hibernate.metamodel.source.annotations.xml;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static junit.framework.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.binding.EntityBinding;
|
import org.hibernate.metamodel.binding.EntityBinding;
|
||||||
import org.hibernate.metamodel.source.MappingException;
|
import org.hibernate.metamodel.source.MappingException;
|
||||||
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
import static junit.framework.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
|
@ -41,7 +39,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/source/annotations/xml/orm-father.xml" );
|
sources.addResource( "org/hibernate/metamodel/source/annotations/xml/orm-father.xml" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -51,7 +49,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/source/annotations/xml/orm-star.xml" );
|
sources.addResource( "org/hibernate/metamodel/source/annotations/xml/orm-star.xml" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -61,7 +59,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/source/annotations/xml/orm-invalid.xml" );
|
sources.addResource( "org/hibernate/metamodel/source/annotations/xml/orm-invalid.xml" );
|
||||||
sources.buildMetadata();
|
sources.buildMetadata();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.internal;
|
package org.hibernate.metamodel.source.internal;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertFalse;
|
||||||
|
import static junit.framework.Assert.assertNotNull;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
@ -34,13 +37,8 @@ import org.hibernate.metamodel.Metadata;
|
||||||
import org.hibernate.metamodel.MetadataSources;
|
import org.hibernate.metamodel.MetadataSources;
|
||||||
import org.hibernate.metamodel.SessionFactoryBuilder;
|
import org.hibernate.metamodel.SessionFactoryBuilder;
|
||||||
import org.hibernate.metamodel.binding.FetchProfile;
|
import org.hibernate.metamodel.binding.FetchProfile;
|
||||||
|
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static junit.framework.Assert.assertFalse;
|
|
||||||
import static junit.framework.Assert.assertNotNull;
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
|
@ -49,28 +47,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.source.internal" );
|
sources.addPackage( "org.hibernate.metamodel.source.internal" );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -79,7 +77,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.source.internal." );
|
sources.addPackage( "org.hibernate.metamodel.source.internal." );
|
||||||
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
MetadataImpl metadata = (MetadataImpl) sources.buildMetadata();
|
||||||
|
|
||||||
|
@ -88,7 +86,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();
|
||||||
|
|
|
@ -62,7 +62,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()
|
||||||
|
@ -82,14 +82,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();
|
||||||
|
|
|
@ -56,7 +56,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 )
|
||||||
|
@ -81,7 +81,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();
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
|
||||||
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey;
|
||||||
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
|
import org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl;
|
||||||
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch;
|
import org.hibernate.engine.jdbc.batch.internal.BatchingBatch;
|
||||||
|
|
|
@ -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 );
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,7 +59,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
|
||||||
|
|
|
@ -71,7 +71,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
|
||||||
|
|
|
@ -23,16 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.boot.internal;
|
package org.hibernate.jpa.boot.internal;
|
||||||
|
|
||||||
import javax.persistence.AttributeConverter;
|
|
||||||
import javax.persistence.Converter;
|
|
||||||
import javax.persistence.Embeddable;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
|
||||||
import javax.persistence.EntityNotFoundException;
|
|
||||||
import javax.persistence.MappedSuperclass;
|
|
||||||
import javax.persistence.PersistenceException;
|
|
||||||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -52,43 +42,47 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import org.jboss.jandex.AnnotationInstance;
|
import javax.persistence.AttributeConverter;
|
||||||
import org.jboss.jandex.ClassInfo;
|
import javax.persistence.Converter;
|
||||||
import org.jboss.jandex.CompositeIndex;
|
import javax.persistence.Embeddable;
|
||||||
import org.jboss.jandex.DotName;
|
import javax.persistence.Entity;
|
||||||
import org.jboss.jandex.Index;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import org.jboss.jandex.IndexView;
|
import javax.persistence.EntityNotFoundException;
|
||||||
import org.jboss.jandex.Indexer;
|
import javax.persistence.MappedSuperclass;
|
||||||
|
import javax.persistence.PersistenceException;
|
||||||
import org.jboss.logging.Logger;
|
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.hibernate.Interceptor;
|
import org.hibernate.Interceptor;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.MappingNotFoundException;
|
import org.hibernate.MappingNotFoundException;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.SessionFactoryObserver;
|
import org.hibernate.SessionFactoryObserver;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
|
||||||
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.cfg.NamingStrategy;
|
import org.hibernate.cfg.NamingStrategy;
|
||||||
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
|
import org.hibernate.cfg.beanvalidation.BeanValidationIntegrator;
|
||||||
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
|
|
||||||
import org.hibernate.jpa.AvailableSettings;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
|
import org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory;
|
||||||
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
import org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory;
|
||||||
|
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
|
||||||
import org.hibernate.integrator.spi.Integrator;
|
import org.hibernate.integrator.spi.Integrator;
|
||||||
import org.hibernate.internal.jaxb.cfg.JaxbHibernateConfiguration;
|
import org.hibernate.internal.jaxb.cfg.JaxbHibernateConfiguration;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.internal.util.ValueHolder;
|
import org.hibernate.internal.util.ValueHolder;
|
||||||
|
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;
|
||||||
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
|
||||||
|
import org.hibernate.jpa.event.spi.JpaIntegrator;
|
||||||
import org.hibernate.jpa.internal.EntityManagerFactoryImpl;
|
import org.hibernate.jpa.internal.EntityManagerFactoryImpl;
|
||||||
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
|
import org.hibernate.jpa.internal.EntityManagerMessageLogger;
|
||||||
import org.hibernate.jpa.event.spi.JpaIntegrator;
|
|
||||||
import org.hibernate.jpa.internal.util.LogHelper;
|
import org.hibernate.jpa.internal.util.LogHelper;
|
||||||
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
|
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
|
||||||
import org.hibernate.jpa.packaging.internal.NativeScanner;
|
import org.hibernate.jpa.packaging.internal.NativeScanner;
|
||||||
|
@ -99,12 +93,17 @@ import org.hibernate.metamodel.source.annotations.JPADotNames;
|
||||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||||
import org.hibernate.secure.internal.JACCConfiguration;
|
import org.hibernate.secure.internal.JACCConfiguration;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
|
||||||
import org.hibernate.service.ConfigLoader;
|
import org.hibernate.service.ConfigLoader;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
|
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
import org.jboss.jandex.AnnotationInstance;
|
||||||
|
import org.jboss.jandex.ClassInfo;
|
||||||
|
import org.jboss.jandex.CompositeIndex;
|
||||||
|
import org.jboss.jandex.DotName;
|
||||||
|
import org.jboss.jandex.Index;
|
||||||
|
import org.jboss.jandex.IndexView;
|
||||||
|
import org.jboss.jandex.Indexer;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
@ -903,7 +902,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) {
|
||||||
|
|
|
@ -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()
|
||||||
);
|
);
|
||||||
|
|
|
@ -27,12 +27,12 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||||
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
import org.hibernate.cache.infinispan.InfinispanRegionFactory;
|
||||||
import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
|
import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
|
||||||
import org.hibernate.cache.infinispan.entity.EntityRegionImpl;
|
import org.hibernate.cache.infinispan.entity.EntityRegionImpl;
|
||||||
import org.hibernate.cache.spi.CacheDataDescription;
|
import org.hibernate.cache.spi.CacheDataDescription;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
|
||||||
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
|
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,7 +110,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();
|
||||||
regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
|
regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,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()
|
||||||
);
|
);
|
||||||
|
@ -212,7 +212,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()
|
||||||
);
|
);
|
||||||
|
|
|
@ -81,7 +81,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()
|
||||||
);
|
);
|
||||||
|
@ -90,7 +90,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) {
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.testing.junit4;
|
package org.hibernate.testing.junit4;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Blob;
|
import java.sql.Blob;
|
||||||
import java.sql.Clob;
|
import java.sql.Clob;
|
||||||
|
@ -34,19 +36,20 @@ 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.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.cfg.Environment;
|
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,19 +62,14 @@ 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.metamodel.source.MetadataImplementor;
|
import org.hibernate.metamodel.source.MetadataImplementor;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
|
||||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
|
||||||
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.junit.After;
|
||||||
import static org.junit.Assert.fail;
|
import org.junit.Before;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies functional testing logic for core Hibernate testing on top of {@link BaseUnitTestCase}
|
* Applies functional testing logic for core Hibernate testing on top of {@link BaseUnitTestCase}
|
||||||
|
@ -126,7 +124,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>() {
|
||||||
|
@ -138,7 +137,9 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if ( isMetadataUsed ) {
|
if ( isMetadataUsed ) {
|
||||||
sessionFactory = ( SessionFactoryImplementor ) buildMetadata( serviceRegistry ).buildSessionFactory();
|
MetadataImplementor metadataImplementor = buildMetadata( bootRegistry, serviceRegistry );
|
||||||
|
afterConstructAndConfigureMetadata( metadataImplementor );
|
||||||
|
sessionFactory = ( SessionFactoryImplementor ) metadataImplementor.buildSessionFactory();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// this is done here because Configuration does not currently support 4.0 xsd
|
// this is done here because Configuration does not currently support 4.0 xsd
|
||||||
|
@ -148,10 +149,24 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
afterSessionFactoryBuilt();
|
afterSessionFactoryBuilt();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry) {
|
protected void rebuildSessionFactory() {
|
||||||
MetadataSources sources = new MetadataSources( serviceRegistry );
|
if ( sessionFactory == null ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void afterConstructAndConfigureMetadata(MetadataImplementor metadataImplementor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private MetadataImplementor buildMetadata(
|
||||||
|
BootstrapServiceRegistry bootRegistry,
|
||||||
|
StandardServiceRegistryImpl serviceRegistry) {
|
||||||
|
MetadataSources sources = new MetadataSources( bootRegistry );
|
||||||
addMappings( sources );
|
addMappings( sources );
|
||||||
return (MetadataImplementor) sources.buildMetadata();
|
return (MetadataImplementor) sources.getMetadataBuilder( serviceRegistry ).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: is this still needed?
|
// TODO: is this still needed?
|
||||||
|
@ -327,20 +342,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();
|
||||||
|
@ -349,6 +351,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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,24 +409,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void rebuildSessionFactory() {
|
|
||||||
if ( sessionFactory == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sessionFactory.close();
|
|
||||||
serviceRegistry.destroy();
|
|
||||||
|
|
||||||
serviceRegistry = buildServiceRegistry( configuration );
|
|
||||||
if ( isMetadataUsed ) {
|
|
||||||
// need to rebuild metadata because serviceRegistry was recreated
|
|
||||||
sessionFactory = ( SessionFactoryImplementor ) buildMetadata( serviceRegistry ).buildSessionFactory();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sessionFactory = ( SessionFactoryImplementor ) configuration.buildSessionFactory( serviceRegistry );
|
|
||||||
}
|
|
||||||
afterSessionFactoryBuilt();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// before/after each test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// before/after each test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue