org.hibernate.boot.registry.selector.spi.StrategySelector#resolveStrategy ( )源码实例Demo

下面列出了org.hibernate.boot.registry.selector.spi.StrategySelector#resolveStrategy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: quarkus   文件: FastBootMetadataBuilder.java
private void registerIdentifierGenerators(StandardServiceRegistry ssr) {
    final StrategySelector strategySelector = ssr.getService(StrategySelector.class);

    // apply id generators
    final Object idGeneratorStrategyProviderSetting = buildTimeSettings
            .get(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER);
    if (idGeneratorStrategyProviderSetting != null) {
        final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider = strategySelector
                .resolveStrategy(IdentifierGeneratorStrategyProvider.class, idGeneratorStrategyProviderSetting);
        final MutableIdentifierGeneratorFactory identifierGeneratorFactory = ssr
                .getService(MutableIdentifierGeneratorFactory.class);
        if (identifierGeneratorFactory == null) {
            throw persistenceException("Application requested custom identifier generator strategies, "
                    + "but the MutableIdentifierGeneratorFactory could not be found");
        }
        for (Map.Entry<String, Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet()) {
            identifierGeneratorFactory.register(entry.getKey(), entry.getValue());
        }
    }
}
 
源代码2 项目: lams   文件: EntityManagerFactoryBuilderImpl.java
private void configure(StandardServiceRegistry ssr, MergedSettings mergedSettings) {
	final StrategySelector strategySelector = ssr.getService( StrategySelector.class );

	// apply id generators
	final Object idGeneratorStrategyProviderSetting = configurationValues.remove( AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER );
	if ( idGeneratorStrategyProviderSetting != null ) {
		final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider =
				strategySelector.resolveStrategy( IdentifierGeneratorStrategyProvider.class, idGeneratorStrategyProviderSetting );
		final MutableIdentifierGeneratorFactory identifierGeneratorFactory = ssr.getService( MutableIdentifierGeneratorFactory.class );
		if ( identifierGeneratorFactory == null ) {
			throw persistenceException(
					"Application requested custom identifier generator strategies, " +
							"but the MutableIdentifierGeneratorFactory could not be found"
			);
		}
		for ( Map.Entry<String,Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet() ) {
			identifierGeneratorFactory.register( entry.getKey(), entry.getValue() );
		}
	}
}
 
源代码3 项目: lams   文件: DefaultMergeEventListener.java
private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
	final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
	if ( entityCopyObserverStrategy == null ) {
		final ConfigurationService configurationService
				= serviceRegistry.getService( ConfigurationService.class );
		entityCopyObserverStrategy = configurationService.getSetting(
				AvailableSettings.MERGE_ENTITY_COPY_OBSERVER,
				new ConfigurationService.Converter<String>() {
					@Override
					public String convert(Object value) {
						return value.toString();
					}
				},
				EntityCopyNotAllowedObserver.SHORT_NAME
		);
		LOG.debugf( "EntityCopyObserver strategy: %s", entityCopyObserverStrategy );
	}
	final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
	return strategySelector.resolveStrategy( EntityCopyObserver.class, entityCopyObserverStrategy );
}
 
源代码4 项目: lams   文件: SessionFactoryOptionsBuilder.java
@SuppressWarnings("deprecation")
private static Interceptor determineInterceptor(Map configurationSettings, StrategySelector strategySelector) {
	Object setting = configurationSettings.get( INTERCEPTOR );
	if ( setting == null ) {
		// try the legacy (deprecated) JPA name
		setting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.INTERCEPTOR );
		if ( setting != null ) {
			DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting(
					org.hibernate.jpa.AvailableSettings.INTERCEPTOR,
					INTERCEPTOR
			);
		}
	}

	return strategySelector.resolveStrategy(
			Interceptor.class,
			setting
	);
}
 
