use of org.hibernate.internal.util.beans.BeanInfoHelper in project hibernate-orm by hibernate.
the class ConnectionProviderInitiator method initiateService.
@Override
public ConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
final MultiTenancyStrategy strategy = MultiTenancyStrategy.determineMultiTenancyStrategy(configurationValues);
if (strategy == MultiTenancyStrategy.DATABASE || strategy == MultiTenancyStrategy.SCHEMA) {
// nothing to do, but given the separate hierarchies have to handle this here.
return null;
}
final StrategySelector strategySelector = registry.getService(StrategySelector.class);
final Object explicitSetting = configurationValues.get(AvailableSettings.CONNECTION_PROVIDER);
if (explicitSetting != null) {
// if we are explicitly supplied a ConnectionProvider to use (in some form) -> use it..
if (explicitSetting instanceof ConnectionProvider) {
return (ConnectionProvider) explicitSetting;
} else if (explicitSetting instanceof Class) {
final Class providerClass = (Class) explicitSetting;
LOG.instantiatingExplicitConnectionProvider(providerClass.getName());
return instantiateExplicitConnectionProvider(providerClass);
} else {
String providerName = explicitSetting.toString();
if (LEGACY_CONNECTION_PROVIDER_MAPPING.containsKey(providerName)) {
final String actualProviderName = LEGACY_CONNECTION_PROVIDER_MAPPING.get(providerName);
DeprecationLogger.DEPRECATION_LOGGER.connectionProviderClassDeprecated(providerName, actualProviderName);
providerName = actualProviderName;
}
LOG.instantiatingExplicitConnectionProvider(providerName);
final Class providerClass = strategySelector.selectStrategyImplementor(ConnectionProvider.class, providerName);
try {
return instantiateExplicitConnectionProvider(providerClass);
} catch (Exception e) {
throw new HibernateException("Could not instantiate connection provider [" + providerName + "]", e);
}
}
}
if (configurationValues.get(AvailableSettings.DATASOURCE) != null) {
return new DatasourceConnectionProviderImpl();
}
ConnectionProvider connectionProvider = null;
if (connectionProvider == null) {
if (c3p0ConfigDefined(configurationValues)) {
connectionProvider = instantiateC3p0Provider(strategySelector);
}
}
if (connectionProvider == null) {
if (proxoolConfigDefined(configurationValues)) {
connectionProvider = instantiateProxoolProvider(strategySelector);
}
}
if (connectionProvider == null) {
if (hikariConfigDefined(configurationValues)) {
connectionProvider = instantiateHikariProvider(strategySelector);
}
}
if (connectionProvider == null) {
if (configurationValues.get(AvailableSettings.URL) != null) {
connectionProvider = new DriverManagerConnectionProviderImpl();
}
}
if (connectionProvider == null) {
LOG.noAppropriateConnectionProvider();
connectionProvider = new UserSuppliedConnectionProviderImpl();
}
final Map injectionData = (Map) configurationValues.get(INJECTION_DATA);
if (injectionData != null && injectionData.size() > 0) {
final ConnectionProvider theConnectionProvider = connectionProvider;
new BeanInfoHelper(connectionProvider.getClass()).applyToBeanInfo(connectionProvider, new BeanInfoHelper.BeanInfoDelegate() {
public void processBeanInfo(BeanInfo beanInfo) throws Exception {
final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
final String propertyName = descriptor.getName();
if (injectionData.containsKey(propertyName)) {
final Method method = descriptor.getWriteMethod();
method.invoke(theConnectionProvider, injectionData.get(propertyName));
}
}
}
});
}
return connectionProvider;
}
Aggregations