@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 ); } }
@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 ); } }
@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 ); } }
@SuppressWarnings( {"unchecked"}) public SessionFactoryServiceRegistryImpl( ServiceRegistryImplementor parent, SessionFactoryImplementor sessionFactory, Configuration configuration) { super( parent ); this.sessionFactory = sessionFactory; this.configuration = configuration; this.metadata = null; // for now, just use the standard initiator list for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) { // create the bindings up front to help identify to which registry services belong createServiceBinding( initiator ); } }
@SuppressWarnings( {"unchecked"}) public SessionFactoryServiceRegistryImpl( ServiceRegistryImplementor parent, SessionFactoryImplementor sessionFactory, MetadataImplementor metadata) { super( parent ); this.sessionFactory = sessionFactory; this.configuration = null; this.metadata = metadata; // for now, just use the standard initiator list for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) { // create the bindings up front to help identify to which registry services belong createServiceBinding( initiator ); } }
@Override public void deRegisterChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { throw new IllegalStateException( "No child ServiceRegistry registrations found" ); } childRegistries.remove( child ); if ( childRegistries.isEmpty() ) { if ( autoCloseRegistry ) { log.debug( "Implicitly destroying ServiceRegistry on de-registration " + "of all child ServiceRegistries" ); destroy(); } else { log.debug( "Skipping implicitly destroying ServiceRegistry on de-registration " + "of all child ServiceRegistries" ); } } }
@Override public void deRegisterChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { throw new IllegalStateException( "No child ServiceRegistry registrations found" ); } childRegistries.remove( child ); if ( childRegistries.isEmpty() ) { if ( autoCloseRegistry ) { LOG.debug( "Implicitly destroying Boot-strap registry on de-registration " + "of all child ServiceRegistries" ); destroy(); } else { LOG.debug( "Skipping implicitly destroying Boot-strap registry on de-registration " + "of all child ServiceRegistries" ); } } }
/** * Extract the Configuration from the ServiceRegistry exposed by SessionFactoryImpl. Works in * Hibernate 4.3, but will probably break in a future version as they keep trying to make the * configuration harder to access (for some reason). Hopefully they will provide a interface to * get the full mapping data again. * * @param sessionFactory */ Configuration getConfigurationFromRegistry(SessionFactory sessionFactory) { ServiceRegistryImplementor serviceRegistry = ((SessionFactoryImplementor) _sessionFactory).getServiceRegistry(); SessionFactoryServiceRegistryImpl impl = (SessionFactoryServiceRegistryImpl) serviceRegistry; Configuration cfg = null; try { Field configurationField = SessionFactoryServiceRegistryImpl.class.getDeclaredField("configuration"); configurationField.setAccessible(true); Object configurationObject = configurationField.get(impl); cfg = (Configuration) configurationObject; } catch (Exception e) { e.printStackTrace(); } if (cfg == null) { throw new RuntimeException( "Unable to get the Configuration from the service registry. Please provide the Configuration in the constructor."); } return cfg; }
@Override public ImportSqlCommandExtractor initiateService(Map configurationValues, ServiceRegistryImplementor registry) { String extractorClassName = (String) configurationValues.get( Environment.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR ); if ( StringHelper.isEmpty( extractorClassName ) ) { return DEFAULT_EXTRACTOR; } final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class ); return instantiateExplicitCommandExtractor( extractorClassName, classLoaderService ); }
@Override public JtaPlatformResolver initiateService(Map configurationValues, ServiceRegistryImplementor registry) { final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER ); final JtaPlatformResolver resolver = registry.getService( StrategySelector.class ) .resolveStrategy( JtaPlatformResolver.class, setting ); if ( resolver == null ) { log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() ); return StandardJtaPlatformResolver.INSTANCE; } return resolver; }
@Override @SuppressWarnings( {"unchecked"}) public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) { final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM ); final JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting ); if ( platform == null ) { LOG.debugf( "No JtaPlatform was specified, checking resolver" ); return registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry ); } return platform; }
@Override @SuppressWarnings({"unchecked"}) public TransactionFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) { final Object strategy = configurationValues.get( AvailableSettings.TRANSACTION_STRATEGY ); if ( strategy == null ) { LOG.usingDefaultTransactionStrategy(); return new JdbcTransactionFactory(); } return registry.getService( StrategySelector.class ).resolveStrategy( TransactionFactory.class, strategy ); }
@Override public NativeQueryInterpreter initiateService( SessionFactoryImplementor sessionFactory, Configuration configuration, ServiceRegistryImplementor registry) { return NativeQueryInterpreterStandardImpl.INSTANCE; }
@Override public NativeQueryInterpreter initiateService( SessionFactoryImplementor sessionFactory, MetadataImplementor metadata, ServiceRegistryImplementor registry) { return NativeQueryInterpreterStandardImpl.INSTANCE; }
public DriverManagerConnectionCreator( ServiceRegistryImplementor serviceRegistry, String url, Properties connectionProps, Boolean autocommit, Integer isolation) { super( serviceRegistry, url, connectionProps, autocommit, isolation ); }
public BasicConnectionCreator( ServiceRegistryImplementor serviceRegistry, String url, Properties connectionProps, boolean autocommit, Integer isolation) { this.serviceRegistry = serviceRegistry; this.url = url; this.connectionProps = connectionProps; this.autoCommit = autocommit; this.isolation = isolation; }
public DriverConnectionCreator( Driver driver, ServiceRegistryImplementor serviceRegistry, String url, Properties connectionProps, Boolean autocommit, Integer isolation) { super( serviceRegistry, url, connectionProps, autocommit, isolation ); this.driver = driver; }
@Override public DialectResolver initiateService(Map configurationValues, ServiceRegistryImplementor registry) { final DialectResolverSet resolver = new DialectResolverSet(); applyCustomerResolvers( resolver, registry, configurationValues ); resolver.addResolver(StandardDialectResolver.INSTANCE ); return resolver; }
protected AbstractServiceRegistryImpl( ServiceRegistryImplementor parent, boolean autoCloseRegistry) { this.parent = parent; this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true ); this.autoCloseRegistry = autoCloseRegistry; this.parent.registerChild( this ); }
public AbstractServiceRegistryImpl( BootstrapServiceRegistry bootstrapServiceRegistry, boolean autoCloseRegistry) { if ( ! ServiceRegistryImplementor.class.isInstance( bootstrapServiceRegistry ) ) { throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" ); } this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry; this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true ); this.autoCloseRegistry = autoCloseRegistry; this.parent.registerChild( this ); }
@Override public void registerChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { childRegistries = new HashSet<ServiceRegistryImplementor>(); } if ( !childRegistries.add( child ) ) { log.warnf( "Child ServiceRegistry [%s] was already registered; this will end badly later...", child ); } }
@Override public StatisticsImplementor initiateService( SessionFactoryImplementor sessionFactory, Configuration configuration, ServiceRegistryImplementor registry) { final Object configValue = configuration.getProperties().get( STATS_BUILDER ); return initiateServiceInternal( sessionFactory, configValue, registry ); }
@Override public StatisticsImplementor initiateService( SessionFactoryImplementor sessionFactory, MetadataImplementor metadata, ServiceRegistryImplementor registry) { ConfigurationService configurationService = registry.getService( ConfigurationService.class ); final Object configValue = configurationService.getSetting( STATS_BUILDER, null ); return initiateServiceInternal( sessionFactory, configValue, registry ); }
@Override public EventListenerRegistry initiateService( SessionFactoryImplementor sessionFactory, Configuration configuration, ServiceRegistryImplementor registry) { return new EventListenerRegistryImpl(); }
@Override public EventListenerRegistry initiateService( SessionFactoryImplementor sessionFactory, MetadataImplementor metadata, ServiceRegistryImplementor registry) { return new EventListenerRegistryImpl(); }
@Override public void registerChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { childRegistries = new HashSet<ServiceRegistryImplementor>(); } if ( !childRegistries.add( child ) ) { LOG.warnf( "Child ServiceRegistry [%s] was already registered; this will end badly later...", child ); } }
@Override public QueryParserService initiateService( SessionFactoryImplementor sessionFactory, SessionFactoryOptions sessionFactoryOptions, ServiceRegistryImplementor registry) { return IgniteQueryParserService.INSTANCE; }
@Override public void injectServices(ServiceRegistryImplementor serviceRegistry) { Map settings = serviceRegistry.getService(ConfigurationService.class).getSettings(); DataSource dataSource = (DataSource) settings.get(Environment.DATASOURCE); datasourceConnectionProvider.setDataSource(dataSource); datasourceConnectionProvider.configure(settings); logger.debug("connection provider:{}", datasourceConnectionProvider); }
@Override @SuppressWarnings({ CompilerWarnings.RAWTYPES }) public CacheRegionFactory initiateService(Map configValues, ServiceRegistryImplementor serviceRegistry) { CacheRegionFactory service = super.initiateService(configValues, serviceRegistry); serviceRegistry.locateServiceBinding(RegionFactory.class).setService(service); return service; }
@Override @SuppressWarnings({ CompilerWarnings.RAWTYPES }) public SdcctHsqlDialectResolver initiateService(Map configValues, ServiceRegistryImplementor serviceRegistry) { serviceRegistry.locateServiceBinding(DialectResolver.class).setService(SdcctHsqlDialectResolver.INSTANCE); return SdcctHsqlDialectResolver.INSTANCE; }
/** * Register an hibernate event listener. Listener will be created and injected by Guice. * * @param type Event type. * @param listenerType Listener type. * @return This module. */ @SuppressWarnings("unchecked") public <T> Hbm onEvent(final EventType<T> type, final Class<? extends T> listenerType) { bindings.add(b -> { b.bind(listenerType).asEagerSingleton(); }); listeners.add((s, r) -> { ServiceRegistryImplementor serviceRegistry = s.getServiceRegistry(); EventListenerRegistry service = serviceRegistry.getService(EventListenerRegistry.class); T listener = r.require(listenerType); service.appendListeners(type, listener); }); return this; }
/** * hibernate {@link ServiceRegistryImplementor}로부터 해당 서비스를 로드합니다. * * @param serviceImpl 서비스 구현체의 타입 * @return {@link ServiceRegistryImplementor}에 등록된 서비스 */ protected final org.hibernate.service.Service getService(Class<? extends org.hibernate.service.Service> serviceImpl) { if (log.isDebugEnabled()) log.debug("Service 를 로드합니다. serviceImpl=[{}]", serviceImpl.getName()); SessionFactoryImplementor sessionFactory = getSessionFactoryImplementor(); ServiceRegistryImplementor serviceRegistry = sessionFactory.getServiceRegistry(); return serviceRegistry.getService(serviceImpl); }
@Override public void injectServices(ServiceRegistryImplementor serviceRegistry) { this.serviceRegistry = serviceRegistry; }
public ServiceRegistryImplementor getServiceRegistry() { return sessionFactoryImplementor.getServiceRegistry(); }
private Class<? extends PersisterFactory> locate(ServiceRegistryImplementor registry, String className) { return registry.getService( ClassLoaderService.class ).classForName( className ); }
private Class<? extends PersisterClassResolver> locate(ServiceRegistryImplementor registry, String className) { return registry.getService( ClassLoaderService.class ).classForName( className ); }
@Override public JmxService initiateService(Map configurationValues, ServiceRegistryImplementor registry) { return ConfigurationHelper.getBoolean( AvailableSettings.JMX_ENABLED, configurationValues, false ) ? new JmxServiceImpl( configurationValues ) : DisabledJmxServiceImpl.INSTANCE; }
@Override public JndiService initiateService(Map configurationValues, ServiceRegistryImplementor registry) { return new JndiServiceImpl( configurationValues ); }