源代码5 项目: lams   文件: BootstrapContextImpl.java
public BootstrapContextImpl(
		StandardServiceRegistry serviceRegistry,
		MetadataBuildingOptions metadataBuildingOptions) {
	this.serviceRegistry = serviceRegistry;
	this.classmateContext = new ClassmateContext();
	this.metadataBuildingOptions = metadataBuildingOptions;

	final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
	this.classLoaderAccess = new ClassLoaderAccessImpl( classLoaderService );
	this.hcannReflectionManager = generateHcannReflectionManager();

	final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
	final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );

	this.jpaCompliance = new MutableJpaComplianceImpl( configService.getSettings(), false );
	this.scanOptions = new StandardScanOptions(
			(String) configService.getSettings().get( AvailableSettings.SCANNER_DISCOVERY ),
			false
	);

	// ScanEnvironment must be set explicitly
	this.scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER );
	if ( this.scannerSetting == null ) {
		this.scannerSetting = configService.getSettings().get( AvailableSettings.SCANNER_DEPRECATED );
		if ( this.scannerSetting != null ) {
			DEPRECATION_LOGGER.logDeprecatedScannerSetting();
		}
	}
	this.archiveDescriptorFactory = strategySelector.resolveStrategy(
			ArchiveDescriptorFactory.class,
			configService.getSettings().get( AvailableSettings.SCANNER_ARCHIVE_INTERPRETER )
	);
	this.typeConfiguration = new TypeConfiguration();
}
 
protected void populate(SessionFactoryOptionsBuilder options, StandardServiceRegistry ssr, MultiTenancyStrategy strategy) {

        // will use user override value or default to false if not supplied to follow
        // JPA spec.
        final boolean jtaTransactionAccessEnabled = runtimeSettings.getBoolean(
                AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS);
        if (!jtaTransactionAccessEnabled) {
            options.disableJtaTransactionAccess();
        }

        final boolean allowRefreshDetachedEntity = runtimeSettings.getBoolean(
                org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY);
        if (!allowRefreshDetachedEntity) {
            options.disableRefreshDetachedEntity();
        }

        // Locate and apply any requested SessionFactoryObserver
        final Object sessionFactoryObserverSetting = runtimeSettings.get(AvailableSettings.SESSION_FACTORY_OBSERVER);
        if (sessionFactoryObserverSetting != null) {

            final StrategySelector strategySelector = ssr.getService(StrategySelector.class);
            final SessionFactoryObserver suppliedSessionFactoryObserver = strategySelector
                    .resolveStrategy(SessionFactoryObserver.class, sessionFactoryObserverSetting);
            options.addSessionFactoryObservers(suppliedSessionFactoryObserver);
        }

        options.addSessionFactoryObservers(new ServiceRegistryCloser());

        options.applyEntityNotFoundDelegate(new JpaEntityNotFoundDelegate());

        if (this.validatorFactory != null) {
            options.applyValidatorFactory(validatorFactory);
        }
        if (this.cdiBeanManager != null) {
            options.applyBeanManager(cdiBeanManager);
        }

        //Small memory optimisations: ensure the class transformation caches of the bytecode enhancer
        //are cleared both on start and on close of the SessionFactory.
        //(On start is useful especially in Quarkus as we won't do any more enhancement after this point)
        BytecodeProvider bytecodeProvider = ssr.getService(BytecodeProvider.class);
        options.addSessionFactoryObservers(new SessionFactoryObserverForBytecodeEnhancer(bytecodeProvider));

        if (strategy != null && strategy != MultiTenancyStrategy.NONE) {
            options.applyMultiTenancyStrategy(strategy);
            options.applyCurrentTenantIdentifierResolver(new HibernateCurrentTenantIdentifierResolver());
        }

    }
 
