Search in sources :

Example 1 with StrategySelector

use of org.hibernate.boot.registry.selector.spi.StrategySelector 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;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) HibernateException(org.hibernate.HibernateException) BeanInfo(java.beans.BeanInfo) Method(java.lang.reflect.Method) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) HibernateException(org.hibernate.HibernateException) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) MultiTenancyStrategy(org.hibernate.MultiTenancyStrategy) BeanInfoHelper(org.hibernate.internal.util.beans.BeanInfoHelper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with StrategySelector

use of org.hibernate.boot.registry.selector.spi.StrategySelector in project hibernate-orm by hibernate.

the class DefaultMergeEventListener method createEntityCopyObserver.

private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
    final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
    if (entityCopyObserverStrategy == null) {
        final ConfigurationService configurationService = serviceRegistry.getService(ConfigurationService.class);
        entityCopyObserverStrategy = configurationService.getSetting(AvailableSettings.MERGE_ENTITY_COPY_OBSERVER, new ConfigurationService.Converter<String>() {

            @Override
            public String convert(Object value) {
                return value.toString();
            }
        }, EntityCopyNotAllowedObserver.SHORT_NAME);
        LOG.debugf("EntityCopyObserver strategy: %s", entityCopyObserverStrategy);
    }
    final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
    return strategySelector.resolveStrategy(EntityCopyObserver.class, entityCopyObserverStrategy);
}
Also used : ServiceRegistry(org.hibernate.service.ServiceRegistry) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector)

Example 3 with StrategySelector

use of org.hibernate.boot.registry.selector.spi.StrategySelector in project hibernate-orm by hibernate.

the class QueryTranslatorFactoryInitiator method initiateService.

@Override
public QueryTranslatorFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    final StrategySelector strategySelector = registry.getService(StrategySelector.class);
    final QueryTranslatorFactory factory = strategySelector.resolveDefaultableStrategy(QueryTranslatorFactory.class, configurationValues.get(QUERY_TRANSLATOR), ASTQueryTranslatorFactory.INSTANCE);
    log.debugf("QueryTranslatorFactory : %s", factory);
    if (factory instanceof ASTQueryTranslatorFactory) {
        log.usingAstQueryTranslatorFactory();
    }
    return factory;
}
Also used : QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory)

Example 4 with StrategySelector

use of org.hibernate.boot.registry.selector.spi.StrategySelector in project hibernate-orm by hibernate.

the class EntityManagerFactoryBuilderImpl method populate.

protected void populate(SessionFactoryBuilder sfBuilder, StandardServiceRegistry ssr) {
    ((SessionFactoryBuilderImplementor) sfBuilder).markAsJpaBootstrap();
    final StrategySelector strategySelector = ssr.getService(StrategySelector.class);
    //		// Locate and apply the requested SessionFactory-level interceptor (if one)
    //		final Object sessionFactoryInterceptorSetting = configurationValues.remove( org.hibernate.cfg.AvailableSettings.INTERCEPTOR );
    //		if ( sessionFactoryInterceptorSetting != null ) {
    //			final Interceptor sessionFactoryInterceptor =
    //					strategySelector.resolveStrategy( Interceptor.class, sessionFactoryInterceptorSetting );
    //			sfBuilder.applyInterceptor( sessionFactoryInterceptor );
    //		}
    // will use user override value or default to false if not supplied to follow JPA spec.
    final boolean jtaTransactionAccessEnabled = readBooleanConfigurationValue(AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS);
    if (!jtaTransactionAccessEnabled) {
        ((SessionFactoryBuilderImplementor) sfBuilder).disableJtaTransactionAccess();
    }
    final boolean allowRefreshDetachedEntity = readBooleanConfigurationValue(org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY);
    if (!allowRefreshDetachedEntity) {
        ((SessionFactoryBuilderImplementor) sfBuilder).disableRefreshDetachedEntity();
    }
    // Locate and apply any requested SessionFactoryObserver
    final Object sessionFactoryObserverSetting = configurationValues.remove(AvailableSettings.SESSION_FACTORY_OBSERVER);
    if (sessionFactoryObserverSetting != null) {
        final SessionFactoryObserver suppliedSessionFactoryObserver = strategySelector.resolveStrategy(SessionFactoryObserver.class, sessionFactoryObserverSetting);
        sfBuilder.addSessionFactoryObservers(suppliedSessionFactoryObserver);
    }
    sfBuilder.addSessionFactoryObservers(ServiceRegistryCloser.INSTANCE);
    sfBuilder.applyEntityNotFoundDelegate(JpaEntityNotFoundDelegate.INSTANCE);
    if (this.validatorFactory != null) {
        sfBuilder.applyValidatorFactory(validatorFactory);
    }
    if (this.cdiBeanManager != null) {
        sfBuilder.applyBeanManager(cdiBeanManager);
    }
}
Also used : SessionFactoryBuilderImplementor(org.hibernate.boot.spi.SessionFactoryBuilderImplementor) SessionFactoryObserver(org.hibernate.SessionFactoryObserver) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector)

Example 5 with StrategySelector

use of org.hibernate.boot.registry.selector.spi.StrategySelector in project hibernate-orm by hibernate.

the class SchemaUpdate method buildMetadata.

private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, ServiceRegistry serviceRegistry) throws Exception {
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    for (String filename : parsedArgs.hbmXmlFiles) {
        metadataSources.addFile(filename);
    }
    for (String filename : parsedArgs.jarFiles) {
        metadataSources.addJar(new File(filename));
    }
    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
    if (parsedArgs.implicitNamingStrategyImplName != null) {
        metadataBuilder.applyImplicitNamingStrategy(strategySelector.resolveStrategy(ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategyImplName));
    }
    if (parsedArgs.physicalNamingStrategyImplName != null) {
        metadataBuilder.applyPhysicalNamingStrategy(strategySelector.resolveStrategy(PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategyImplName));
    }
    return (MetadataImplementor) metadataBuilder.build();
}
Also used : ImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategy) MetadataBuilder(org.hibernate.boot.MetadataBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) File(java.io.File) StrategySelector(org.hibernate.boot.registry.selector.spi.StrategySelector) PhysicalNamingStrategy(org.hibernate.boot.model.naming.PhysicalNamingStrategy)

Aggregations

StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)9 File (java.io.File)3 MetadataBuilder (org.hibernate.boot.MetadataBuilder)3 MetadataSources (org.hibernate.boot.MetadataSources)3 ImplicitNamingStrategy (org.hibernate.boot.model.naming.ImplicitNamingStrategy)3 PhysicalNamingStrategy (org.hibernate.boot.model.naming.PhysicalNamingStrategy)3 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConfigurationService (org.hibernate.engine.config.spi.ConfigurationService)2 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Method (java.lang.reflect.Method)1 ConnectionFinder (org.geolatte.geom.codec.db.oracle.ConnectionFinder)1 OracleJDBCTypeFactory (org.geolatte.geom.codec.db.oracle.OracleJDBCTypeFactory)1 HibernateException (org.hibernate.HibernateException)1 MultiTenancyStrategy (org.hibernate.MultiTenancyStrategy)1 SessionFactoryObserver (org.hibernate.SessionFactoryObserver)1 SessionFactoryBuilderImplementor (org.hibernate.boot.spi.SessionFactoryBuilderImplementor)1