Java Code Examples for org.hibernate.boot.registry.StandardServiceRegistry#getService()
The following examples show how to use
org.hibernate.boot.registry.StandardServiceRegistry#getService() .
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: BaseReactiveTest.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
private void mysqlConfiguration(StandardServiceRegistry registry) { registry.getService( ConnectionProvider.class ); //force the NoJdbcConnectionProvider to load first registry.getService( SchemaManagementTool.class ) .setCustomDatabaseGenerationTarget( new ReactiveGenerationTarget(registry) { @Override public void prepare() { super.prepare(); if ( dbType() == DBType.MYSQL ) { accept("set foreign_key_checks = 0"); } } @Override public void release() { if ( dbType() == DBType.MYSQL ) { accept("set foreign_key_checks = 1"); } super.release(); } } ); }
Example 2
Source File: FastBootMetadataBuilder.java From quarkus with Apache License 2.0 | 6 votes |
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()); } } }
Example 3
Source File: EntityManagerFactoryBuilderImpl.java From lams with GNU General Public License v2.0 | 6 votes |
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() ); } } }
Example 4
Source File: PersistentTableBulkIdStrategy.java From lams with GNU General Public License v2.0 | 6 votes |
@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 5
Source File: BaseReactiveTest.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void before() { Configuration configuration = constructConfiguration(); StandardServiceRegistry registry = new ReactiveServiceRegistryBuilder() .applySettings( configuration.getProperties() ) .build(); mysqlConfiguration( registry ); sessionFactory = configuration.buildSessionFactory( registry ); poolProvider = registry.getService( ReactiveConnectionPool.class ); }
Example 6
Source File: BaseMutinyTest.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
@Before public void before() { StandardServiceRegistry registry = new ReactiveServiceRegistryBuilder() .applySettings( constructConfiguration().getProperties() ) .build(); sessionFactory = constructConfiguration().buildSessionFactory( registry ); poolProvider = registry.getService( ReactiveConnectionPool.class ); }
Example 7
Source File: SQLiteMetadataBuilderInitializer.java From md_blockchain with Apache License 2.0 | 5 votes |
@Override public void contribute(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) { DialectResolver dialectResolver = serviceRegistry.getService(DialectResolver.class); if (!(dialectResolver instanceof DialectResolverSet)) { logger.warnf("DialectResolver '%s' is not an instance of DialectResolverSet, not registering SQLiteDialect", dialectResolver); return; } ((DialectResolverSet) dialectResolver).addResolver(resolver); }
Example 8
Source File: SchemaValidatorTask.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") private void configure(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) { final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class ); if ( implicitNamingStrategy != null ) { metadataBuilder.applyImplicitNamingStrategy( strategySelector.resolveStrategy( ImplicitNamingStrategy.class, implicitNamingStrategy ) ); } if ( physicalNamingStrategy != null ) { metadataBuilder.applyPhysicalNamingStrategy( strategySelector.resolveStrategy( PhysicalNamingStrategy.class, physicalNamingStrategy ) ); } }
Example 9
Source File: SessionFactoryOptionsBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") private PhysicalConnectionHandlingMode interpretConnectionHandlingMode( Map configurationSettings, StandardServiceRegistry serviceRegistry) { final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret( configurationSettings.get( CONNECTION_HANDLING ) ); if ( specifiedHandlingMode != null ) { return specifiedHandlingMode; } final TransactionCoordinatorBuilder transactionCoordinatorBuilder = serviceRegistry.getService( TransactionCoordinatorBuilder.class ); // see if the deprecated ConnectionAcquisitionMode/ConnectionReleaseMode were used.. final ConnectionAcquisitionMode specifiedAcquisitionMode = ConnectionAcquisitionMode.interpret( configurationSettings.get( ACQUIRE_CONNECTIONS ) ); final ConnectionReleaseMode specifiedReleaseMode = ConnectionReleaseMode.interpret( configurationSettings.get( RELEASE_CONNECTIONS ) ); if ( specifiedAcquisitionMode != null || specifiedReleaseMode != null ) { return interpretConnectionHandlingMode( specifiedAcquisitionMode, specifiedReleaseMode, configurationSettings, transactionCoordinatorBuilder ); } return transactionCoordinatorBuilder.getDefaultConnectionHandlingMode(); }
Example 10
Source File: BootstrapContextImpl.java From lams with GNU General Public License v2.0 | 5 votes |
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(); }
Example 11
Source File: MetadataBuilderImpl.java From lams with GNU General Public License v2.0 | 5 votes |
public MappingDefaultsImpl(StandardServiceRegistry serviceRegistry) { final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class ); this.implicitSchemaName = configService.getSetting( AvailableSettings.DEFAULT_SCHEMA, StandardConverters.STRING, null ); this.implicitCatalogName = configService.getSetting( AvailableSettings.DEFAULT_CATALOG, StandardConverters.STRING, null ); this.implicitlyQuoteIdentifiers = configService.getSetting( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, StandardConverters.BOOLEAN, false ); this.implicitCacheAccessType = configService.getSetting( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, new ConfigurationService.Converter<AccessType>() { @Override public AccessType convert(Object value) { return AccessType.fromExternalName( value.toString() ); } } ); }
Example 12
Source File: GlobalTemporaryTableBulkIdStrategy.java From lams with GNU General Public License v2.0 | 5 votes |
@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 13
Source File: FastBootEntityManagerFactoryBuilder.java From quarkus with Apache License 2.0 | 4 votes |
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()); } }
Example 14
Source File: EntityManagerFactoryBuilderImpl.java From lams with GNU General Public License v2.0 | 4 votes |
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 ); } }