diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderInitiator.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderInitiator.java new file mode 100644 index 0000000000..1ef0ed7bbb --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderInitiator.java @@ -0,0 +1,32 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.boot.internal; + +import java.util.Map; + +import org.hibernate.boot.registry.StandardServiceInitiator; +import org.hibernate.boot.spi.SessionFactoryBuilderService; +import org.hibernate.service.spi.ServiceRegistryImplementor; + +public final class DefaultSessionFactoryBuilderInitiator implements StandardServiceInitiator { + + public static final DefaultSessionFactoryBuilderInitiator INSTANCE = new DefaultSessionFactoryBuilderInitiator(); + + private DefaultSessionFactoryBuilderInitiator() { + } + + @Override + public SessionFactoryBuilderService initiateService(Map configurationValues, ServiceRegistryImplementor registry) { + return DefaultSessionFactoryBuilderService.INSTANCE; + } + + @Override + public Class getServiceInitiated() { + return SessionFactoryBuilderService.class; + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java new file mode 100644 index 0000000000..a599960aa6 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java @@ -0,0 +1,29 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.boot.internal; + +import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.SessionFactoryBuilderImplementor; +import org.hibernate.boot.spi.SessionFactoryBuilderService; + +/** + * This is the default implementation of SessionFactoryBuilderService, which just + * returns the default SessionFactoryBuilderImpl. + */ +public final class DefaultSessionFactoryBuilderService implements SessionFactoryBuilderService { + + protected static final DefaultSessionFactoryBuilderService INSTANCE = new DefaultSessionFactoryBuilderService(); + + private DefaultSessionFactoryBuilderService() { + } + + @Override + public SessionFactoryBuilderImplementor createSessionFactoryBuilder(final MetadataImpl metadata, final BootstrapContext bootstrapContext) { + return new SessionFactoryBuilderImpl( metadata, bootstrapContext ); + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java index 23ba7c61c1..9b524ffb42 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java @@ -30,6 +30,8 @@ import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryBuilderFactory; +import org.hibernate.boot.spi.SessionFactoryBuilderImplementor; +import org.hibernate.boot.spi.SessionFactoryBuilderService; import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.cfg.annotations.NamedProcedureCallDefinition; import org.hibernate.dialect.function.SQLFunction; @@ -154,7 +156,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable { @Override public SessionFactoryBuilder getSessionFactoryBuilder() { - final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl( this, bootstrapContext ); + final SessionFactoryBuilderService factoryBuilderService = metadataBuildingOptions.getServiceRegistry().getService( SessionFactoryBuilderService.class ); + final SessionFactoryBuilderImplementor defaultBuilder = factoryBuilderService.createSessionFactoryBuilder( this, bootstrapContext ); final ClassLoaderService cls = metadataBuildingOptions.getServiceRegistry().getService( ClassLoaderService.class ); final java.util.Collection discoveredBuilderFactories = cls.loadJavaServices( SessionFactoryBuilderFactory.class ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryBuilderService.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryBuilderService.java new file mode 100644 index 0000000000..07b13bf29c --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryBuilderService.java @@ -0,0 +1,19 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.boot.spi; + +import org.hibernate.boot.internal.MetadataImpl; +import org.hibernate.service.Service; + +/** + * Allows bootstrapping Hibernate ORM using a custom {@link SessionFactoryBuilderImplementor} + */ +public interface SessionFactoryBuilderService extends Service { + + SessionFactoryBuilderImplementor createSessionFactoryBuilder(MetadataImpl metadata, BootstrapContext bootstrapContext); + +} diff --git a/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java b/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java index e41aba7769..4ffc3d6b69 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java +++ b/hibernate-core/src/main/java/org/hibernate/service/StandardServiceInitiators.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.List; import org.hibernate.boot.cfgxml.internal.CfgXmlAccessServiceInitiator; +import org.hibernate.boot.internal.DefaultSessionFactoryBuilderInitiator; import org.hibernate.boot.registry.StandardServiceInitiator; import org.hibernate.bytecode.internal.BytecodeProviderInitiator; import org.hibernate.bytecode.internal.ProxyFactoryFactoryInitiator; @@ -54,6 +55,8 @@ public final class StandardServiceInitiators { private static List buildStandardServiceInitiatorList() { final ArrayList serviceInitiators = new ArrayList(); + serviceInitiators.add( DefaultSessionFactoryBuilderInitiator.INSTANCE ); + serviceInitiators.add( BytecodeProviderInitiator.INSTANCE ); serviceInitiators.add( ProxyFactoryFactoryInitiator.INSTANCE );