org.hibernate.boot.spi.SessionFactoryOptions Java Examples

The following examples show how to use org.hibernate.boot.spi.SessionFactoryOptions. 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: MemcachedRegionFactory.java    From hibernate-l2-memcached with Apache License 2.0 6 votes vote down vote up
private CacheManager useExplicitCacheManager(SessionFactoryOptions settings, Object setting) {
    if (setting instanceof CacheManager) {
        return (CacheManager) setting;
    }

    final Class<? extends CacheManager> cacheManagerClass;
    if (setting instanceof Class) {
        cacheManagerClass = (Class<? extends CacheManager>) setting;
    } else {
        cacheManagerClass = settings.getServiceRegistry().getService(ClassLoaderService.class).classForName(setting.toString());
    }

    try {
        return cacheManagerClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new CacheException("Could not use explicit CacheManager : " + setting);
    }
}
 
Example #2
Source File: JtaTransactionCoordinatorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Construct a JtaTransactionCoordinatorImpl instance.  package-protected to ensure access goes through
 * builder.
 *
 * @param owner The transactionCoordinatorOwner
 * @param autoJoinTransactions Should JTA transactions be auto-joined?  Or should we wait for explicit join calls?
 */
JtaTransactionCoordinatorImpl(
		TransactionCoordinatorBuilder transactionCoordinatorBuilder,
		TransactionCoordinatorOwner owner,
		boolean autoJoinTransactions) {
	this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
	this.transactionCoordinatorOwner = owner;
	this.autoJoinTransactions = autoJoinTransactions;

	this.observers = new ArrayList<>();

	final JdbcSessionContext jdbcSessionContext = owner.getJdbcSessionOwner().getJdbcSessionContext();

	this.jtaPlatform = jdbcSessionContext.getServiceRegistry().getService( JtaPlatform.class );

	final SessionFactoryOptions sessionFactoryOptions = jdbcSessionContext.getSessionFactory().getSessionFactoryOptions();
	this.preferUserTransactions = sessionFactoryOptions.isPreferUserTransaction();
	this.performJtaThreadTracking = sessionFactoryOptions.isJtaTrackByThread();

	synchronizationRegistered = false;

	pulse();
}
 
Example #3
Source File: TypeSafeActivator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static ValidatorFactory resolveProvidedFactory(SessionFactoryOptions options) {
	final Object validatorFactoryReference = options.getValidatorFactoryReference();

	if ( validatorFactoryReference == null ) {
		return null;
	}

	try {
		return ValidatorFactory.class.cast( validatorFactoryReference );
	}
	catch ( ClassCastException e ) {
		throw new IntegrationException(
				String.format(
						Locale.ENGLISH,
						"ValidatorFactory reference (provided via %s) was not castable to %s : %s",
						SessionFactoryOptions.class.getName(),
						ValidatorFactory.class.getName(),
						validatorFactoryReference.getClass().getName()
				)
		);
	}
}
 
Example #4
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 #5
Source File: PersistentTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) {
	final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry();
	final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	final String catalogName = configService.getSetting(
			CATALOG,
			StandardConverters.STRING,
			configService.getSetting( AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING )
	);
	final String schemaName = configService.getSetting(
			SCHEMA,
			StandardConverters.STRING,
			configService.getSetting( AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING )
	);

	this.catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier( catalogName );
	this.schema = jdbcEnvironment.getIdentifierHelper().toIdentifier( schemaName );

	this.dropIdTables = configService.getSetting(
			DROP_ID_TABLES,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example #6
Source File: AbstractRegionFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final void start(SessionFactoryOptions settings, Map configValues) throws CacheException {
	if ( started.compareAndSet( false, true ) ) {
		synchronized (this) {
			this.options = settings;
			try {
				prepareForUse( settings, configValues );
				startingException = null;
			}
			catch ( Exception e ) {
				options = null;
				started.set( false );
				startingException = e;
			}
		}
	}
	else {
		SecondLevelCacheLogger.INSTANCE.attemptToStartAlreadyStartedCacheProvider();
	}
}
 
Example #7
Source File: J2CacheRegionFactory.java    From J2Cache with Apache License 2.0 5 votes vote down vote up
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    this.settings = settings;
    if (this.channel == null) {
        this.channel = J2Cache.getChannel();
    }
}
 
Example #8
Source File: SessionFactoryServiceRegistryBuilderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	return new SessionFactoryServiceRegistryImpl(
			parent,
			initiators,
			providedServices,
			sessionFactory,
			bootstrapContext,
			options
	);
}
 
Example #9
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 #10
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 #11
Source File: RedissonCacheRegionFactory.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/**
 * 准备阶段
 */
@Override
protected void prepareForUse(SessionFactoryOptions settings, Map properties) throws CacheException {
    this.context = ApplicationContextHolder.getApplicationContext();
    this.defaultConfig = context.getBean(Config.class);
    super.prepareForUse(settings, properties);
}
 
Example #12
Source File: SessionFactoryServiceRegistryFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SessionFactoryServiceRegistry buildServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
	final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );

	for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {
		contributor.contribute( builder );
	}

	return builder.buildSessionFactoryServiceRegistry( sessionFactory, bootstrapContext, options );
}
 
