org.hibernate.service.jdbc.connections.spi.ConnectionProvider Java Examples
The following examples show how to use
org.hibernate.service.jdbc.connections.spi.ConnectionProvider.
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: Hibernate4Access.java From snakerflow with Apache License 2.0 | 5 votes |
/** * 取得hibernate的connection对象 */ protected Connection getConnection() throws SQLException { if (sessionFactory instanceof SessionFactoryImpl) { SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) sessionFactory; ConnectionProvider provider = sessionFactoryImpl.getServiceRegistry().getService(ConnectionProvider.class); if(provider != null) return provider.getConnection(); } return null; }
Example #2
Source File: HibernateL2CacheTransactionalSelfTest.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Nullable @Override protected ServiceRegistryBuilder registryBuilder() { ServiceRegistryBuilder builder = new ServiceRegistryBuilder(); 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.addService(TransactionFactory.class, new JtaTransactionFactory()); return builder; }