SAAS化下,hibernate session 管理,隔离多租户
来源:互联网 发布:java支付接口开发 编辑:程序博客网 时间:2024/06/06 03:58
-----------------------------TenantMasterFactory.java---------------------------
package com.nen.cn.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
@SuppressWarnings("static-access")
public class TenantMasterFactory{
private static Map<String, SessionFactory> sessionmapdfactory = new HashMap<String, SessionFactory>();
private static Map<String, Session> sessionmap = new HashMap<String, Session>();
private static Configuration cfg = null;
private static Properties pps = null;
TenantMasterFactory() {
}
/**
* new sessionFactorys for the Tenants
*/
static {
pps = new Getproperties().getProperties("src/TenantManagerFile.properties");
try {
for (Iterator iter = pps.keySet().iterator(); iter.hasNext();) {
String element = (String) iter.next();
SessionFactory sessionFactory = Configuartion(pps.getProperty(String.valueOf(element)).trim());
sessionmapdfactory.put(String.valueOf(element), sessionFactory);
}
}catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private static SessionFactory Configuartion(String catalog){
cfg = new Configuration();
cfg.configure("/"+ catalog +"hibernate.cfg.xml");
return cfg.buildSessionFactory();
}
public Session getSession(String catalog) {
Session session = sessionmap.get(catalog);
if( session == null || !session.isOpen()){
if(sessionmapdfactory.get(catalog) == null || sessionmapdfactory.get(catalog).isClosed()){
SessionFactory sessionFactory = Configuartion(catalog);
sessionmapdfactory.put(catalog, sessionFactory);
}
session = sessionmapdfactory.get(catalog).openSession();
sessionmap.put(catalog, session);
}
System.out.println(sessionmapdfactory.get(catalog));
return session;
}
}
------------------------------Getproperties .java------------------------
package com.nen.cn.util;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
public class Getproperties {
private static Properties pps = null;
public static Properties getProperties(String fileName) {
pps = new Properties();
try {
FileInputStream ss = new FileInputStream(fileName);
if(ss != null){
pps.load((InputStream) ss);
}
ss.close();
} catch (Exception e) {
System.out.println("The file loader error....");
}
return pps;
}
}
---------------------------TenantManagerFile.properties)---------------------------
1=WIS1
2=WIS2
3=WIS3
4=WIS4
5=WIS5
6=WIS6
7=WIS7
8=WIS8
9=WIS9
10=WIS10
--------------------------------------------------------------------------------------------------
Session session = dao.getSession(catalog);
catalog = TenantManagerFile.properties 前置项
TenantManagerFile.properties 后置项 = 数据库database名
- SAAS化下,hibernate session 管理,隔离多租户
- SaaS多租户数据隔离的三种方案
- 多租户SaaS应用
- [在线Demo]使用Hibernate多租户实现SaaS服务
- 12cR2多租户下隔离PDB磁盘I/O
- 如何转化成SaaS多租户模式
- SaaS多租户模式数据存储方案
- 多租户--hibernate实现
- hibernate实现多租户
- Hibernate -- 配置c3p0连接池, 事务隔离级别, 管理session
- 多租户技术 【摘】---共用、隔离
- Oracle12.2 多租户环境下的授权管理
- 多session下的事务隔离级别
- 剖析SalesForce的多租户架构(PAAS\SAAS\云计算)
- SAAS软件的多租户实现技术研究笔记
- SaaS架构设计之如何转化成SaaS多租户模式
- SaaS架构设计之如何转化成SaaS多租户模式
- EEPlat PaaS中的多租户数据隔离模式
- android中image文件的压缩与解压缩
- virtio设备中断分析
- 在启动阶段获取控件大小
- CSS text-decoration: blink 只在火狐中闪烁
- 类的静态成员变量
- SAAS化下,hibernate session 管理,隔离多租户
- Net设计模式实例之简单工厂模式(Simple Factory Pattern)
- linux feiq
- 简单记录,非常简单的一个提示音播放类(允许多个提示音播放)
- PL/SQL连接Oracle设置
- 每个程序员都应读的书
- PL/SQL编程(高级特性)
- 面试 改错题-1
- Windows powershell tips:Conditional Operators