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);
}
}
});
}
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);
}
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;
}
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;
}
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);
}
Aggregations