Search in sources :

Example 1 with SessionFactoryBuilderFactory

use of org.hibernate.boot.spi.SessionFactoryBuilderFactory in project hibernate-orm by hibernate.

the class MetadataImpl method getSessionFactoryBuilder.

@Override
public SessionFactoryBuilder getSessionFactoryBuilder() {
    final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl(this);
    final ClassLoaderService cls = metadataBuildingOptions.getServiceRegistry().getService(ClassLoaderService.class);
    final java.util.Collection<SessionFactoryBuilderFactory> discoveredBuilderFactories = cls.loadJavaServices(SessionFactoryBuilderFactory.class);
    SessionFactoryBuilder builder = null;
    List<String> activeFactoryNames = null;
    for (SessionFactoryBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories) {
        final SessionFactoryBuilder returnedBuilder = discoveredBuilderFactory.getSessionFactoryBuilder(this, defaultBuilder);
        if (returnedBuilder != null) {
            if (activeFactoryNames == null) {
                activeFactoryNames = new ArrayList<>();
            }
            activeFactoryNames.add(discoveredBuilderFactory.getClass().getName());
            builder = returnedBuilder;
        }
    }
    if (activeFactoryNames != null && activeFactoryNames.size() > 1) {
        throw new HibernateException("Multiple active SessionFactoryBuilderFactory definitions were discovered : " + StringHelper.join(", ", activeFactoryNames));
    }
    if (builder != null) {
        return builder;
    }
    return defaultBuilder;
}
Also used : SessionFactoryBuilderFactory(org.hibernate.boot.spi.SessionFactoryBuilderFactory) HibernateException(org.hibernate.HibernateException) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

HibernateException (org.hibernate.HibernateException)1 SessionFactoryBuilder (org.hibernate.boot.SessionFactoryBuilder)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 SessionFactoryBuilderFactory (org.hibernate.boot.spi.SessionFactoryBuilderFactory)1