Search in sources :

Example 1 with ServiceException

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);
    }
}
Also used : ServiceException(org.hibernate.service.spi.ServiceException) BatchBuilder(org.hibernate.engine.jdbc.batch.spi.BatchBuilder) ServiceException(org.hibernate.service.spi.ServiceException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 2 with ServiceException

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);
    }
}
Also used : ServiceException(org.hibernate.service.spi.ServiceException) PersisterFactory(org.hibernate.persister.spi.PersisterFactory) ServiceException(org.hibernate.service.spi.ServiceException)

Example 3 with ServiceException

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);
    }
}
Also used : ServiceException(org.hibernate.service.spi.ServiceException) Driver(java.sql.Driver) UnknownUnwrapTypeException(org.hibernate.service.UnknownUnwrapTypeException) SQLException(java.sql.SQLException) HibernateException(org.hibernate.HibernateException) ServiceException(org.hibernate.service.spi.ServiceException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 4 with ServiceException

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() + "]");
        }
    }
}
Also used : MultiTenancyStrategy(org.hibernate.MultiTenancyStrategy) ServiceException(org.hibernate.service.spi.ServiceException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) DataSourceBasedMultiTenantConnectionProviderImpl(org.hibernate.engine.jdbc.connections.spi.DataSourceBasedMultiTenantConnectionProviderImpl) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ServiceException(org.hibernate.service.spi.ServiceException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 5 with ServiceException

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);
    }
}
Also used : ServiceException(org.hibernate.service.spi.ServiceException) ServiceException(org.hibernate.service.spi.ServiceException) PersisterClassResolver(org.hibernate.persister.spi.PersisterClassResolver)

Aggregations

ServiceException (org.hibernate.service.spi.ServiceException)5 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)3 Driver (java.sql.Driver)1 SQLException (java.sql.SQLException)1 HibernateException (org.hibernate.HibernateException)1 MultiTenancyStrategy (org.hibernate.MultiTenancyStrategy)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 BatchBuilder (org.hibernate.engine.jdbc.batch.spi.BatchBuilder)1 DataSourceBasedMultiTenantConnectionProviderImpl (org.hibernate.engine.jdbc.connections.spi.DataSourceBasedMultiTenantConnectionProviderImpl)1 MultiTenantConnectionProvider (org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider)1 PersisterClassResolver (org.hibernate.persister.spi.PersisterClassResolver)1 PersisterFactory (org.hibernate.persister.spi.PersisterFactory)1 UnknownUnwrapTypeException (org.hibernate.service.UnknownUnwrapTypeException)1