Java Code Examples for org.hibernate.boot.registry.StandardServiceRegistryBuilder#applySetting()
The following examples show how to use
org.hibernate.boot.registry.StandardServiceRegistryBuilder#applySetting() .
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: EntityManagerFactoryBuilderImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private void configure(StandardServiceRegistryBuilder ssrBuilder) { applyJdbcConnectionProperties( ssrBuilder ); applyTransactionProperties( ssrBuilder ); // flush before completion validation if ( "true".equals( configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) { ssrBuilder.applySetting( Environment.FLUSH_BEFORE_COMPLETION, "false" ); LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION ); } // final StrategySelector strategySelector = ssrBuilder.getBootstrapServiceRegistry().getService( StrategySelector.class ); // final Object interceptorSetting = configurationValues.remove( AvailableSettings.SESSION_INTERCEPTOR ); // if ( interceptorSetting != null ) { // settings.setSessionInterceptorClass( // loadSessionInterceptorClass( interceptorSetting, strategySelector ) // ); // } }
Example 2
Source File: EntityManagerFactoryBuilderImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private void applyTransactionProperties(StandardServiceRegistryBuilder ssrBuilder) { PersistenceUnitTransactionType txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType( configurationValues.get( JPA_TRANSACTION_TYPE ) ); if ( txnType == null ) { txnType = persistenceUnit.getTransactionType(); } if ( txnType == null ) { // is it more appropriate to have this be based on bootstrap entry point (EE vs SE)? txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL; } boolean hasTxStrategy = configurationValues.containsKey( TRANSACTION_COORDINATOR_STRATEGY ); if ( hasTxStrategy ) { LOG.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY ); } else { if ( txnType == PersistenceUnitTransactionType.JTA ) { ssrBuilder.applySetting( TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class ); } else if ( txnType == PersistenceUnitTransactionType.RESOURCE_LOCAL ) { ssrBuilder.applySetting( TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class ); } } }
Example 3
Source File: App.java From juddi with Apache License 2.0 | 6 votes |
/** * Method that actually creates the file. * * @param dbDialect to use */ private void generate(Dialect dialect) { StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(); ssrb.applySetting("hibernate.dialect", dialect.getDialectClass()); StandardServiceRegistry standardServiceRegistry = ssrb.build(); MetadataSources metadataSources = new MetadataSources(standardServiceRegistry); for (Class clzz : jpaClasses) { metadataSources.addAnnotatedClass(clzz); } Metadata metadata = metadataSources.buildMetadata(); SchemaExport export = new SchemaExport(); export.setDelimiter(";"); export.setOutputFile(dialect.name().toLowerCase() + ".ddl"); //export.execute(true, false, false, true); export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata); }
Example 4
Source File: EntityManagerFactoryBuilderImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private void applyJdbcConnectionProperties(StandardServiceRegistryBuilder ssrBuilder) { if ( dataSource != null ) { ssrBuilder.applySetting( DATASOURCE, dataSource ); } else if ( persistenceUnit.getJtaDataSource() != null ) { if ( ! ssrBuilder.getSettings().containsKey( DATASOURCE ) ) { ssrBuilder.applySetting( DATASOURCE, persistenceUnit.getJtaDataSource() ); // HHH-8121 : make the PU-defined value available to EMF.getProperties() configurationValues.put( JPA_JTA_DATASOURCE, persistenceUnit.getJtaDataSource() ); } } else if ( persistenceUnit.getNonJtaDataSource() != null ) { if ( ! ssrBuilder.getSettings().containsKey( DATASOURCE ) ) { ssrBuilder.applySetting( DATASOURCE, persistenceUnit.getNonJtaDataSource() ); // HHH-8121 : make the PU-defined value available to EMF.getProperties() configurationValues.put( JPA_NON_JTA_DATASOURCE, persistenceUnit.getNonJtaDataSource() ); } } else { final String driver = (String) configurationValues.get( JPA_JDBC_DRIVER ); if ( StringHelper.isNotEmpty( driver ) ) { ssrBuilder.applySetting( DRIVER, driver ); } final String url = (String) configurationValues.get( JPA_JDBC_URL ); if ( StringHelper.isNotEmpty( url ) ) { ssrBuilder.applySetting( URL, url ); } final String user = (String) configurationValues.get( JPA_JDBC_USER ); if ( StringHelper.isNotEmpty( user ) ) { ssrBuilder.applySetting( USER, user ); } final String pass = (String) configurationValues.get( JPA_JDBC_PASSWORD ); if ( StringHelper.isNotEmpty( pass ) ) { ssrBuilder.applySetting( PASS, pass ); } } }
Example 5
Source File: Hbm2ddl.java From wallride with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { String locationPattern = "classpath:/org/wallride/domain/*"; final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build(); final MetadataSources metadataSources = new MetadataSources(registry); final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry); registryBuilder.applySetting(AvailableSettings.DIALECT, ExtendedMySQL5InnoDBDialect.class.getCanonicalName()); registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true); registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, PhysicalNamingStrategySnakeCaseImpl.class); final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); final Resource[] resources = resourcePatternResolver.getResources(locationPattern); final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(); for (Resource resource : resources) { MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource); AnnotationMetadata metadata = metadataReader.getAnnotationMetadata(); if (metadata.hasAnnotation(Entity.class.getName())) { metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName())); } } final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build(); final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl); new SchemaExport() .setHaltOnError(true) .setDelimiter(";") .create(EnumSet.of(TargetType.STDOUT), metadataBuilder.build()); }
Example 6
Source File: HibernateL2CacheExample.java From ignite with Apache License 2.0 | 5 votes |
/** * Creates a new Hibernate {@link SessionFactory} using a programmatic * configuration. * * @param hibernateCfg Hibernate configuration file. * @return New Hibernate {@link SessionFactory}. */ private static SessionFactory createHibernateSessionFactory(URL hibernateCfg) { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", JDBC_URL); builder.applySetting("hibernate.show_sql", true); builder.configure(hibernateCfg); return new MetadataSources(builder.build()).buildMetadata().buildSessionFactory(); }
Example 7
Source File: HibernateL2CacheSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Starts Hibernate. * * @param accessType Cache access type. * @param igniteInstanceName Ignite instance name. * @return Session factory. */ private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) { StandardServiceRegistryBuilder builder = registryBuilder(); for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue()); // Use the same cache for Entity and Entity2. builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME); StandardServiceRegistry srvcRegistry = builder.build(); MetadataSources metadataSources = new MetadataSources(srvcRegistry); for (Class entityClass : getAnnotatedClasses()) metadataSources.addAnnotatedClass(entityClass); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (!entityBinding.isInherited()) ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName()); } for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings()) collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName()); return metadata.buildSessionFactory(); }
Example 8
Source File: HibernateL2CacheSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @return Hibernate registry builder. */ protected StandardServiceRegistryBuilder registryBuilder() { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); return builder; }
Example 9
Source File: HibernateL2CacheStrategySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param accessType Cache access typr. * @param igniteInstanceName Name of the grid providing caches. * @return Session factory. */ private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue()); builder.applySetting(USE_STRUCTURED_CACHE, "true"); builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1"); builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2"); builder.applySetting(REGION_CACHE_PROPERTY + DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME, DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME); builder.applySetting(REGION_CACHE_PROPERTY + DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME); MetadataSources metadataSources = new MetadataSources(builder.build()); metadataSources.addAnnotatedClass(Entity1.class); metadataSources.addAnnotatedClass(Entity2.class); metadataSources.addAnnotatedClass(Entity3.class); metadataSources.addAnnotatedClass(Entity4.class); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (!entityBinding.isInherited()) ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName()); } return metadata.buildSessionFactory(); }
Example 10
Source File: HibernateL2CacheConfigurationSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param igniteInstanceName Name of the grid providing caches. * @return Session factory. */ private SessionFactory startHibernate(String igniteInstanceName) { Configuration cfg = hibernateConfiguration(igniteInstanceName); StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); builder.applySetting("hibernate.show_sql", false); builder.applySettings(cfg.getProperties()); return cfg.buildSessionFactory(builder.build()); }
Example 11
Source File: HibernateL2CacheSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Starts Hibernate. * * @param accessType Cache access type. * @param igniteInstanceName Ignite instance name. * @return Session factory. */ private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) { StandardServiceRegistryBuilder builder = registryBuilder(); for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue()); // Use the same cache for Entity and Entity2. builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME); StandardServiceRegistry srvcRegistry = builder.build(); MetadataSources metadataSources = new MetadataSources(srvcRegistry); for (Class entityClass : getAnnotatedClasses()) metadataSources.addAnnotatedClass(entityClass); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (!entityBinding.isInherited()) ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName()); } for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings()) collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName() ); return metadata.buildSessionFactory(); }
Example 12
Source File: HibernateL2CacheSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @return Hibernate registry builder. */ protected StandardServiceRegistryBuilder registryBuilder() { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); return builder; }
Example 13
Source File: HibernateL2CacheStrategySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param accessType Cache access typr. * @param igniteInstanceName Name of the grid providing caches. * @return Session factory. */ private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue()); builder.applySetting(USE_STRUCTURED_CACHE, "true"); builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1"); builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2"); builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE); builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE); MetadataSources metadataSources = new MetadataSources(builder.build()); metadataSources.addAnnotatedClass(Entity1.class); metadataSources.addAnnotatedClass(Entity2.class); metadataSources.addAnnotatedClass(Entity3.class); metadataSources.addAnnotatedClass(Entity4.class); Metadata metadata = metadataSources.buildMetadata(); for (PersistentClass entityBinding : metadata.getEntityBindings()) { if (!entityBinding.isInherited()) ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName()); } return metadata.buildSessionFactory(); }
Example 14
Source File: HibernateL2CacheConfigurationSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param igniteInstanceName Name of the grid providing caches. * @return Session factory. */ private SessionFactory startHibernate(String igniteInstanceName) { Configuration cfg = hibernateConfiguration(igniteInstanceName); StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); builder.applySetting("hibernate.connection.url", CONNECTION_URL); builder.applySetting("hibernate.show_sql", false); builder.applySettings(cfg.getProperties()); return cfg.buildSessionFactory(builder.build()); }
Example 15
Source File: HibernateL2CacheMultiJvmTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param nodeName Name of the grid providing caches. * @return Session factory. */ SessionFactory startHibernate(String nodeName) { log.info("Start hibernate on node: " + nodeName); StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue()); builder.applySetting("hibernate.connection.url", CONNECTION_URL); MetadataSources metadataSources = new MetadataSources(builder.build()); metadataSources.addAnnotatedClass(Entity1.class); metadataSources.addAnnotatedClass(Entity2.class); metadataSources.addAnnotatedClass(Entity3.class); return metadataSources.buildMetadata().buildSessionFactory(); }
Example 16
Source File: HibernateL2CacheMultiJvmTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param nodeName Name of the grid providing caches. * @return Session factory. */ SessionFactory startHibernate(String nodeName) { log.info("Start hibernate on node: " + nodeName); StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet()) builder.applySetting(e.getKey(), e.getValue()); builder.applySetting("hibernate.connection.url", CONNECTION_URL); MetadataSources metadataSources = new MetadataSources(builder.build()); metadataSources.addAnnotatedClass(Entity1.class); metadataSources.addAnnotatedClass(Entity2.class); metadataSources.addAnnotatedClass(Entity3.class); return metadataSources.buildMetadata().buildSessionFactory(); }
Example 17
Source File: HibernateL2CacheTransactionalSelfTest.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl(); BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source. dataSrc.setTransactionManager(jotm.getTransactionManager()); dataSrc.setDefaultAutoCommit(false); JdbcDataSource h2DataSrc = new JdbcDataSource(); h2DataSrc.setURL(CONNECTION_URL); dataSrc.setXaDataSourceInstance(h2DataSrc); connProvider.setDataSource(dataSrc); connProvider.configure(Collections.emptyMap()); builder.addService(ConnectionProvider.class, connProvider); builder.addService(JtaPlatform.class, new TestJtaPlatform()); builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()); return builder; }
Example 18
Source File: HibernateL2CacheTransactionalSelfTest.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() { StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder(); DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl(); BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source. dataSrc.setTransactionManager(jotm.getTransactionManager()); dataSrc.setDefaultAutoCommit(false); JdbcDataSource h2DataSrc = new JdbcDataSource(); h2DataSrc.setURL(CONNECTION_URL); dataSrc.setXaDataSourceInstance(h2DataSrc); connProvider.setDataSource(dataSrc); connProvider.configure(Collections.emptyMap()); builder.addService(ConnectionProvider.class, connProvider); builder.addService(JtaPlatform.class, new TestJtaPlatform()); builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()); return builder; }