当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionProvider类代码示例

本文整理汇总了Java中org.hibernate.engine.jdbc.connections.spi.ConnectionProvider的典型用法代码示例。如果您正苦于以下问题:Java ConnectionProvider类的具体用法?Java ConnectionProvider怎么用?Java ConnectionProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionProvider类属于org.hibernate.engine.jdbc.connections.spi包,在下文中一共展示了ConnectionProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SchemaExport

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) {
	this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
			serviceRegistry.getService( ConnectionProvider.class )
	);
	this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger();
	this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
	this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();

	this.importFiles = ConfigurationHelper.getString(
			AvailableSettings.HBM2DDL_IMPORT_FILES,
			configuration.getProperties(),
			DEFAULT_IMPORT_FILE
	);

	final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
	this.dropSQL = configuration.generateDropSchemaScript( dialect );
	this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SchemaExport.java

示例2: getJdbcConnectionAccess

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
@Override
public JdbcConnectionAccess getJdbcConnectionAccess() {
	if ( jdbcConnectionAccess == null ) {
		if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) {
			jdbcConnectionAccess = new NonContextualJdbcConnectionAccess(
					getEventListenerManager(),
					factory.getServiceRegistry().getService( ConnectionProvider.class )
			);
		}
		else {
			jdbcConnectionAccess = new ContextualJdbcConnectionAccess(
					getEventListenerManager(),
					factory.getServiceRegistry().getService( MultiTenantConnectionProvider.class )
			);
		}
	}
	return jdbcConnectionAccess;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:AbstractSessionImpl.java

示例3: buildLocalConnectionAccess

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
private JdbcConnectionAccess buildLocalConnectionAccess() {
	return new JdbcConnectionAccess() {
		@Override
		public Connection obtainConnection() throws SQLException {
			return settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE
					? serviceRegistry.getService( ConnectionProvider.class ).getConnection()
					: serviceRegistry.getService( MultiTenantConnectionProvider.class ).getAnyConnection();
		}

		@Override
		public void releaseConnection(Connection connection) throws SQLException {
			if ( settings.getMultiTenancyStrategy() == MultiTenancyStrategy.NONE ) {
				serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection );
			}
			else {
				serviceRegistry.getService( MultiTenantConnectionProvider.class ).releaseAnyConnection( connection );
			}
		}

		@Override
		public boolean supportsAggressiveRelease() {
			return false;
		}
	};
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:SessionFactoryImpl.java

