当前位置:网站首页>ORM同时使用不同数据源和不同命名转换
ORM同时使用不同数据源和不同命名转换
2022-07-26 21:25:00 【abckingaa】
同时使用不同数据源和不同命名转换实例.
比如:mysql使用: DB<-->Java,eg: order_no<-->orderNo.
oracle使用:DB<-->Java,eg: ORDER_NO<-->orderNo.
可参考该实例
但是建议只使用一种命名规则。 Javabean根据DB使用Bee自动生成
/*
* Copyright 2016-2022 the original author.All rights reserved.
* Kingstar([email protected])
* The license,see the LICENSE file.
*/
package org.teasoft.exam.bee.osql.ds;
import org.teasoft.bee.osql.SuidRich;
import org.teasoft.exam.bee.osql.entity.Orders;
import org.teasoft.honey.osql.core.HoneyConfig;
import org.teasoft.honey.osql.core.HoneyContext;
import org.teasoft.honey.osql.name.UnderScoreAndCamelName;
import org.teasoft.honey.osql.shortcut.BF;
/**
* 同时使用不同数据源和不同命名转换实例.
* <br>比如:mysql使用: DB<-->Java,eg: order_no<-->orderNo.
* <br>oracle使用:DB<-->Java,eg: ORDER_NO<-->orderNo.
* <br>可参考该实例
* <br> 但是建议只使用一种命名规则。 Javabean根据DB使用Bee自动生成
*
* @author Kingstar
* @since 1.11
*/
public class TwoDiffDsAndName {
static {
InitDsUtil.initDS();
}
public static void main(String[] args) {
HoneyConfig.getHoneyConfig().multiDS_enable = true; //使用多数据源 多个数据源时必须设置
HoneyConfig.getHoneyConfig().multiDS_differentDbType=true; //同时要使用多种数据库,一定要设置
HoneyContext.setConfigRefresh(true);
//当操作mysql时
SuidRich mysqlSuidRich=getMysqlSuidRich();
// mysqlSuidRich.select(new Orders());
mysqlSuidRich.select(new Orders(),2);
//当操作sqlite时
SuidRich sqliteSuidRich=getSqliteSuidRich();
// sqliteSuidRich.select(new Orders());
sqliteSuidRich.select(new Orders(),2);
//mysql
mysqlSuidRich.select(new Orders(),2);
}
public static SuidRich getMysqlSuidRich() {
SuidRich mysqlSuidRich=BF.getSuidRich();
// 数据源可以使用Java方式配置,也可以使用xml方式配置
// mysqlSuidRich.setDataSourceName("mysqlDsName");
mysqlSuidRich.setDataSourceName("ds1"); //此实例是在InitDsUtil.initDS();用java设置方式
mysqlSuidRich.setNameTranslate(new UnderScoreAndCamelName()); //DB<-->Java,eg: order_no<-->orderNo.
return mysqlSuidRich;
}
public static SuidRich getSqliteSuidRich() {
SuidRich sqliteSuidRich=BF.getSuidRich();
// 数据源可以使用Java方式配置,也可以使用xml方式配置
// sqliteSuidRich.setDataSourceName("sqliteDsName");
sqliteSuidRich.setDataSourceName("ds2"); //此实例是在InitDsUtil.initDS();用java设置方式
//TODO 像Oracle使用的规则,与其它不一样,可以这样使用.
// sqliteSuidRich.setNameTranslate(new UpperCaseUnderScoreAndCamelName()); //DB<-->Java,eg: ORDER_NO<-->orderNo.
return sqliteSuidRich;
}
}
边栏推荐
- Matlab pitch period estimation post-processing
- unity 获取网络时间
- imshow()函数后面如果不加waitKey()函数就不显示
- js验证复杂密码
- Leetcode exercise - Sword finger offer II 005. maximum product of word length
- Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
- My SQL is OK. Why is it still so slow? MySQL locking rules
- SQL注入 Less24(二次注入)
- 我的sql没问题为什么还是这么慢|MySQL加锁规则
- Highlight the secondary and tertiary columns under the primary column of pbootcms
猜你喜欢
随机推荐
软件测试技术之跨平台的移动端UI自动化测试(下)
Technology sharing | do you know the functions of the server interface automated testing and requests library?
Jd.com: how does redis realize inventory deduction? How to prevent goods from being oversold?
仅需一个依赖给Swagger换上新皮肤,既简单又炫酷
Flink 在讯飞 AI 营销业务的实时数据分析实践
matlab 短时自相关实现
Pytoch -- used by visdom
C# 数据类型_摘自菜鸟教程
国信证券手机开户收费吗?开户安全吗?
Kalibr calibration realsensed435i -- multi camera calibration
Li Kou daily question - day 43 -168. Name of Excel table column
imshow()函数后面如果不加waitKey()函数就不显示
Altium designer 22 modify the layer properties of the selected component
In depth analysis of the source code, why is the string class immutable? (hit me before you understand)
新兴市场潜力无限,ADVANCE.AI风控产品助中国出海企业筑牢安全发展基础
Thorough load balancing
Understanding and practice of the trend of Bank of London foreign exchange
Cmake compiling obs-studio-27.2.0
Try new functions | decrypt Doris complex data type array
Database notes (from Lao She)








