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