Search in sources :

Example 16 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 17 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)

Example 18 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);
    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)

Example 19 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<String>();
            }
            activeFactoryNames.add(discoveredBuilderFactory.getClass().getName());
            builder = returnedBuilder;
        }
    }
    if (activeFactoryNames != null && activeFactoryNames.size() > 1) {
        throw new HibernateException("Multiple active MetadataBuilder definitions were discovered : " + StringHelper.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 20 with ClassLoaderService

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

the class TypeSafeActivator method applyCallbackListeners.

@SuppressWarnings({ "UnusedDeclaration" })
public static void applyCallbackListeners(ValidatorFactory validatorFactory, ActivationContext activationContext) {
    final Set<ValidationMode> modes = activationContext.getValidationModes();
    if (!(modes.contains(ValidationMode.CALLBACK) || modes.contains(ValidationMode.AUTO))) {
        return;
    }
    final ConfigurationService cfgService = activationContext.getServiceRegistry().getService(ConfigurationService.class);
    final ClassLoaderService classLoaderService = activationContext.getServiceRegistry().getService(ClassLoaderService.class);
    // asks for it
    if (cfgService.getSettings().get(Environment.CHECK_NULLABILITY) == null) {
        activationContext.getSessionFactory().getSessionFactoryOptions().setCheckNullability(false);
    }
    final BeanValidationEventListener listener = new BeanValidationEventListener(validatorFactory, cfgService.getSettings(), classLoaderService);
    final EventListenerRegistry listenerRegistry = activationContext.getServiceRegistry().getService(EventListenerRegistry.class);
    listenerRegistry.addDuplicationStrategy(DuplicationStrategyImpl.INSTANCE);
    listenerRegistry.appendListeners(EventType.PRE_INSERT, listener);
    listenerRegistry.appendListeners(EventType.PRE_UPDATE, listener);
    listenerRegistry.appendListeners(EventType.PRE_DELETE, listener);
    listener.initialize(cfgService.getSettings(), classLoaderService);
}
Also used : ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Aggregations

ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)29 HibernateException (org.hibernate.HibernateException)8 MappingException (org.hibernate.MappingException)6 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)6 HashSet (java.util.HashSet)3 ServiceRegistry (org.hibernate.service.ServiceRegistry)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Set (java.util.Set)2 AttributeConverter (javax.persistence.AttributeConverter)2 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)2 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)2 ServiceException (org.hibernate.service.spi.ServiceException)2 BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)2 File (java.io.File)1 InputStream (java.io.InputStream)1 InvalidObjectException (java.io.InvalidObjectException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1