org.hibernate.service.spi.ServiceRegistryImplementor Java Examples

The following examples show how to use org.hibernate.service.spi.ServiceRegistryImplementor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized 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"
			);
		}
	}
}
 
Example #2
Source File: BatchBuilderInitiator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 );
	}
}
 
Example #3
Source File: JtaPlatformInitiator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
@SuppressWarnings( {"unchecked"})
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
	JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );

	if ( platform == null ) {
		LOG.debugf( "No JtaPlatform was specified, checking resolver" );
		platform = registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
	}

	if ( platform == null ) {
		LOG.debugf( "No JtaPlatform was specified, checking resolver" );
		platform = getFallbackProvider( configurationValues, registry );
	}

	return platform;
}
 
Example #4
Source File: QueryTranslatorFactoryInitiator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: SessionFactoryServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings( {"unchecked"})
public SessionFactoryServiceRegistryImpl(
		ServiceRegistryImplementor parent,
		List<SessionFactoryServiceInitiator> initiators,
		List<ProvidedService> providedServices,
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions sessionFactoryOptions) {
	super( parent );

	this.sessionFactory = sessionFactory;
	this.sessionFactoryOptions = sessionFactoryOptions;
	this.bootstrapContext = bootstrapContext;

	// for now, just use the standard initiator list
	for ( SessionFactoryServiceInitiator initiator : initiators ) {
		// create the bindings up front to help identify to which registry services belong
		createServiceBinding( initiator );
	}

	for ( ProvidedService providedService : providedServices ) {
		createServiceBinding( providedService );
	}

	bootstrapContext = null;
}
 
Example #6
Source File: DefaultIdentifierGeneratorFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
	this.serviceRegistry = serviceRegistry;
	this.dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect();
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	final boolean useNewIdentifierGenerators = configService.getSetting(
			AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
			StandardConverters.BOOLEAN,
			true
	);

	if(!useNewIdentifierGenerators) {
		register( "sequence", SequenceGenerator.class );
	}
}
 
Example #7
Source File: PersisterClassResolverInitiator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 );
	}
}
 
Example #8
Source File: JtaPlatformResolverInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #9
Source File: StatisticsInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public StatisticsImplementor initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	final Object configValue = registry
			.getService( ConfigurationService.class )
			.getSettings()
			.get( STATS_BUILDER );
	return initiateServiceInternal( sessionFactory, configValue, registry );
}
 
Example #10
Source File: SchemaDropperImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SchemaDropperImpl(ServiceRegistry serviceRegistry, SchemaFilter schemaFilter) {
	SchemaManagementTool smt = serviceRegistry.getService( SchemaManagementTool.class );
	if ( smt == null || !HibernateSchemaManagementTool.class.isInstance( smt ) ) {
		smt = new HibernateSchemaManagementTool();
		( (HibernateSchemaManagementTool) smt ).injectServices( (ServiceRegistryImplementor) serviceRegistry );
	}

	this.tool = (HibernateSchemaManagementTool) smt;
	this.schemaFilter = schemaFilter;
}
 
Example #11
Source File: SchemaManagementToolInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SchemaManagementTool initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final Object setting = configurationValues.get( AvailableSettings.SCHEMA_MANAGEMENT_TOOL );
	SchemaManagementTool tool = registry.getService( StrategySelector.class ).resolveStrategy( SchemaManagementTool.class, setting );
	if ( tool == null ) {
		tool = new HibernateSchemaManagementTool();
	}

	return tool;
}
 
