use of org.hibernate.service.spi.ServiceException in project hibernate-orm by hibernate.
the class BatchBuilderInitiator method initiateService.
@Override
public BatchBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object builder = configurationValues.get(BUILDER);
if (builder == null) {
return new BatchBuilderImpl(ConfigurationHelper.getInt(Environment.STATEMENT_BATCH_SIZE, configurationValues, 1));
}
if (BatchBuilder.class.isInstance(builder)) {
return (BatchBuilder) builder;
}
final String builderClassName = builder.toString();
try {
return (BatchBuilder) registry.getService(ClassLoaderService.class).classForName(builderClassName).newInstance();
} catch (Exception e) {
throw new ServiceException("Could not build explicit BatchBuilder [" + builderClassName + "]", e);
}
}
use of org.hibernate.service.spi.ServiceException in project hibernate-orm by hibernate.
the class PersisterFactoryInitiator method initiateService.
@Override
@SuppressWarnings({ "unchecked" })
public PersisterFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object customImpl = configurationValues.get(IMPL_NAME);
if (customImpl == null) {
return new PersisterFactoryImpl();
}
if (PersisterFactory.class.isInstance(customImpl)) {
return (PersisterFactory) customImpl;
}
final Class<? extends PersisterFactory> customImplClass = Class.class.isInstance(customImpl) ? (Class<? extends PersisterFactory>) customImpl : locate(registry, customImpl.toString());
try {
return customImplClass.newInstance();
} catch (Exception e) {
throw new ServiceException("Could not initialize custom PersisterFactory impl [" + customImplClass.getName() + "]", e);
}
}
use of org.hibernate.service.spi.ServiceException 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.service.spi.ServiceException 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.service.spi.ServiceException in project hibernate-orm by hibernate.
the class PersisterClassResolverInitiator method initiateService.
@Override
@SuppressWarnings({ "unchecked" })
public PersisterClassResolver initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final Object customImpl = configurationValues.get(IMPL_NAME);
if (customImpl == null) {
return new StandardPersisterClassResolver();
}
if (PersisterClassResolver.class.isInstance(customImpl)) {
return (PersisterClassResolver) customImpl;
}
final Class<? extends PersisterClassResolver> customImplClass = Class.class.isInstance(customImpl) ? (Class<? extends PersisterClassResolver>) customImpl : locate(registry, customImpl.toString());
try {
return customImplClass.newInstance();
} catch (Exception e) {
throw new ServiceException("Could not initialize custom PersisterClassResolver impl [" + customImplClass.getName() + "]", e);
}
}
Aggregations