Search in sources :

Example 31 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.

the class EnversServiceImpl method initialize.

@Override
public void initialize(final MetadataImplementor metadata, final MappingCollector mappingCollector) {
    if (initialized) {
        throw new UnsupportedOperationException("EnversService#initialize should be called only once");
    }
    initialized = true;
    this.serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
    this.classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
    this.xmlHelper = new XMLHelper(classLoaderService);
    doInitialize(metadata, mappingCollector, serviceRegistry);
}
Also used : XMLHelper(org.hibernate.internal.util.xml.XMLHelper) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 32 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method loadConfiguration.

private ConfigurationBuilderHolder loadConfiguration(ServiceRegistry serviceRegistry, String configFile) {
    final FileLookup fileLookup = FileLookupFactory.newInstance();
    final ClassLoader infinispanClassLoader = InfinispanRegionFactory.class.getClassLoader();
    return serviceRegistry.getService(ClassLoaderService.class).workWithClassLoader(new ClassLoaderService.Work<ConfigurationBuilderHolder>() {

        @Override
        public ConfigurationBuilderHolder doWork(ClassLoader classLoader) {
            InputStream is = null;
            try {
                is = fileLookup.lookupFile(configFile, classLoader);
                if (is == null) {
                    // when it's not a user-provided configuration file, it might be a default configuration file,
                    // and if that's included in [this] module might not be visible to the ClassLoaderService:
                    classLoader = infinispanClassLoader;
                    // This time use lookupFile*Strict* so to provide an exception if we can't find it yet:
                    is = FileLookupFactory.newInstance().lookupFileStrict(configFile, classLoader);
                }
                final ParserRegistry parserRegistry = new ParserRegistry(infinispanClassLoader);
                final ConfigurationBuilderHolder holder = parseWithOverridenClassLoader(parserRegistry, is, infinispanClassLoader);
                return holder;
            } catch (IOException e) {
                throw log.unableToCreateCacheManager(e);
            } finally {
                Util.close(is);
            }
        }
    });
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) InputStream(java.io.InputStream) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) IOException(java.io.IOException) FileLookup(org.infinispan.commons.util.FileLookup) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 33 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.

the class MetadataImpl method getSessionFactoryBuilder.

@Override
public SessionFactoryBuilder getSessionFactoryBuilder() {
    final SessionFactoryBuilderImpl defaultBuilder = new SessionFactoryBuilderImpl(this, bootstrapContext);
    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 : " + String.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)

Example 34 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.

the class MetadataSources method getCustomBuilderOrDefault.

/**
 * In case a custom {@link MetadataBuilderFactory} creates a custom builder, return that one, otherwise the default
 * builder.
 */
private MetadataBuilder getCustomBuilderOrDefault(MetadataBuilderImpl defaultBuilder) {
    final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
    final java.util.Collection<MetadataBuilderFactory> discoveredBuilderFactories = cls.loadJavaServices(MetadataBuilderFactory.class);
    MetadataBuilder builder = null;
    List<String> activeFactoryNames = null;
    for (MetadataBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories) {
        final MetadataBuilder returnedBuilder = discoveredBuilderFactory.getMetadataBuilder(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 MetadataBuilder definitions were discovered : " + String.join(", ", activeFactoryNames));
    }
    return builder != null ? builder : defaultBuilder;
}
Also used : MetadataBuilderFactory(org.hibernate.boot.spi.MetadataBuilderFactory) HibernateException(org.hibernate.HibernateException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 35 with ClassLoaderService

use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.

the class BootstrapServiceRegistryBuilder method build.

/**
 * Build the bootstrap registry.
 *
 * @return The built bootstrap registry
 */
public BootstrapServiceRegistry build() {
    final ClassLoaderService classLoaderService;
    if (providedClassLoaderService == null) {
        // Use a set.  As an example, in JPA, OsgiClassLoader may be in both
        // the providedClassLoaders and the overridenClassLoader.
        final Set<ClassLoader> classLoaders = new HashSet<ClassLoader>();
        if (providedClassLoaders != null) {
            classLoaders.addAll(providedClassLoaders);
        }
        classLoaderService = new ClassLoaderServiceImpl(classLoaders, tcclLookupPrecedence);
    } else {
        classLoaderService = providedClassLoaderService;
    }
    final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(providedIntegrators, classLoaderService);
    return new BootstrapServiceRegistryImpl(autoCloseRegistry, classLoaderService, strategySelectorBuilder.buildSelector(classLoaderService), integratorService);
}
Also used : BootstrapServiceRegistryImpl(org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl) IntegratorServiceImpl(org.hibernate.integrator.internal.IntegratorServiceImpl) ClassLoaderServiceImpl(org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)43 HibernateException (org.hibernate.HibernateException)9 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)9 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)9 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)8 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)8 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)8 MetadataSources (org.hibernate.boot.MetadataSources)7 InFlightMetadataCollector (org.hibernate.boot.spi.InFlightMetadataCollector)7 TypeResolver (org.hibernate.type.TypeResolver)7 MappingException (org.hibernate.MappingException)6 MetadataBuildingOptionsImpl (org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl)6 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)6 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)6 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)6 HashSet (java.util.HashSet)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)4 ServiceRegistry (org.hibernate.service.ServiceRegistry)4 Set (java.util.Set)3