Example #12
Source File: ReactiveIdentifierGeneratorFactory.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static IdentifierGenerator augmentWithReactiveGenerator(IdentifierGenerator generator, Type type, Properties params, ServiceRegistryImplementor serviceRegistry) {
	ReactiveIdentifierGenerator<?> reactiveGenerator;
	if (generator instanceof SequenceStyleGenerator) {
		DatabaseStructure structure = ((SequenceStyleGenerator) generator).getDatabaseStructure();
		if (structure instanceof TableStructure) {
			reactiveGenerator = new TableReactiveIdentifierGenerator(true);
		}
		else if (structure instanceof SequenceStructure) {
			reactiveGenerator = new SequenceReactiveIdentifierGenerator();
		}
		else {
			throw new IllegalStateException("unknown structure type");
		}
	}
	else if (generator instanceof TableGenerator) {
		reactiveGenerator = new TableReactiveIdentifierGenerator(false);
	}
	else if (generator instanceof SequenceGenerator) {
		reactiveGenerator = new SequenceReactiveIdentifierGenerator();
	}
	else if (generator instanceof SelectGenerator) {
		//TODO: this is easy to fix!
		throw new HibernateException("SelectGenerator is not yet supported in Hibernate Reactive");
	}
	else {
		//nothing to do
		return generator;
	}

	((Configurable) reactiveGenerator).configure( type, params, serviceRegistry );

	return new ReactiveGeneratorWrapper<>( reactiveGenerator, generator );
}
 
Example #13
Source File: ManagedBeanRegistryInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private BeanContainer interpretExplicitBeanContainer(
		Object explicitSetting,
		ClassLoaderService classLoaderService, ServiceRegistryImplementor serviceRegistry) {
	if ( explicitSetting == null ) {
		return null;
	}

	if ( explicitSetting instanceof BeanContainer ) {
		return (BeanContainer) explicitSetting;
	}

	// otherwise we ultimately need to resolve this to a class
	final Class containerClass;
	if ( explicitSetting instanceof Class ) {
		containerClass = (Class) explicitSetting;
	}
	else {
		final String name = explicitSetting.toString();
		// try the StrategySelector service
		final Class selected = serviceRegistry.getService( StrategySelector.class )
				.selectStrategyImplementor( BeanContainer.class, name );
		if ( selected != null ) {
			containerClass = selected;
		}
		else {
			containerClass = classLoaderService.classForName( name );
		}
	}

	try {
		return (BeanContainer) containerClass.newInstance();
	}
	catch (Exception e) {
		throw new InstantiationException( "Unable to instantiate specified BeanContainer : " + containerClass.getName(), containerClass, e );
	}
}
 
Example #14
Source File: ManagedBeanRegistryInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private BeanContainer resoveBeanContainer(Map configurationValues, ServiceRegistryImplementor serviceRegistry) {
	final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
	final ConfigurationService cfgSvc = serviceRegistry.getService( ConfigurationService.class );

	// was a specific container explicitly specified?
	final Object explicitBeanContainer = configurationValues.get( AvailableSettings.BEAN_CONTAINER );
	if ( explicitBeanContainer != null ) {
		return interpretExplicitBeanContainer( explicitBeanContainer, classLoaderService, serviceRegistry );
	}

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// simplified CDI support

	final boolean isCdiAvailable = isCdiAvailable( classLoaderService );
	final Object beanManagerRef = cfgSvc.getSettings().get( AvailableSettings.CDI_BEAN_MANAGER );
	if ( beanManagerRef != null ) {
		if ( !isCdiAvailable ) {
			BeansMessageLogger.BEANS_LOGGER.beanManagerButCdiNotAvailable( beanManagerRef );
		}

		return CdiBeanContainerBuilder.fromBeanManagerReference( beanManagerRef, serviceRegistry );
	}
	else {
		if ( isCdiAvailable ) {
			BeansMessageLogger.BEANS_LOGGER.noBeanManagerButCdiAvailable();
		}
	}

	return null;
}
 
Example #15
Source File: TransactionCoordinatorBuilderInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TransactionCoordinatorBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	return registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
			TransactionCoordinatorBuilder.class,
			determineStrategySelection( configurationValues ),
			JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE
	);
}
 
Example #16
Source File: IgniteQueryParserServiceInitiator.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public QueryParserService initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return IgniteQueryParserService.INSTANCE;
}
 
