import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
public class DynamicHibernateConfiguration extends Configuration {
public DynamicHibernateConfiguration() {
super();
}
public void reset() {
super.reset();
}
public DynamicHibernateConfiguration(String dialect, String driverClass,
String ipAddress, String port, String dataBaseName,
String username, String password) throws HibernateException {
String connection_url = "";
if (dialect.indexOf("MySQL") > -1) {
connection_url = "jdbc:mysql://" + ipAddress + "/" + dataBaseName;
} 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);
}
// 连接池提供类,本配置采用bonecp连接池
/*super.setProperty("hibernate.connection.provider_class","com.jolbox.bonecp.provider.BoneCPConnectionProvider");
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("bonecp.idleMaxAge", "0");
super.setProperty("bonecp.idleConnectionTestPeriod", "1");
super.setProperty("bonecp.partitionCount", "3");
super.setProperty("bonecp.maxConnectionsPerPartition", "25");
super.setProperty("bonecp.minConnectionsPerPartition", "5");
super.setProperty("bonecp.acquireIncrement", "1");
super.setProperty("bonecp.connectionTimeout", "5000");
super.setProperty("bonecp.poolAvailabilityThreshold", "30");
super.setProperty("bonecp.statementsCacheSize", "50");
super.setProperty("bonecp.preparedStatementCacheSize", "50");
super.setProperty("bonecp.releaseHelperThreads", "3");
super.setProperty("bonecp.statementReleaseHelperThreads", "3");
super.setProperty("bonecp.connectionTestStatement","select 1");
super.setProperty("hibernate.connection.release_mode","after_statement");*/
//c3p0
System.out.println("connection_url==="+connection_url);
super.setProperty("hibernate.connection.provider_class","org.hibernate.connection.C3P0ConnectionProvider");
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.connection.release_mode","after_statement");
super.setProperty("hibernate.c3p0.max_size","15");
super.setProperty("hibernate.c3p0.min_size","10");
super.setProperty("hibernate.c3p0.timeout","120");
super.setProperty("hibernate.c3p0.max_statements","100");
super.setProperty("hibernate.c3p0.idle_test_period","120");
super.setProperty("hibernate.c3p0.acquire_increment","5");
super.setProperty("hibernate.c3p0.testConnectionOnCheckin","true");
super.setProperty("hibernate.c3p0.testConnectionOnCheckout","true");
}
public DynamicHibernateConfiguration(String dialect, String driverClass,
String ipAddress, String port, String dataBaseName,
String username, String password, String schema, String catalog)
throws HibernateException {
String connection_url = "";
if (dialect.indexOf("MySQL") > -1) {
connection_url = "jdbc:mysql://" + ipAddress + "/" + dataBaseName;
} 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);
}
// 连接池提供类,本配置采用bonecp连接池
/*super.setProperty("hibernate.connection.provider_class","com.jolbox.bonecp.provider.BoneCPConnectionProvider");
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("bonecp.idleMaxAge", "0");
super.setProperty("bonecp.idleConnectionTestPeriod", "1");
super.setProperty("bonecp.partitionCount", "3");
super.setProperty("bonecp.maxConnectionsPerPartition", "25");
super.setProperty("bonecp.minConnectionsPerPartition", "5");
super.setProperty("bonecp.acquireIncrement", "1");
super.setProperty("bonecp.connectionTimeout", "5000");
super.setProperty("bonecp.poolAvailabilityThreshold", "30");
super.setProperty("bonecp.statementsCacheSize", "50");
super.setProperty("bonecp.preparedStatementCacheSize", "50");
super.setProperty("bonecp.releaseHelperThreads", "3");
super.setProperty("bonecp.statementReleaseHelperThreads", "3");
super.setProperty("bonecp.connectionTestStatement","select 1");
super.setProperty("hibernate.connection.release_mode","after_statement");*/
super.setProperty("hibernate.connection.provider_class","org.hibernate.connection.C3P0ConnectionProvider");
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.connection.release_mode","after_statement");
super.setProperty("hibernate.c3p0.max_size","15");
super.setProperty("hibernate.c3p0.min_size","10");
super.setProperty("hibernate.c3p0.timeout","120");
super.setProperty("hibernate.c3p0.max_statements","100");
super.setProperty("hibernate.c3p0.idle_test_period","120");
super.setProperty("hibernate.c3p0.acquire_increment","5");
super.setProperty("hibernate.c3p0.testConnectionOnCheckin","true");
super.setProperty("hibernate.c3p0.testConnectionOnCheckout","true");
}
public DynamicHibernateConfiguration(String dialect, String driverClass,
String ipAddress, String port, String dataBaseName,
String username, String password, String cj) throws HibernateException {
String connection_url = "";
if (dialect.indexOf("MySQL") > -1) {
connection_url = "jdbc:mysql://" + ipAddress + "/" + dataBaseName;
} 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);
}
// 连接池提供类,本配置采用bonecp连接池
/*super.setProperty("hibernate.connection.provider_class","com.jolbox.bonecp.provider.BoneCPConnectionProvider");
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("bonecp.idleMaxAge", "0");
super.setProperty("bonecp.idleConnectionTestPeriod", "1");
super.setProperty("bonecp.partitionCount", "3");
super.setProperty("bonecp.maxConnectionsPerPartition", "25");
super.setProperty("bonecp.minConnectionsPerPartition", "5");
super.setProperty("bonecp.acquireIncrement", "1");
super.setProperty("bonecp.connectionTimeout", "5000");
super.setProperty("bonecp.poolAvailabilityThreshold", "30");
super.setProperty("bonecp.statementsCacheSize", "50");
super.setProperty("bonecp.preparedStatementCacheSize", "50");
super.setProperty("bonecp.releaseHelperThreads", "3");
super.setProperty("bonecp.statementReleaseHelperThreads", "3");
super.setProperty("bonecp.connectionTestStatement","select 1");
super.setProperty("hibernate.connection.release_mode","after_statement");*/
//c3p0
super.setProperty("hibernate.connection.provider_class","org.hibernate.connection.C3P0ConnectionProvider");
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.connection.release_mode","after_statement");
super.setProperty("hibernate.c3p0.max_size","15");
super.setProperty("hibernate.c3p0.min_size","10");
super.setProperty("hibernate.c3p0.timeout","120");
super.setProperty("hibernate.c3p0.max_statements","100");
super.setProperty("hibernate.c3p0.idle_test_period","120");
super.setProperty("hibernate.c3p0.acquire_increment","5");
super.setProperty("hibernate.c3p0.testConnectionOnCheckin","true");
super.setProperty("hibernate.c3p0.testConnectionOnCheckout","true");
}
public DynamicHibernateConfiguration(String dialect, String driverClass,
String ipAddress, String port, String dataBaseName,
String username, String password, String schema, String catalog, String cj)
throws HibernateException {
String connection_url = "";
if (dialect.indexOf("MySQL") > -1) {
connection_url = "jdbc:mysql://" + ipAddress + "/" + dataBaseName;
} 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);
}
// 连接池提供类,本配置采用bonecp连接池
/*super.setProperty("hibernate.connection.provider_class","com.jolbox.bonecp.provider.BoneCPConnectionProvider");
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("bonecp.idleMaxAge", "0");
super.setProperty("bonecp.idleConnectionTestPeriod", "1");
super.setProperty("bonecp.partitionCount", "3");
super.setProperty("bonecp.maxConnectionsPerPartition", "25");
super.setProperty("bonecp.minConnectionsPerPartition", "5");
super.setProperty("bonecp.acquireIncrement", "1");
super.setProperty("bonecp.connectionTimeout", "5000");
super.setProperty("bonecp.poolAvailabilityThreshold", "30");
super.setProperty("bonecp.statementsCacheSize", "50");
super.setProperty("bonecp.preparedStatementCacheSize", "50");
super.setProperty("bonecp.releaseHelperThreads", "3");
super.setProperty("bonecp.statementReleaseHelperThreads", "3");
super.setProperty("bonecp.connectionTestStatement","select 1");
super.setProperty("hibernate.connection.release_mode","after_statement");*/
super.setProperty("hibernate.connection.provider_class","org.hibernate.connection.C3P0ConnectionProvider");
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.connection.release_mode","after_statement");
super.setProperty("hibernate.c3p0.max_size","15");
super.setProperty("hibernate.c3p0.min_size","10");
super.setProperty("hibernate.c3p0.timeout","120");
super.setProperty("hibernate.c3p0.max_statements","100");
super.setProperty("hibernate.c3p0.idle_test_period","120");
super.setProperty("hibernate.c3p0.acquire_increment","5");
super.setProperty("hibernate.c3p0.testConnectionOnCheckin","true");
super.setProperty("hibernate.c3p0.testConnectionOnCheckout","true");
}
}
相关推荐
踩坑记录:Clawdbot 对接 Minimax 报错 “401 token is unusable (1004)“ 的终极解决方案
如果你也在配置 Clawdbot 对接 Minimax 模型时,明明 API Key 是新申请的,却死活报错 `401 Unauthorized`,错误码 `1004`,提示 `token is unusable`——那么恭喜你,来对地方了。
Hibernate dynamic model 动态模型
Hibernate的动态模型为我们动态改动表结构带来了方便, 个人认为这一点非常有价值, 现在的企业级应用系统越来越强调用户可定制性, hibernate的这一点使用户自定义字段或自定义表成为可能 .
Python高效转换病理图像:从mrxs到SVS的完整实践指南
本文提供了使用Python将数字病理切片从mrxs格式高效转换为SVS格式的完整实践指南。针对mrxs格式兼容性差的问题,文章详细解析了基于openslide和tifffile库的核心转换流程,并重点分享了应对大内存消耗的优化方案与流式处理技巧,确保转换后的SVS文件保留多分辨率金字塔结构,兼容主流病理分析工具。
Hibernate之配置文件
可持久化对象有以下三种状态: 临时状态(Transient):对象在保存进数据库之前为临时状态,这时数据库中没有该对象的信息,如果没有持久化,程序退出后临时状态的对象信息将会丢失。随时可能被垃圾回收器回收(在数据库中没有于之对应的记录,应为是new初始化),而执行save()方法后,就变为Persistent对象(持久性对象),没有纳入session的管理,内存中一个对象,没有ID,缓存...
二、时间序列的预处理
一般情况下,拿到一个观察值序列之后,首先要对它的平稳性和纯随机性进行检验,这两个重要的检验称为序列的预处理。根据检验的结果可以将序列分为不同的类型,对不同类型的序列我们会采用不同的分析方法。 一、平稳性检验 1、特征统计量 (1)概率分布 数理统计的基础知识告诉我们分布函数或者密度函数能够完整地描述一个随机变量的统计特征。同样,一个堆积变量族{Xt} 的统计特征也完全由...
EMC设计实战:BCI(大电流注入)硬件设计规范
LIN接口:集成TVS管(如PESD5V0S1BL)与共模电感,耐压等级≥20V(8kV HBM)。输入滤波:10μF电解电容(100kHz截止)+ 0.1μF陶瓷电容(10MHz截止)。:全频段(1MHz-400MHz)注入200mA电流,LIN通信误码率<0.01%。对敏感电路(如传感器)采用隔离电源(如ADuM5000),隔离电压≥3kVrms。:连续波(CW)与调幅波(AM,调制深度80%)组合,覆盖全频段干扰场景。:选择低频段(1-100MHz)感量≥100μH的绕线电感,抑制共模电流。
hibernate动态读取配置及创建数据源
public static Configuration initDBConfig(String dialect, String driver, String url, String user, String pwd){ Configuration cfg = new Configuration().configure("/hibernate.cfg.xml"); cfg.setProper
深圳SILAS(智能融合低空系统)无人机调度系统介绍
一、系统定位与核心目标SILAS(Smart Integrated Lower Airspace System)是深圳市为低空经济打造的“数字大脑”,由粤港澳大湾区数字经济研究院自主研发,定位为城市级低空飞行智能调度与管理平台。核心目标是解决低空经济中“高密度、高复杂度、多主体”的飞行调度难题,实现空域资源的高效分配、飞行安全的智能监管及全场景服务的无缝协同,支撑深圳从“无人机之都”向“天空之城”升级。二、核心架构:低空基础设施“四张网”设施网。
Hibernate数据库属性hibernate.dialect的设置
数据库属性hibernate.dialect的设置 为数据库属性hibernate.dialect设置正确的 org.hibernate.dialect.Dialect子类. 如果指定一种方言, Hibernate将为上面列出的一些属性使用合理的默认值, 为你省去了手工指定它们的功夫. RDBMS 方言 DB2 org.hiber
【STM32 CubeMX】I2C中断方式与DMA方式
在STM32 CubeMX环境中,I2C(Inter-Integrated Circuit)通信协议的实现可以采用中断方式或DMA(Direct Memory Access)方式。中断方式通过触发中断来处理数据传输,而DMA方式则利用直接内存访问技术来实现数据传输,减轻了CPU的负担。在选择I2C通信方式时,开发者需要根据具体的应用需求和性能要求来选择合适的方式。STM32 CubeMX提供了图形化配置工具,使得配置I2C通信方式变得更加便捷。
[Python图像处理] 十九.图像分割之基于K-Means聚类的区域分割
前面的文章讲解了图像锐化和边缘提取技术,该篇文章将开始围绕图像分割进行讲解。图像分割就是把图像分成若干个特定的、具有独特性质的区域并提出感兴趣目标的技术和过程。 本篇文章主要讲解基于理论的图像分割方法,通过K-Means聚类算法实现图像分割或颜色分层处理。基础性文章,希望对你有所帮助。 1.K-Means原理 2.K-Means聚类分割灰度图像 3.K-Means聚类对比分割彩色图像
hibernate 中的dialect设置(转载)
[table] |RDBMS ||方言 | |DB2||org.hibernate.dialect.DB2Dialect| |DB2 AS/400||org.hibernate.dialect.DB2400Dialect| |DB2 OS390||org.hibernate.dialect.DB2390Dialect| |Pos...
【Matlab】如何使用Simulink进行电池建模和SOC预估
“通过Simulink电池建模进行SOC预估,其实挺容易!” 1 声明 本文只描述一般性电池建模方法,文中出现的电池相关数据来自一些论文或者外文文献,对数据的真实性不做任何保证。 本文参考了不少国内高校的硕士论文和外文文献,所以本篇文章只作为学术性交流,未经...
SpringBoot从数据库加载配置信息
版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.youkuaiyun.com/asing1elife/article/details/82811803 Spring Boot 通过@Va...
计算机控制技术及应用
《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。
ET2012新版免狗免安装绿色软件
ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,
自己实现ORM
这篇文章源自刚开发的一个小项目。项目中并未使用hibernate,但我还是要把它放在hibernate栏下。理由很简单,技术是死的,而人是活的,能熟练的使用一项技术不算什么,但能恰当的选择相应的技术,甚至自己想出办法来优雅的解决实际问题,就需要一定的积累了。而这种积累就来源自项目实践和对各种技术其实质的理解。我记得在某个论坛上某人(名字忘了)说过一句话:如果学习hibernate只是学会了怎么ma...
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
Spring与Hibernate动态建表及动态加载映射文件(无需SessionFactory Rebuild)
Spring与Hibernate动态建表及动态加载映射文件(无需SessionFactory Rebuild) 博客分类: Hibernate HibernateSpringDAOXMLEclipse Spring与Hibernate动态建表及动态加载映射文件(无需SessionFactory Rebuild) J.Office2有一功能是工作流支持动态表单设计,设计后可以
Hibernate 动态条件查询
Hibernate 条件动态查询 Hibernate 是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装。提供了高效的程序与数据库之间的交互接口。从产品特性上看,Hibernate 是一个全自动的 orm 框架,这意味着无须用户再手动编写 SQL 语句,只需要通过 Hibernate 就可以自动生成 SQL 语句。这从使用的角度上来看是非常方便的。除此之外,Hibernate 还做到了对数据库层的抽象,使得程序能够做到在切换数据库(如从 Oracle 切换到 MySQL )时完全无感
hibernate动态表名映射
最近用Hibernate做一个项目的时候遇到这么一个问题: 用一个配置文件,一个类去映射多个表,(每个表的结构相同)。按照平时的做法,有多少个表就要 写多少个配置文件,岂不是很麻烦。怎样才能只写一个配置文件就能达到上述目的呢? 经过研究,发现Hibernate中的NamingStrategy可以达到这个目的。它是用来定义表名和列名映射规 则的一个接口。我们要通过实现这个
hibernate之动态生成SQL
hibernate之动态生成SQL
hibernate 动态更新
dynamic-update (optional - defaults to false): specifies that UPDATE SQL should be generated at runtime and can contain only those columns whose values have changed. Take into account that dynami
hibernate实现动态表名
起因: mysql数据库中生成的表有的名字是大写,有的是小写,有的和类名相同,有的后面加了日期,也就是所谓的动态表名,每月都会自动产生一个新的表。 环境: mysql5.5+hibernate3 分析: 当然我是菜鸟,直接不知道原因,通过对比发现了原因。需要解决的问题其实有以下几个: 类怎么和表名对应 表名大小写怎么产生的 如何产生动态的表名 解决: 第一个问题类怎么和表名对应
Spring+Hibernate动态切换数据源以及失败解决方案
前言 本来只是动态数据源切换的话,是不准备记录下来当博客发表的。但是在使用Spring + Hibernate实现数据源切换时,遇到了切换失败的问题。无论是查看源码还是debug调试都解决不了,最后还是在网上找到了答案,这里留一个悬念。 所以本文主旨在查阅大量资料后解决动态切换数据源失败的问题,顺便在前面介绍如何进行配置动态切换数据源。所有场景以Spring 4.2.6 + Hibern
HIBERNATE动态更换表名
HIBERNATE动态更换表名 public class ReportDBApi { private SessionFactory sessionFactory = null; public ReportDBApi(){ createSession(); } public void createSession(){ Date date = new Da...
Hibernate之DetachedCriteria动态条件查询
在hibernate中要实现动态查询或者子查询等可以用DetachedCriteria来动态构造sql语句比如要实现类似这样一个sql语句:select * from Table1 t1 where t1.field1 in(select field2 from Table2 t2 where t2.field3=value)实现方法:Session session = HibernateS
Hibernate动态查询
结合freemarker 实现hibernate动态查询
hibernate中的实体名以及动态实体dynamic models
对于POJO实体类来说,类的全限定名就是实体类的名称。我们可以不用写实体类,而是使用Map来替代,Map比实体类具有更大的灵活性。在实体映射文件中,通过<class>元素的entity-name属性来设置实体名称。
利用hibernate的动态模型进行多表查询
实验条件:实验所用的数据库软件为Mysql,数据库store包含user( userID int, userName varchar(45), phone varchar(45))和goods(goodsID int, goodsName varchar(45), userID int)两个表。 实验目的:利用hibernate的动态模型进行多表查询。 项目的结构如下:
2001



被折叠的 条评论
为什么被折叠?



