Java Code Examples for org.hibernate.service.spi.ServiceRegistryImplementor

The following examples show how to use org.hibernate.service.spi.ServiceRegistryImplementor. These examples are extracted from open source projects. 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
@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 2
@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 3
@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 4
@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 Project: lams   Source File: JtaPlatformInitiator.java    License: 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 6
Source Project: lams   Source File: BatchBuilderInitiator.java    License: 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 7
@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 8
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 9
@Override
public ConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	ConnectionProvider provider = ConnectionProviderInitiator.INSTANCE.initiateService(configurationValues, registry);
	if (provider instanceof DriverManagerConnectionProviderImpl) {
		registry.getService( SchemaManagementTool.class )
				.setCustomDatabaseGenerationTarget( new ReactiveGenerationTarget(registry) );
		return NoJdbcConnectionProvider.INSTANCE;
	}
	return provider;
}
 
Example 10
Source Project: lams   Source File: StatisticsInitiator.java    License: 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 11
@Override
public CfgXmlAccessService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    return new CfgXmlAccessService() {
        @Override
        public LoadedConfig getAggregatedConfig() {
            return null;
        }
    };
}
 
Example 12
Source Project: quarkus   Source File: DisabledJMXInitiator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JmxService initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    if (ConfigurationHelper.getBoolean(AvailableSettings.JMX_ENABLED, configurationValues, false)) {
        Logger.getLogger(DisabledJMXInitiator.class)
                .warn("Enabling JMX is not allowed in Quarkus: forcefully disabled. Ignoring property:"
                        + AvailableSettings.JMX_ENABLED);
    }
    return DisabledJmxServiceImpl.INSTANCE;
}
 
Example 13
@Override
public synchronized 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 14
@Override
public void sessionFactoryClosed(SessionFactory sessionFactory) {
    SessionFactoryImplementor sfi = ((SessionFactoryImplementor) sessionFactory);
    sfi.getServiceRegistry().destroy();
    ServiceRegistry basicRegistry = sfi.getServiceRegistry().getParentServiceRegistry();
    ((ServiceRegistryImplementor) basicRegistry).destroy();
}
 
Example 15
@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 16
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 17
@Override
public QueryParserService initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return IgniteQueryParserService.INSTANCE;
}
 
Example 18
@Override
public TransactionCoordinatorBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	return registry.getService( StrategySelector.class ).resolveDefaultableStrategy(
			TransactionCoordinatorBuilder.class,
			determineStrategySelection( configurationValues ),
			JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE
	);
}
 
Example 19
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 20
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 21
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 22
Source Project: lams   Source File: SchemaDropperImpl.java    License: 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 23
@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 24
@Override
public EventListenerRegistry initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return new EventListenerRegistryImpl( sessionFactory, sessionFactoryOptions, registry );
}
 
Example 25
@Override
public NativeQueryInterpreter initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return new NativeQueryInterpreterStandardImpl( sessionFactory );
}
 
Example 26
public DriverManagerConnectionCreator(
		ServiceRegistryImplementor serviceRegistry,
		String url,
		Properties connectionProps,
		Boolean autocommit,
		Integer isolation) {
	super( serviceRegistry, url, connectionProps, autocommit, isolation );
}
 
Example 27
Source Project: lams   Source File: BasicConnectionCreator.java    License: 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 28
Source Project: lams   Source File: DriverConnectionCreator.java    License: 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 29
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 30
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 );
	}
}