Example #17
Source File: RedirectionSchemaInitializer.java    From teiid-spring-boot with Apache License 2.0 5 votes vote down vote up
List<String> createScript(Metadata metadata, Dialect d, boolean includeDrops) {
    final JournalingGenerationTarget target = new JournalingGenerationTarget();

    final ExecutionOptions options = new ExecutionOptions() {
        @Override
        public boolean shouldManageNamespaces() {
            return false;
        }

        @Override
        public Map getConfigurationValues() {
            return Collections.emptyMap();
        }

        @Override
        public ExceptionHandler getExceptionHandler() {
            return ExceptionHandlerHaltImpl.INSTANCE;
        }
    };
    HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
    tool.injectServices((ServiceRegistryImplementor) this.registry);
    SourceDescriptor sd = new SourceDescriptor() {
        @Override
        public SourceType getSourceType() {
            return SourceType.METADATA;
        }

        @Override
        public ScriptSourceInput getScriptSourceInput() {
            return null;
        }
    };
    if (includeDrops) {
        new SchemaDropperImpl(tool).doDrop(metadata, options, d, sd, target);
    }
    new SchemaCreatorImpl(tool).doCreation(metadata, d, options, sd, target);
    return target.commands;
}
 
Example #18
Source File: QuarkusReactiveConnectionPoolInitiator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public ReactiveConnectionPool initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    //First, check that this setup won't need to deal with multi-tenancy at the connection pool level:
    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;
    }

    return new QuarkusReactiveConnectionPool(pool);
}
 
Example #19
Source File: EventListenerServiceInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public EventListenerRegistry initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return new EventListenerRegistryImpl( sessionFactory, sessionFactoryOptions, registry );
}
 
Example #20
Source File: NativeQueryInterpreterInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public NativeQueryInterpreter initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return new NativeQueryInterpreterStandardImpl( sessionFactory );
}
 
Example #21
Source File: DriverManagerConnectionCreator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public DriverManagerConnectionCreator(
		ServiceRegistryImplementor serviceRegistry,
		String url,
		Properties connectionProps,
		Boolean autocommit,
		Integer isolation) {
	super( serviceRegistry, url, connectionProps, autocommit, isolation );
}
 
Example #22
Source File: BasicConnectionCreator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #23
Source File: DriverConnectionCreator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public DriverConnectionCreator(
		Driver driver,
		ServiceRegistryImplementor serviceRegistry,
		String url,
		Properties connectionProps,
		Boolean autocommit,
		Integer isolation) {
	super( serviceRegistry, url, connectionProps, autocommit, isolation );
	this.driver = driver;
}
 
Example #24
Source File: JdbcEnvironmentInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues, ServiceRegistryImplementor registry) {
	final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy(
			configValues
	);
	if ( !multiTenancyStrategy.requiresMultiTenantConnectionProvider() ) {
		ConnectionProvider connectionProvider = registry.getService( ConnectionProvider.class );
		return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
	}
	else {
		final MultiTenantConnectionProvider multiTenantConnectionProvider = registry.getService( MultiTenantConnectionProvider.class );
		return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
	}
}
 
Example #25
Source File: JdbcEnvironmentInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static JdbcConnectionAccess buildBootstrapJdbcConnectionAccess(
		MultiTenancyStrategy multiTenancyStrategy,
		ServiceRegistryImplementor registry) {
	if ( !multiTenancyStrategy.requiresMultiTenantConnectionProvider() ) {
		ConnectionProvider connectionProvider = registry.getService( ConnectionProvider.class );
		return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
	}
	else {
		final MultiTenantConnectionProvider multiTenantConnectionProvider = registry.getService( MultiTenantConnectionProvider.class );
		return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
	}
}
 
Example #26
Source File: DialectResolverInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DialectResolver initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final DialectResolverSet resolver = new DialectResolverSet();

	applyCustomerResolvers( resolver, registry, configurationValues );
	resolver.addResolver(StandardDialectResolver.INSTANCE );

	return resolver;
}
 
Example #27
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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
		);
	}
}
 
Example #28
Source File: CacheInitiator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CacheImplementor initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	final RegionFactory regionFactory = registry.getService( RegionFactory.class );
	return ( ! NoCachingRegionFactory.class.isInstance( regionFactory ) )
			? new EnabledCaching( sessionFactory )
			: new DisabledCaching( sessionFactory );
}
 
Example #29
Source File: AbstractServiceRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 );
}
 
Example #30
Source File: NoJtaPlatformInitiator.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	return NoJtaPlatform.INSTANCE;
}