下面列出了怎么用org.hibernate.boot.spi.SessionFactoryOptions的API类实例代码及写法,或者点击链接到github查看源代码。
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()
)
);
}
}
/**
* 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();
}
@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;
}
@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();
}
}
@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
);
}
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);
}
}
/**
* 准备阶段
*/
@Override
protected void prepareForUse(SessionFactoryOptions settings, Map properties) throws CacheException {
this.context = ApplicationContextHolder.getApplicationContext();
this.defaultConfig = context.getBean(Config.class);
super.prepareForUse(settings, properties);
}
/**
* 准备阶段
*/
@Override
protected void prepareForUse(SessionFactoryOptions settings, Map properties) throws CacheException {
this.context = ApplicationContextHolder.getApplicationContext();
this.defaultConfig = context.getBean(Config.class);
super.prepareForUse(settings, properties);
}
@Override
protected void prepareForUse(SessionFactoryOptions settings, @SuppressWarnings("rawtypes") Map properties) throws CacheException {
this.redisson = createRedissonClient(properties);
StrategySelector selector = settings.getServiceRegistry().getService(StrategySelector.class);
cacheKeysFactory = selector.resolveDefaultableStrategy(CacheKeysFactory.class,
properties.get(Environment.CACHE_KEYS_FACTORY), new RedissonCacheKeysFactory(redisson.getConfig().getCodec()));
}
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
this.settings = settings;
if (this.channel == null) {
this.channel = J2Cache.getChannel();
}
}
@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()));
}
public TransactionalJ2CacheEntityRegionAccessStrategy(
J2CacheEntityRegion region,
CacheRegion cache,
SessionFactoryOptions settings) {
super(region, settings);
this.cache = cache;
}
@Override
public EntityManagerFactory build() {
final SessionFactoryOptionsBuilder optionsBuilder = metadata.buildSessionFactoryOptionsBuilder();
populate(optionsBuilder, standardServiceRegistry, multiTenancyStrategy);
SessionFactoryOptions options = optionsBuilder.buildOptions();
return new ReactiveSessionFactoryImpl(metadata.getOriginalMetadata(), options);
}
public Settings(SessionFactoryOptions sessionFactoryOptions, Metadata metadata) {
this(
sessionFactoryOptions,
extractName( metadata.getDatabase().getDefaultNamespace().getName().getCatalog() ),
extractName( metadata.getDatabase().getDefaultNamespace().getName().getSchema() )
);
}
@Override
public NativeQueryInterpreter initiateService(
SessionFactoryImplementor sessionFactory,
SessionFactoryOptions sessionFactoryOptions,
ServiceRegistryImplementor registry) {
return new NativeQueryInterpreterStandardImpl( sessionFactory );
}
@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 );
}
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
SessionFactoryImplementor sessionFactory,
BootstrapContext bootstrapContext,
SessionFactoryOptions options) {
return new SessionFactoryServiceRegistryImpl(
parent,
initiators,
providedServices,
sessionFactory,
bootstrapContext,
options
);
}
@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 );
}
@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 );
}
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;
}
public String qualify(String regionName, SessionFactoryOptions options) {
final String prefix = options.getCacheRegionPrefix();
if ( prefix == null ) {
return regionName;
}
return qualify( prefix, regionName );
}
public static boolean isUnqualified(String regionName, SessionFactoryOptions options) {
final String prefix = options.getCacheRegionPrefix();
if ( prefix == null ) {
return true;
}
else {
return !regionName.startsWith( prefix );
}
}
/**
* @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();
}
@Override
public EventListenerRegistry initiateService(
SessionFactoryImplementor sessionFactory,
SessionFactoryOptions sessionFactoryOptions,
ServiceRegistryImplementor registry) {
return new EventListenerRegistryImpl( sessionFactory, sessionFactoryOptions, registry );
}
public SessionFactoryOptions buildOptions() {
if ( MutableJpaCompliance.class.isInstance( this.jpaCompliance ) ) {
this.jpaCompliance = mutableJpaCompliance().immutableCopy();
}
return this;
}
@Override
public void prepare(
JdbcServices jdbcServices,
JdbcConnectionAccess jdbcConnectionAccess,
MetadataImplementor metadataImplementor,
SessionFactoryOptions sessionFactoryOptions) {
// nothing to do
}
@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
);
}
@Override
public void prepare(
JdbcServices jdbcServices,
JdbcConnectionAccess jdbcConnectionAccess,
MetadataImplementor metadataImplementor,
SessionFactoryOptions sessionFactoryOptions) {
// nothing to do
}
@Override
public void prepare(
JdbcServices jdbcServices,
JdbcConnectionAccess jdbcConnectionAccess,
MetadataImplementor metadataImplementor,
SessionFactoryOptions sessionFactoryOptions) {
// nothing to do
}
@Override
public void prepare(
JdbcServices jdbcServices,
JdbcConnectionAccess jdbcConnectionAccess,
MetadataImplementor metadataImplementor,
SessionFactoryOptions sessionFactoryOptions) {
// nothing to do
}