本文整理汇总了Java中org.hibernate.MultiTenancyStrategy类的典型用法代码示例。如果您正苦于以下问题:Java MultiTenancyStrategy类的具体用法?Java MultiTenancyStrategy怎么用?Java MultiTenancyStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultiTenancyStrategy类属于org.hibernate包,在下文中一共展示了MultiTenancyStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: entityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan(JPA_PACKAGES);
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例2: entityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
LocalValidatorFactoryBean localValidatorFactoryBean) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties.put(MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties.put(MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan(JPA_PACKAGES);
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例3: entityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan(JPA_PACKAGES);
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例4: getJdbcConnectionAccess
import org.hibernate.MultiTenancyStrategy; //导入依赖的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;
}
示例5: buildLocalConnectionAccess
import org.hibernate.MultiTenancyStrategy; //导入依赖的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;
}
};
}
示例6: entityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, MultiTenantConnectionProvider multiTenantConnectionProvider,
CurrentTenantIdentifierResolver tenantIdentifierResolver) {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.mycompany.models");
em.setJpaVendorAdapter(this.jpaVendorAdapter());
final Map<String, Object> jpaProperties = new HashMap<>();
jpaProperties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
jpaProperties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
jpaProperties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantIdentifierResolver);
jpaProperties.put(Environment.FORMAT_SQL, true);
em.setJpaPropertyMap(jpaProperties);
return em;
}
示例7: entityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.srai");
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例8: entityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
MultiTenantConnectionProvider multiTenantConnectionProviderImpl,
CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl,
LocalValidatorFactoryBean localValidatorFactoryBean) {
Map<String, Object> properties = new HashMap<>();
properties.putAll(jpaProperties.getHibernateProperties(dataSource));
properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProviderImpl);
properties
.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolverImpl);
properties.put(JPA_VALIDATION_FACTORY, localValidatorFactoryBean);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan(JPA_PACKAGES);
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaPropertyMap(properties);
return em;
}
示例9: buildJdbcConnectionAccess
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
private JdbcConnectionAccess buildJdbcConnectionAccess(Map configValues) {
final MultiTenancyStrategy multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configValues );
if ( MultiTenancyStrategy.NONE == multiTenancyStrategy ) {
connectionProvider = serviceRegistry.getService( ConnectionProvider.class );
return new ConnectionProviderJdbcConnectionAccess( connectionProvider );
}
else {
connectionProvider = null;
final MultiTenantConnectionProvider multiTenantConnectionProvider = serviceRegistry.getService( MultiTenantConnectionProvider.class );
return new MultiTenantConnectionProviderJdbcConnectionAccess( multiTenantConnectionProvider );
}
}
示例10: AbstractSessionImpl
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
protected AbstractSessionImpl(SessionFactoryImpl factory, String tenantIdentifier) {
this.factory = factory;
this.tenantIdentifier = tenantIdentifier;
if ( MultiTenancyStrategy.NONE == factory.getSettings().getMultiTenancyStrategy() ) {
if ( tenantIdentifier != null ) {
throw new HibernateException( "SessionFactory was not configured for multi-tenancy" );
}
}
else {
if ( tenantIdentifier == null ) {
throw new HibernateException( "SessionFactory configured for multi-tenancy, but no tenant identifier specified" );
}
}
}
示例11: createSessionFactoryBean
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
protected LocalSessionFactoryBean createSessionFactoryBean() {
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
factoryBean.setDataSource(this.dataSourceConfig.dataSource());
if (StringUtil.isEmpty(this.propertiesConfig.hibernateDialect())) {
throw new IllegalStateException("hibernateDialect is required");
}
factoryBean.getHibernateProperties().setProperty(AvailableSettings.DIALECT,
this.propertiesConfig.hibernateDialect());
if (!ArrayUtil.isEmpty(this.propertiesConfig.hibernateMappingLocations())) {
factoryBean
.setMappingLocations(this.propertiesConfig.hibernateMappingLocations());
}
// configure for multitenancy
if (!(this.dataSourceConfig.dataSource() instanceof MultiTenantDataSource)) {
throw new IllegalStateException("a MultiTenantDataSource is required");
}
factoryBean.getHibernateProperties().setProperty(AvailableSettings.MULTI_TENANT,
MultiTenancyStrategy.DATABASE.toString());
factoryBean.setMultiTenantConnectionProvider(
new MultiTenantConnectionProviderImpl((MultiTenantDataSource) this.dataSourceConfig.dataSource()));
factoryBean.setCurrentTenantIdentifierResolver(
new CurrentTenantIdentifierResolverImpl(contextConfig.tenantResolver()));
// update guard
factoryBean.setEntityInterceptor(new MultiTenantEntityInterceptor(contextConfig.tenantResolver()));
return factoryBean;
}
示例12: customEntityManagerFactory
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
public
@Bean
EntityManagerFactory customEntityManagerFactory(DataSource dataSource) {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(false); // turn off with Discriminator strategy so far!
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan(TenancySampleApplication.class.getPackage().getName());
factory.setDataSource(dataSource);
factory.getJpaPropertyMap().put(Environment.DIALECT, PostgreSQL9Dialect.class.getName());
factory.getJpaPropertyMap().put(Environment.MULTI_TENANT, MultiTenancyStrategy.DISCRIMINATOR);
factory.getJpaPropertyMap().put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, new TenantHolder());
factory.afterPropertiesSet();
return factory.getObject();
}
示例13: buildLocalConnectionAccess
import org.hibernate.MultiTenancyStrategy; //导入依赖的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;
}
};
}
示例14: getMultiTenancyStrategy
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
public MultiTenancyStrategy getMultiTenancyStrategy() {
return multiTenancyStrategy;
}
示例15: setMultiTenancyStrategy
import org.hibernate.MultiTenancyStrategy; //导入依赖的package包/类
void setMultiTenancyStrategy(MultiTenancyStrategy multiTenancyStrategy) {
this.multiTenancyStrategy = multiTenancyStrategy;
}