Java 类org.hibernate.service.jdbc.connections.spi.MultiTenantConnectionProvider 实例源码

项目:hibernate-dynamic-dialects    文件:SessionFactoryImpl.java   
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;
        }
    };
}