org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl Java Examples
The following examples show how to use
org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.
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: GrailsHibernateTemplate.java From gorm-hibernate5 with Apache License 2.0 | 6 votes |
public GrailsHibernateTemplate(SessionFactory sessionFactory) { Assert.notNull(sessionFactory, "Property 'sessionFactory' is required"); this.sessionFactory = sessionFactory; ConnectionProvider connectionProvider = ((SessionFactoryImplementor) sessionFactory).getServiceRegistry().getService(ConnectionProvider.class); if(connectionProvider instanceof DatasourceConnectionProviderImpl) { this.dataSource = ((DatasourceConnectionProviderImpl) connectionProvider).getDataSource(); if(dataSource instanceof TransactionAwareDataSourceProxy) { this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource(); } jdbcExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(dataSource); } else { // must be in unit test mode, setup default translator SQLErrorCodeSQLExceptionTranslator sqlErrorCodeSQLExceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(); sqlErrorCodeSQLExceptionTranslator.setDatabaseProductName("H2"); jdbcExceptionTranslator = sqlErrorCodeSQLExceptionTranslator; } }
Example #2
Source File: SchemaMultitenancyTest.java From high-performance-java-persistence with Apache License 2.0 | 5 votes |
private void addTenantConnectionProvider(String tenantId, DataSource tenantDataSource, Properties properties) { DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl(); connectionProvider.setDataSource(tenantDataSource); connectionProvider.configure(properties); MultiTenantConnectionProvider.INSTANCE.getConnectionProviderMap().put( tenantId, connectionProvider ); }
Example #3
Source File: CatalogMultitenancyTest.java From high-performance-java-persistence with Apache License 2.0 | 5 votes |
private void addTenantConnectionProvider(String tenantId, DataSource tenantDataSource, Properties properties) { DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl(); connectionProvider.setDataSource(tenantDataSource); connectionProvider.configure(properties); MultiTenantConnectionProvider.INSTANCE.getConnectionProviderMap().put( tenantId, connectionProvider ); }
Example #4
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 #5
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; }