源代码7 项目: lams   文件: EntityManagerFactoryBuilderImpl.java
protected void populate(SessionFactoryBuilder sfBuilder, StandardServiceRegistry ssr) {

		final StrategySelector strategySelector = ssr.getService( StrategySelector.class );

//		// Locate and apply the requested SessionFactory-level interceptor (if one)
//		final Object sessionFactoryInterceptorSetting = configurationValues.remove( org.hibernate.cfg.AvailableSettings.INTERCEPTOR );
//		if ( sessionFactoryInterceptorSetting != null ) {
//			final Interceptor sessionFactoryInterceptor =
//					strategySelector.resolveStrategy( Interceptor.class, sessionFactoryInterceptorSetting );
//			sfBuilder.applyInterceptor( sessionFactoryInterceptor );
//		}

		// will use user override value or default to false if not supplied to follow JPA spec.
		final boolean jtaTransactionAccessEnabled = readBooleanConfigurationValue( AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS );
		if ( !jtaTransactionAccessEnabled ) {
			( ( SessionFactoryBuilderImplementor ) sfBuilder ).disableJtaTransactionAccess();
		}

		final boolean allowRefreshDetachedEntity = readBooleanConfigurationValue( org.hibernate.cfg.AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY );
		if ( !allowRefreshDetachedEntity ) {
			( (SessionFactoryBuilderImplementor) sfBuilder ).disableRefreshDetachedEntity();
		}

		// Locate and apply any requested SessionFactoryObserver
		final Object sessionFactoryObserverSetting = configurationValues.remove( AvailableSettings.SESSION_FACTORY_OBSERVER );
		if ( sessionFactoryObserverSetting != null ) {
			final SessionFactoryObserver suppliedSessionFactoryObserver =
					strategySelector.resolveStrategy( SessionFactoryObserver.class, sessionFactoryObserverSetting );
			sfBuilder.addSessionFactoryObservers( suppliedSessionFactoryObserver );
		}

		sfBuilder.addSessionFactoryObservers( ServiceRegistryCloser.INSTANCE );

		sfBuilder.applyEntityNotFoundDelegate( JpaEntityNotFoundDelegate.INSTANCE );

		if ( this.validatorFactory != null ) {
			sfBuilder.applyValidatorFactory( validatorFactory );
		}
		if ( this.cdiBeanManager != null ) {
			sfBuilder.applyBeanManager( cdiBeanManager );
		}
	}
 
源代码8 项目: lams   文件: RegionFactoryInitiator.java
@SuppressWarnings({"unchecked", "WeakerAccess"})
protected RegionFactory resolveRegionFactory(Map configurationValues, ServiceRegistryImplementor registry) {
	final Properties p = new Properties();
	p.putAll( configurationValues );

	final Boolean useSecondLevelCache = ConfigurationHelper.getBooleanWrapper(
			AvailableSettings.USE_SECOND_LEVEL_CACHE,
			configurationValues,
			null
	);
	final Boolean useQueryCache = ConfigurationHelper.getBooleanWrapper(
			AvailableSettings.USE_QUERY_CACHE,
			configurationValues,
			null
	);

	// We should immediately return NoCachingRegionFactory if either:
	//		1) both are explicitly FALSE
	//		2) USE_SECOND_LEVEL_CACHE is FALSE and USE_QUERY_CACHE is null
	if ( useSecondLevelCache != null && useSecondLevelCache == FALSE ) {
		if ( useQueryCache == null || useQueryCache == FALSE ) {
			return NoCachingRegionFactory.INSTANCE;
		}
	}

	final Object setting = configurationValues.get( AvailableSettings.CACHE_REGION_FACTORY );

	final StrategySelector selector = registry.getService( StrategySelector.class );
	final Collection<Class<? extends RegionFactory>> implementors = selector.getRegisteredStrategyImplementors( RegionFactory.class );

	if ( setting == null && implementors.size() != 1 ) {
		// if either are explicitly defined as TRUE we need a RegionFactory
		if ( ( useSecondLevelCache != null && useSecondLevelCache == TRUE )
				|| ( useQueryCache != null && useQueryCache == TRUE ) ) {
			throw new CacheException( "Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory" );
		}
	}

	final RegionFactory regionFactory = registry.getService( StrategySelector.class ).resolveStrategy(
			RegionFactory.class,
			setting,
			(RegionFactory) null,
			new StrategyCreatorRegionFactoryImpl( p )
	);

	if ( regionFactory != null ) {
		return regionFactory;
	}


	final RegionFactory fallback = getFallback( configurationValues, registry );
	if ( fallback != null ) {
		return fallback;
	}

	if ( implementors.size() == 1 ) {
		final RegionFactory registeredFactory = selector.resolveStrategy( RegionFactory.class, implementors.iterator().next() );
		configurationValues.put( AvailableSettings.CACHE_REGION_FACTORY, registeredFactory );
		configurationValues.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" );

		return registeredFactory;
	}
	else {
		LOG.debugf(
				"Cannot default RegionFactory based on registered strategies as `%s` RegionFactory strategies were registered",
				implementors
		);
	}

	return NoCachingRegionFactory.INSTANCE;
}