Example #13
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 #14
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static Interceptor configuredInterceptor(Interceptor interceptor, SessionFactoryOptions options) {
	// NOTE : DO NOT return EmptyInterceptor.INSTANCE from here as a "default for the Session"
	// 		we "filter" that one out here.  The return from here should represent the
	//		explicitly configured Interceptor (if one).  Return null from here instead; Session
	//		will handle it

	if ( interceptor != null && interceptor != EmptyInterceptor.INSTANCE ) {
		return interceptor;
	}

	// prefer the SF-scoped interceptor, prefer that to any Session-scoped interceptor prototype
	if ( options.getInterceptor() != null && options.getInterceptor() != EmptyInterceptor.INSTANCE ) {
		return options.getInterceptor();
	}

	// then check the Session-scoped interceptor prototype
	if ( options.getStatelessInterceptorImplementor() != null && options.getStatelessInterceptorImplementorSupplier() != null ) {
		throw new HibernateException(
				"A session scoped interceptor class or supplier are allowed, but not both!" );
	}
	else if ( options.getStatelessInterceptorImplementor() != null ) {
		try {
			/**
			 * We could remove the getStatelessInterceptorImplementor method and use just the getStatelessInterceptorImplementorSupplier
			 * since it can cover both cases when the user has given a Supplier<? extends Interceptor> or just the
			 * Class<? extends Interceptor>, in which case, we simply instantiate the Interceptor when calling the Supplier.
			 */
			return options.getStatelessInterceptorImplementor().newInstance();
		}
		catch (InstantiationException | IllegalAccessException e) {
			throw new HibernateException( "Could not supply session-scoped SessionFactory Interceptor", e );
		}
	}
	else if ( options.getStatelessInterceptorImplementorSupplier() != null ) {
		return options.getStatelessInterceptorImplementorSupplier().get();
	}

	return null;
}
 
Example #15
Source File: RegionNameQualifier.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public String qualify(String regionName, SessionFactoryOptions options) {
	final String prefix = options.getCacheRegionPrefix();
	if ( prefix == null ) {
		return regionName;
	}

	return qualify( prefix, regionName );
}
 
Example #16
Source File: CacheUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isUnqualified(String regionName, SessionFactoryOptions options) {
	final String prefix = options.getCacheRegionPrefix();
	if ( prefix == null ) {
		return true;
	}
	else {
		return !regionName.startsWith( prefix );
	}
}
 
Example #17
Source File: EventListenerRegistryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link EventListenerRegistryImpl#EventListenerRegistryImpl(BootstrapContext, SessionFactoryImplementor)} instead
 */
@Deprecated
EventListenerRegistryImpl(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	this.sessionFactory = sessionFactory;

	this.callbackRegistry = new CallbackRegistryImpl();

	this.registeredEventListeners = buildListenerGroups();
}
 
Example #18
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 #19
Source File: SessionFactoryOptionsBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SessionFactoryOptions buildOptions() {
	if ( MutableJpaCompliance.class.isInstance( this.jpaCompliance ) ) {
		this.jpaCompliance = mutableJpaCompliance().immutableCopy();
	}

	return this;
}
 
Example #20
Source File: CteValuesListBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #21
Source File: GlobalTemporaryTableBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void initialize(MetadataBuildingOptions buildingOptions, SessionFactoryOptions sessionFactoryOptions) {
	final StandardServiceRegistry serviceRegistry = buildingOptions.getServiceRegistry();
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
	this.dropIdTables = configService.getSetting(
			DROP_ID_TABLES,
			StandardConverters.BOOLEAN,
			false
	);
}
 
Example #22
Source File: InlineIdsInClauseBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #23
Source File: InlineIdsSubSelectValueListBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #24
Source File: InlineIdsOrClauseBulkIdStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #25
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 #26
Source File: HibernateRegionFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void start(SessionFactoryOptions settings, Properties props) throws CacheException {
    String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name());

    dfltAccessType = AccessType.valueOf(accessType);

    accessStgyFactory.start(props);
}
 
Example #27
Source File: HibernateRegionFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void start(SessionFactoryOptions options, Map cfgValues) throws CacheException {
    this.options = options;

    String accessType = cfgValues.getOrDefault(
        DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name()).toString();

    dfltAccessType = AccessType.valueOf(accessType);

    accessStgyFactory.start(cfgValues);
}
 
Example #28
Source File: CacheManager.java    From hibernate-l2-memcached with Apache License 2.0 5 votes vote down vote up
public CacheManager(SessionFactoryOptions settings, Map properties) {
    this.properties = properties;
    try {
        client = getMemcachedClientFactory(wrapInConfig(properties)).createMemcacheClient();
    } catch (Exception e) {
        throw new CacheException("Unable to initialize MemcachedClient", e);
    }
}
 
Example #29
Source File: RedissonRegionFactory.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
    this.redisson = createRedissonClient(properties);
    this.settings = new Settings(settings);
    
    StrategySelector selector = settings.getServiceRegistry().getService(StrategySelector.class);
    cacheKeysFactory = selector.resolveDefaultableStrategy(CacheKeysFactory.class, 
                            properties.get(Environment.CACHE_KEYS_FACTORY), new RedissonCacheKeysFactory(redisson.getConfig().getCodec()));
}
 
Example #30
Source File: MemcachedRegionFactory.java    From hibernate-l2-memcached with Apache License 2.0 5 votes vote down vote up
protected CacheManager resolveCacheManager(SessionFactoryOptions settings, Map properties) {
    final Object explicitCacheManager = properties.get(ConfigSettings.CACHE_MANAGER);
    if (explicitCacheManager != null) {
        return useExplicitCacheManager(settings, explicitCacheManager);
    }

    return useNormalCacheManager(settings, properties);
}