} else if (dialect.indexOf("SQLServer") > -1) {
connection_url = "jdbc:sqlserver://" + ipAddress + ":" + port
+ ";DataBaseName=" + dataBaseName;
} else if (dialect.indexOf("Oracle") > -1) {
connection_url = "jdbc:oracle:thin:@" + ipAddress + ":" + port
+ ":" + dataBaseName;
} else {
throw new HibernateException("The dialect was not allowed.==fd=="
+ dialect);
}
super.setProperty("hibernate.dialect", dialect);
super.setProperty("hibernate.connection.url", connection_url);
super.setProperty("hibernate.connection.driver_class", driverClass);
super.setProperty("hibernate.connection.username", username);
super.setProperty("hibernate.connection.password", password);
super.setProperty("hibernate.default_schema", schema);
// super.setProperty("hibernate.default_catalog", catalog);
// super.setProperty("hibernate.show_sql", "true");
super.setProperty("bonecp.idleMaxAge", "30");
super.setProperty("bonecp.idleConnectionTestPeriod", "5");
super.setProperty("bonecp.partitionCount", "3");
super.setProperty("bonecp.acquireIncrement", "1");
super.setProperty("bonecp.maxConnectionsPerPartition", "30");
super.setProperty("bonecp.minConnectionsPerPartition", "10");
super.setProperty("bonecp.statementsCacheSize", "50");
super.setProperty("bonecp.releaseHelperThreads", "3");
super.setProperty("bonecp.connectionTestStatement", "select 1 from dual");
}
}
[java]
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
/**
* 动态会话工厂类
* @author 陈道俊改进版
*
*/
public class DynamicSessionFactory {
// private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal
private static DynamicHibernateConfiguration configuration = new DynamicHibernateConfiguration();
private static org.hibernate.SessionFactory sessionFactory;
private static List
private static Map
// private static String configFile = CONFIG_FILE_LOCATION;
/* static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err.println("%%%% 创建临时会话工厂错误 %%%%");
e.printStackTrace();
}
}*/
private DynamicSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize the
* SessionFactory if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) sessionFactory.openS