use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class StatisticsInitiator method initiateServiceInternal.
private StatisticsImplementor initiateServiceInternal(SessionFactoryImplementor sessionFactory, Object configValue, ServiceRegistryImplementor registry) {
StatisticsFactory statisticsFactory;
if (configValue == null) {
statisticsFactory = DEFAULT_STATS_BUILDER;
} else if (StatisticsFactory.class.isInstance(configValue)) {
statisticsFactory = (StatisticsFactory) configValue;
} else {
// assume it names the factory class
final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
try {
statisticsFactory = (StatisticsFactory) classLoaderService.classForName(configValue.toString()).newInstance();
} catch (HibernateException e) {
throw e;
} catch (Exception e) {
throw new HibernateException("Unable to instantiate specified StatisticsFactory implementation [" + configValue.toString() + "]", e);
}
}
StatisticsImplementor statistics = statisticsFactory.buildStatistics(sessionFactory);
final boolean enabled = sessionFactory.getSettings().isStatisticsEnabled();
statistics.setStatisticsEnabled(enabled);
LOG.debugf("Statistics initialized [enabled=%s]", enabled);
return statistics;
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class DriverManagerConnectionProviderImpl method loadDriverIfPossible.
private Driver loadDriverIfPossible(String driverClassName) {
if (driverClassName == null) {
log.debug("No driver class specified");
return null;
}
if (serviceRegistry != null) {
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
final Class<Driver> driverClass = classLoaderService.classForName(driverClassName);
try {
return driverClass.newInstance();
} catch (Exception e) {
throw new ServiceException("Specified JDBC Driver " + driverClassName + " could not be loaded", e);
}
}
try {
return (Driver) Class.forName(driverClassName).newInstance();
} catch (Exception e1) {
throw new ServiceException("Specified JDBC Driver " + driverClassName + " could not be loaded", e1);
}
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class MultiTenantConnectionProviderInitiator method initiateService.
@Override
@SuppressWarnings({ "unchecked" })
public MultiTenantConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final MultiTenancyStrategy strategy = MultiTenancyStrategy.determineMultiTenancyStrategy(configurationValues);
if (strategy == MultiTenancyStrategy.NONE || strategy == MultiTenancyStrategy.DISCRIMINATOR) {
// nothing to do, but given the separate hierarchies have to handle this here.
return null;
}
final Object configValue = configurationValues.get(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER);
if (configValue == null) {
// if they also specified the data source *name*, then lets assume they want
// DataSourceBasedMultiTenantConnectionProviderImpl
final Object dataSourceConfigValue = configurationValues.get(AvailableSettings.DATASOURCE);
if (dataSourceConfigValue != null && String.class.isInstance(dataSourceConfigValue)) {
return new DataSourceBasedMultiTenantConnectionProviderImpl();
}
return null;
}
if (MultiTenantConnectionProvider.class.isInstance(configValue)) {
return (MultiTenantConnectionProvider) configValue;
} else {
final Class<MultiTenantConnectionProvider> implClass;
if (Class.class.isInstance(configValue)) {
implClass = (Class) configValue;
} else {
final String className = configValue.toString();
final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
try {
implClass = classLoaderService.classForName(className);
} catch (ClassLoadingException cle) {
log.warn("Unable to locate specified class [" + className + "]", cle);
throw new ServiceException("Unable to locate specified multi-tenant connection provider [" + className + "]");
}
}
try {
return implClass.newInstance();
} catch (Exception e) {
log.warn("Unable to instantiate specified class [" + implClass.getName() + "]", e);
throw new ServiceException("Unable to instantiate specified multi-tenant connection provider [" + implClass.getName() + "]");
}
}
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class DefaultIdentifierGeneratorFactory method getIdentifierGeneratorClass.
@Override
public Class getIdentifierGeneratorClass(String strategy) {
if ("hilo".equals(strategy)) {
throw new UnsupportedOperationException("Support for 'hilo' generator has been removed");
}
String resolvedStrategy = "native".equals(strategy) ? getDialect().getNativeIdentifierGeneratorStrategy() : strategy;
Class generatorClass = generatorStrategyToClassNameMap.get(resolvedStrategy);
try {
if (generatorClass == null) {
final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
generatorClass = cls.classForName(resolvedStrategy);
}
} catch (ClassLoadingException e) {
throw new MappingException(String.format("Could not interpret id generator strategy [%s]", strategy));
}
return generatorClass;
}
Aggregations