示例4: closeHibernate

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
public static void closeHibernate() {
	if (sSessionFactory!=null) {
		if (sSessionFactory instanceof SessionFactoryImpl) {
			ConnectionProvider cp = ((SessionFactoryImpl)sSessionFactory).getConnectionProvider();
			if (cp instanceof DisposableConnectionProvider) {
				try {
					((DisposableConnectionProvider)cp).destroy();
				} catch (Exception e) {
					sLog.error("Failed to destroy connection provider: " + e.getMessage());
				}
			}
		}
		sSessionFactory.close();
		sSessionFactory=null;
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:17,代码来源:HibernateUtil.java

示例5: getDataSource

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
/**
 * Determine the DataSource of the given SessionFactory.
 * @param sessionFactory the SessionFactory to check
 * @return the DataSource, or {@code null} if none found
 * @see ConnectionProvider
 */
public static DataSource getDataSource(SessionFactory sessionFactory) {
	if (sessionFactory instanceof SessionFactoryImplementor) {
		try {
			ConnectionProvider cp = ((SessionFactoryImplementor) sessionFactory).getServiceRegistry().getService(
					ConnectionProvider.class);
			if (cp != null) {
				return cp.unwrap(DataSource.class);
			}
		}
		catch (UnknownServiceException ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("No ConnectionProvider found - cannot determine DataSource for SessionFactory: " + ex);
			}
		}
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:SessionFactoryUtils.java

示例6: build

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
public SessionFactory build(final RemoteCredentialHibernateBundle<?> bundle,
        final Environment environment,
        final PooledDataSourceFactory dbConfig,
        final ManagedDataSource dataSource,
        final List<Class<?>> entities) {
    final ConnectionProvider provider = this.buildConnectionProvider(dataSource,
            dbConfig.getProperties());
    final SessionFactory factory = this.buildSessionFactory(bundle,
            dbConfig,
            provider,
            dbConfig.getProperties(),
            entities);
    final SessionFactoryManager managedFactory = new SessionFactoryManager(factory, dataSource);
    environment.lifecycle().manage(managedFactory);
    return factory;
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:17,代码来源:SessionFactoryFactory.java

示例7: buildSessionFactory

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
private static SessionFactory buildSessionFactory() {
	try {
		Configuration configuration = new Configuration();

		Properties props = new Properties();
		props.put("hibernate.current_session_context_class", "thread");
		configuration.setProperties(props);

		for (Class<?> clazz : entityClasses) {
			configuration.addAnnotatedClass(clazz);
		}

		PluginHandler.get().getPlugin().addAnnotatedClass(configuration);

		ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
				.applySettings(configuration.getProperties())
				.addService(ConnectionProvider.class, new NomadConnectionProvider()).build();

		SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

		return sessionFactory;
	} catch (Throwable ex) {
		logger.error("Failed to build session factory.", ex);
		throw new ExceptionInInitializerError(ex);
	}
}
 
开发者ID:GHzGangster,项目名称:Nomad,代码行数:27,代码来源:DB.java

示例8: GrailsHibernateTemplate

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
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;
    }
}
 
开发者ID:grails,项目名称:gorm-hibernate5,代码行数:20,代码来源:GrailsHibernateTemplate.java

示例9: testSelectStatementWithStatementsCache

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
@Test
public void testSelectStatementWithStatementsCache() throws SQLException {
    Session session = HibernateTestUtils.getSessionFactoryWithStmtCache().openSession();

    ConnectionProvider cp = ((SessionFactoryImplementor) session.getSessionFactory())
            .getServiceRegistry().getService(ConnectionProvider.class);
    ViburDBCPDataSource ds = ((ViburDBCPConnectionProvider) cp).getDataSource();

    ConcurrentMap<StatementMethod, StatementHolder> mockedStatementCache = mockStatementCache(ds);

    executeAndVerifySelectInSession(session);
    // resources/hibernate-with-stmt-cache.cfg.xml defines pool with 1 connection only, that's why
    // the second session will get and use the same underlying connection.
    session = HibernateTestUtils.getSessionFactoryWithStmtCache().openSession();
    executeAndVerifySelectInSession(session);

    InOrder inOrder = inOrder(mockedStatementCache);
    inOrder.verify(mockedStatementCache).get(key1.capture());
    inOrder.verify(mockedStatementCache).putIfAbsent(same(key1.getValue()), val1.capture());
    inOrder.verify(mockedStatementCache).get(key2.capture());

    assertEquals(1, mockedStatementCache.size());
    assertTrue(mockedStatementCache.containsKey(key1.getValue()));
    assertEquals(key1.getValue(), key2.getValue());
    assertEquals(AVAILABLE, val1.getValue().state().get());
}
 
开发者ID:vibur,项目名称:vibur-dbcp-hibernate4,代码行数:27,代码来源:ViburDBCPConnectionProviderTest.java

示例10: buildSessionFactory

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
/**
 * Builds a {@link SessionFactory}
 * @param bundle
 *            the bundle
 * @param dbConfig
 *            the dbconfig
 * @param connectionProvider
 *            the connection provider
 * @param properties
 *            the hibernate properties
 * @param entities
 *            the persistent entities
 * @return {@link SessionFactory}
 */
private SessionFactory buildSessionFactory(RoutingHibernateBundle<?> bundle, DataSourceFactory dbConfig,
        ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS,
            Boolean.toString(dbConfig.isAutoCommentsEnabled()));
    configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
    configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
    configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
    configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
    configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
    for (Map.Entry<String, String> property : properties.entrySet()) {
        configuration.setProperty(property.getKey(), property.getValue());
    }

    addAnnotatedClasses(configuration, entities);
    bundle.configure(configuration);

    final ServiceRegistry registry = new StandardServiceRegistryBuilder()
            .addService(ConnectionProvider.class, connectionProvider).applySettings(properties).build();

    return configuration.buildSessionFactory(registry);
}
 
开发者ID:Astonish-Results,项目名称:dropwizard-routing,代码行数:40,代码来源:RoutingSessionFactoryFactory.java

示例11: getSqlConnection

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
public Connection getSqlConnection() {
	Connection connection = null;
	try {
		connection = getSessionFactory().
				getSessionFactoryOptions().getServiceRegistry().
				getService(ConnectionProvider.class).getConnection();
	} catch (SQLException e) {
		final InformationFrame INFORMATION_FRAME = new InformationFrame();
		INFORMATION_FRAME.setMessage("Connection converting error!\n" +e.getLocalizedMessage());
		INFORMATION_FRAME.setVisible(true);
	}
	return connection;
}
 
开发者ID:Coder-ACJHP,项目名称:Hotel-Properties-Management-System,代码行数:14,代码来源:DataSourceFactory.java

示例12: prepare

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
public void prepare(boolean needsAutoCommit) throws SQLException {
	serviceRegistry = createServiceRegistry( cfgProperties );
	connection = serviceRegistry.getService( ConnectionProvider.class ).getConnection();
	if ( needsAutoCommit && ! connection.getAutoCommit() ) {
		connection.commit();
		connection.setAutoCommit( true );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ManagedProviderConnectionHelper.java

示例13: releaseConnection

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
private void releaseConnection() throws SQLException {
	if ( connection != null ) {
		try {
			new SqlExceptionHelper().logAndClearWarnings( connection );
		}
		finally {
			try  {
				serviceRegistry.getService( ConnectionProvider.class ).closeConnection( connection );
			}
			finally {
				connection = null;
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:ManagedProviderConnectionHelper.java

示例14: unwrap

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
@Override
@SuppressWarnings( {"unchecked"})
public <T> T unwrap(Class<T> unwrapType) {
	if ( ConnectionProvider.class.equals( unwrapType ) ||
			DriverManagerConnectionProviderImpl.class.isAssignableFrom( unwrapType ) ) {
		return (T) this;
	}
	else {
		throw new UnknownUnwrapTypeException( unwrapType );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:DriverManagerConnectionProviderImpl.java

示例15: unwrap

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; //导入依赖的package包/类
@Override
@SuppressWarnings( {"unchecked"})
public <T> T unwrap(Class<T> unwrapType) {
	if ( ConnectionProvider.class.equals( unwrapType ) ||
			UserSuppliedConnectionProviderImpl.class.isAssignableFrom( unwrapType ) ) {
		return (T) this;
	}
	else {
		throw new UnknownUnwrapTypeException( unwrapType );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:UserSuppliedConnectionProviderImpl.java


注:本文中的org.hibernate.engine.jdbc.connections.spi.ConnectionProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。