diff --git a/AiTea-meaning.png b/AiTea-meaning.png new file mode 100644 index 0000000000000000000000000000000000000000..a380b79aa537b8afb924b0fcd17ce57ed2d96bc6 Binary files /dev/null and b/AiTea-meaning.png differ diff --git a/Bee-architecture.png b/Bee-architecture.png new file mode 100644 index 0000000000000000000000000000000000000000..b985af0e0afb8793f311e4f31ea18f7195196d81 Binary files /dev/null and b/Bee-architecture.png differ diff --git a/Changed_Log.md b/Changed_Log.md index 48e30c352adc516d9fdc79c9157cd9238bb41113..61704cf358760a492ef56f5c93cf68f8d01ce217 100644 --- a/Changed_Log.md +++ b/Changed_Log.md @@ -223,4 +223,53 @@ fixed: update is default by id,but no id field or id is null,will have exception fixed: cache bug. fixed: about getRangeId(int sizeOfIds) of GenId. fixed: in jdk 11,LoggerFactory use log4j2,have exception. -when entity is view(not table), recommend put in bee.osql.cache.never(bee.properties). \ No newline at end of file +when entity is view(not table), recommend put in bee.osql.cache.never(bee.properties). + +**V1.9.8**(2021 Mid-Autumn Day) +SuidRich add 4 method: +public int save(T entity); +public int update(T oldEntity,T newEntity); +public String selectJson(T entity, String selectField); +public String selectJson(T entity, String selectField, int start, int size); + +MoreTable(more table select): +support List type field for more tables join; +support two sub tables join(inner join,right join, left join); +support one sub table have another join sub table; +if all fields is null, the sub table field will set null; +annotation JoinTable add method:subClass() for List type field +Condition add method: +public Condition opOn(String field, Op Op, Object value); + +MapSuid(the Javabean corresponding to the table is not required): +add method update,count,paging select, add and adjust insert and insertAndReturnId. +add method putNew(String fieldName, Object newValue),putNew(Map map),put(Map map),support page in MapSql. +add method count(MapSql mapSql),update(MapSql mapSql),insertAndReturnId(MapSql mapSql),support page in MapSuid. +add method putNew(String fieldName, Object newValue),putNew(Map map),put(Map map),support page in MapSqlImpl. +add method toUpdateSqlByMap ,toCountSqlByMap ,support page in MapSqlProcessor. +add method count(MapSql mapSql),update(MapSql mapSql),support page in MapSuidImpl. +MapSuidImpl change two different method:insert(MapSql mapSql) & insertAndReturnId(MapSql mapSql) + +PreparedSqlLib support selectMapList method. +Read/Write multi-DataSource support different type DataSource. +Logger: two method support have parameter Throwable. +sql log support config the log level. +add class StreamUtil +ObjectUtils add one method: isTrue(Boolean b) +enhance check field +use LinkedHashMap in List<Map> result for selectMapList(String sql). +Condition support condition.set("fieldName", null). +selectJson support config long to string +enhance autoGenBean ,support to generate SQL Json Script. +Add general search function support (simplify back-end complex query programming). +enhance multi-thread support. +custom the path of bee.properties. +Generate Javabean(GenBean) support type:JSON,TEXT. + +fix bug for ExecutableSql. +transfer the the field of 'order by'. +fix null bug in create() of ObjectCreatorFactory. +fix bug for max column number(excel in bee-ext). +fix bug about HoneyContext +fix bug about checkPackageByClass +fix bug about multi-thread safe in ConditionHelper. \ No newline at end of file diff --git a/Changed_Log_CN.md b/Changed_Log_CN.md index bd2ce5c0b7305bf46a2ab62341f915e20971be35..afdb8f1d000cbeecbc06438fb789e7e528053e7e 100644 --- a/Changed_Log_CN.md +++ b/Changed_Log_CN.md @@ -45,7 +45,7 @@ Procedure存储过程支持(CallableStatement.executeQuery). 增加: selectJson add config:ignoreNull;date,time,timestamp Wit hMillisecond format 增加: List select(String sql), add config:nullToEmptyString 完善查询结果缓存机制(一级缓存可**对用户编程透明**,也可进行细粒度配置调优控制) -**一级缓存**即可支持: **不缓存列表,永久缓存列表,永久缓存且可更新列表**,结果集超过一定大小可不放缓存 等细粒度配置调优控制. +**一级缓存**即可支持: **不缓存列表,永久缓存列表,可更新的长久缓存列表**,结果集超过一定大小可不放缓存 等细粒度配置调优控制. 增加: SysValue注解 **V1.5** @@ -212,4 +212,53 @@ MapSuid,无需Javabean,用map承载需要转换的实体信息,操作数据 修复缺陷:jdk 11下,LoggerFactory在配置log4j2时,报错. 强烈建议:使用视图时,声明视图不放缓存(因会产生脏数据). +**V1.9.8**(2021中秋节) +SuidRich增加4个方法: +public int save(T entity); +public int update(T oldEntity,T newEntity); +public String selectJson(T entity, String selectField); +public String selectJson(T entity, String selectField, int start, int size); + +MoreTable(多表查询): +支持子表实体字段为List类型的多表关联查询. +支持两个子表的join关联查询(inner join,right join, left join); +支持一个子表里还有一个子表的关联查询. +修复问题:当一个子表的属性都为null时,子表字段直接设置为null. +注解 JoinTable添加方法:subClass()用于List类型字段的多表关联查询. +Condition新增方法,用于在关联查询时的on表达式达到提前过滤数据: +public Condition opOn(String field, Op Op, Object value); + +MapSuid(不用Javabean实体结构操作数据库): +新增update,count,查询分页,新增和调整insert and insertAndReturnId. +add method putNew(String fieldName, Object newValue),putNew(Map map),put(Map map),support page in MapSql. +add method count(MapSql mapSql),update(MapSql mapSql),insertAndReturnId(MapSql mapSql),support page in MapSuid. +add method putNew(String fieldName, Object newValue),putNew(Map map),put(Map map),support page in MapSqlImpl. +add method toUpdateSqlByMap ,toCountSqlByMap ,support page in MapSqlProcessor. +add method count(MapSql mapSql),update(MapSql mapSql),support page in MapSuidImpl. +MapSuidImpl change two different method:insert(MapSql mapSql) & insertAndReturnId(MapSql mapSql) + +PreparedSqlLib新增selectMapList方法. +多数据源读写模式,支持不同类型数据源,方便数据库间转移数据. +Logger: 两个方法支持有Throwable参数. +sql输出日志支持logger不同级别输出设置. +增加流的工具类StreamUtil. +ObjectUtils增加一个方法: isTrue(Boolean b) +增强检测字段合法性,包括MapSuid使用的字段. +use LinkedHashMap in List<Map> result for selectMapList(String sql). +Condition支持condition.set("fieldName", null). +selectJson支持通过配置将long转为string +增强autoGenBean ,支持生成Json格式的SQL脚本(SQL Json Script). +添加通用查询功能支持(简化后端复杂查询编程). +增强多线程支持. +可指定bee.properties所在路径. +自动生成Javabean(GenBean)支持类型:JSON,TEXT. + +fix bug for ExecutableSql. +transfer the the field of 'order by'. +fix null bug in create() of ObjectCreatorFactory. +fix bug for max column number(excel in bee-ext). +fix bug about HoneyContext. +fix bug about checkPackageByClass. +fix bug about multi-thread safe in ConditionHelper. + \ No newline at end of file diff --git a/FAQ_CN-before1.9.8.md b/FAQ_CN-before1.9.8.md new file mode 100644 index 0000000000000000000000000000000000000000..caa1030652b55dafbb01d6ba12db5924ed32309b --- /dev/null +++ b/FAQ_CN-before1.9.8.md @@ -0,0 +1,390 @@ +常见问题收集: + +1. + +Q: Bee支持几种数据库? + +A: MySQL,MariaDB,Oracle,SQL Server,H2,SQLite,PostgreSQL等等都是支持的,只要该DB支持JDBC,Bee就可以轻松支持它! + +2. + +Q: 表与实体Javabean可以自动映射吗? + +A: Bee采用约定优于配置的方式,默认实现有三种方式, 且支持自定义映射规则扩展. +在bee.properties作相关配置即可切换默认实现方式. + +```properties +#since 1.7.2 +#default implement translate type. 1 : order_no<-->orderNo(DB<-->Java), 2: ORDER_NO<-->orderNo(DB<-->Java), 3: original +#if want to use other naming rule, you can define a new class implements NameTranslate +#default value is :1 +bee.osql.naming.translateType=1 +``` +一般情况下,字段命名转换,MySQL设置为1, Oracle设置为2. + +3. + +Q: Bee支持读写分离,支持多数据源吗? + +A: V1.8支持读写分离一主多从, 仅分库等多数据源模式。 +分布式环境下生成连续单调递增(在一个workerid内),全局唯一数字id。 + +4. + + +Q: 在一个DB中,随着数据量不断增长,需要将老的数据移到历史表中. 如,订单表orders,将5月,6月数据移到 orders\_202005,orders\_202006,结构与表orders一样。 如何用同一Javabean,同时映射多个数据表? + +A: V1.8支持同库分表,动态表名映射.  + +参考: [https://gitee.com/automvc/bee/issues/I1P8YH](https://gitee.com/automvc/bee/issues/I1P8YH)  + +或: [https://github.com/automvc/bee/issues/18](https://github.com/automvc/bee/issues/18) + +5. + +Q: Bee有说明文档吗?有测试用例吗?这么好用的orm竟然没文档??!!! + +A: 请参考Bee源码网站wiki,或: JavaWeb开发的利器 系统文章,请关注微信公众号: 软件设计活跃区. 测试用例,请查看:[https://gitee.com/automvc/bee-exam](https://gitee.com/automvc/bee-exam) + +6. + + +Q: 请教下bee的多对多映射是类似mybatis那种可以全部查出来然后映射,还是hibernate那种多次查询? + +A: bee更接近原生SQL,可用原生语句分页,不需要全部查出来,也不需要查多次 wiki相关文档: (四): 分页、查询部分字段原来如此简单 (六): 多表查询(面向对象方式) + +7. + + +Q: Bee怎么具有AI特性? + +A: 通过从手工写sql语句直接用JDBC操作数据库,到简单的DB工具类, 再到像Hibernate的旧版本通过操作对象将操作DB封闭到Dao; 再到后来写dao都觉得累赘,通用操作只写个空接口。 ORM工具的发展,就是一步一提炼,简化操作的历史。 假如用AI学习,演变,那写空接口都会觉得是多余的, 每个数据库表不就是表名,以及包含一些列而矣吗??!!! 为什么不能用同样的方式去处理呢??!!! 而且dao层可以直接去掉放到ORM框架统一处理。 为了实现这些目标,就有了Bee框架。 原来编码复杂度是O(n)的,现在变成是O(1),无论多少个表,你都可以不用另外再写dao代码。 可以用时间复杂度和空间复杂度体会下编码复杂度这种变化。 + +8. + + +Q: 分布式ORM正在解决的问题之一: 能不能找到一种,既不依赖DB,也不依赖时间的ID生成算法呢? DB表自增ID真的不能用在分布式场景吗? + +A: 都是可以的.参考Bee的org.teasoft.bee.distribution.GenId接口的三种实现. + +9. + + +Q: 与传统ORM工具的比较? + +A: Hibernate的概念太复杂,学习成本高,更新会先查询再更新,n+1问题。Mybatis即使进行单表的Suid操作也需要人工写sql或生成sql文件,需要维护的sql太多。 更多比较,参考: [https://blog.csdn.net/abckingaa/article/details/84557336](https://blog.csdn.net/abckingaa/article/details/84557336) + +10. + + +Q: Bee如何提高Java web软件开发效率? + +A: 除了可以不需要写dao代码外(编码复杂度为O(1)),还提供了表对应的实体Javabean自动生成工具, 根据模板自动生成Java web前后端代码;人性化的SQL日志,可输出直接运行的sql语句(有占位符的SQL不能直接运行,不方便调试). +bee-exam工程,org.teasoft.exam.bee.osql.autogen包下: +GenBeanExam.java javabean生成实例 +GenFilesExam.java SpringMVC Rest Controller生成实例 + +11. + + +Q: Bee支持缓存吗? 如何设置缓存? + +A: 支持。还可以像调优JVM一样,对一级缓存进行调优。有暂时缓存,也有永久缓存,还有可以同步更新的永久缓存。 + +```properties +#cache=======================start +#缓存类型 +#bee.osql.cache.type=FIFO +#缓存集数据量数目 +bee.osql.cache.mapSize=10 +#resultset超过一定的值将不会放缓存 +bee.osql.cache.workResultSetSize=300 +#缓存保存时间(毫秒 ms) +bee.osql.cache.timeout=3000 +#检测到超时,超过这个使用比例则顺便起线程清除缓存 +bee.osql.cache.startDeleteRate=0.6 +#缓存容量使用率;添加缓存,检测达到该使用率则清除一定比例缓存 +bee.osql.cache.fullUsedRate=0.8 +#添加缓存,检测到缓存容量快满时,删除缓存数的比例 +bee.osql.cache.fullClearRate=0.2 + +#仅分库时(bee.dosql.multiDS.type=2),可用格式: dsName.tableName +#use table name, not entity name +#不缓存表的列表, 表名不区分大小写.视图强烈建议不放缓存,因会产生脏数据. +#bee.osql.cache.never=user +#永久缓存表的列表, 表名不区分大小写 +#bee.osql.cache.forever=constant +#只有更改时才会清除缓存,以便同步新的值到缓存. 表名不区分大小写 +#bee.osql.cache.modifySyn=para + +# since v1.7.2. default value is: false (use cache) +#bee.osql.cache.nocache=false + +#since 1.8.99 +bee.osql.cache.keyUseMD5=true +#cache=======================end + +``` + +12. + + +Q: Bee设计原理? + +A: 参考wiki或公众号相关文章: (十一):如何设计ORM架构及Bee源码分析 (十二):为什么需要一个新的ORM框架 + +13.Q: Bee查询自己怎么写筛选条件呢?像筛选状态大于2的 + +A: 写法类似: Condition condition=new ConditionImpl(); condition .op("status", Op.gt, 2) // 会转化到SQL中的where status>2 详情参考wiki: (五): 复杂查询(面向对象方式) (十三):update高级用法说明 + **更新的字段是在原来的基础上变化** +如某类商品提价2元,可以有如下写法。 +set price=price+2 + **这样写的好处,可以不需要查询出原来的价格,减少IO开销。** +Bee的面向对象写法: +condition.setAdd("price", 2); +suidRich.update(entity,condition); + +若字段p每次增加的值由字段step配置,则写为: +condition.setAdd("p", "step"); +会转化为: set p=p+step + +14.Q: Bee与Honey是什么关系? + +A: ORM Bee框架是采用接口与实现分离的设计方式.Bee是接口,而Honey则是Bee的实现. + +15. + +Q: Bee非常易用,编写代码少,但使用是一方面, 它的性能如何? + +A: 性能绝对是过得去的.README给出了详细的表格比较数据.  详细比较还开启了一个项目,欢迎PK。 +https://gitee.com/automvc/orm-compare + +16. + +Q: Bee适合手机开发领域吗? + +A: Bee文件小。bee V1.8 jar files 仅217k. 而且性能也接近JDBC的性能.还专门对H2,SQLite作了优化. + +17. + + +Q: 如何自动填日期字段? + +A: Bee默认不解析是null或空的字段; +当Javabean的日期是null时,Bee不会解析. 像mysql可以在DB端自动触发填充日期值。 + +18. + +Q: Bee对Excel导入有什么支持? 有简化操作吗? + +A: 轻松用ORM Bee实现将Excel的数据转成List,并导入到数据库。 +读取最简单的就一行代码: List list = ExcelReader.readExcel("D:\\test-dataType.xlsx"); +参考bee-exam项目里: +ExcelReaderTest.java +ImportExcelTest.java +八行代码搞定将excel数据导入到DB +https://blog.csdn.net/abckingaa/article/details/113603130 +或: +https://my.oschina.net/u/4111850/blog/4944468 + +19. + +Q: 没有与表对应的实体Javabean,如何操作数据? +A: 用map进行转换实体信息,查询/删除数据库中的数据. +参考bee-exam项目里: +MapSuidExam +```java + MapSuid mapSuid = BeeFactoryHelper.getMapSuid(); + MapSql mapSql = BeeFactoryHelper.getMapSql(); + + mapSql.put(MapSqlKey.Table, "test_user"); +// mapSql.put(MapSqlKey.Table, "testUser"); + mapSql.put(MapSqlKey.SelectColumns, "name,password"); + mapSql.put(MapSqlKey.OrderBy, "name"); + + mapSql.put(MapSqlSetting.IsNamingTransfer, true); +// mapSql.put(MapSqlSetting.IsIncludeEmptyString, true); + mapSql.put(MapSqlSetting.IsIncludeNull, true); + + mapSql.put("name", "Bee"); + mapSql.put("email", ""); //emptyString + mapSql.put("lastName", null); +// mapSql.put("last_name", null); + + String json = mapSuid.selectJson(mapSql); + Logger.info(json); +// mapSuid.selectJson(mapSql); //test cache + + mapSuid.select(mapSql); + mapSuid.select(mapSql); + + Map map = mapSuid.selectOne(mapSql); + if (ObjectUtils.isNotEmpty(map)) { + Logger.info(map.get("name").toString()); + Logger.info(map.get("password").toString()); + } + mapSuid.selectOne(mapSql); +``` + +20. + +Q:表对应的实体Javabean有些字段不想解析,如何实现? +A: +Ignore注解,忽略Javabean字段,不进行转换. +但这种应尽量少用. 纯的Javabean,当DB有变动时,很容易就可以更改了,自动生成纯Javabean更方便,安全. +Bee默认是不处理为null或空字符的字段的,因此,操作DB前将其置空即可. + +21. +How to use ORM Bee develop when the sql like: select examno, subject,max(score) ,avg(score) ,min(score) from scores? +Detail see wiki: +More SQL Function, more Group by + +```java + Condition condition=new ConditionImpl(); + + condition + .selectField("classno,term,examno,subject") + .selectFun(FunctionType.MAX, "score","maxScore") + .selectFun(FunctionType.AVG, "score","avgScore") + .selectFun(FunctionType.MIN, "score","minScore"); + + condition.op("status", Op.nq, "FIN"); + + condition + .groupBy("term,examno,subjectno,subject") + .orderBy("classno,term,examno,subjectno") + ; + + Scores scores=new Scores(); + String r=suidRich.selectJson(scores, condition); // json result + System.out.println(r); + + List listString=suidRich.selectString(scores, condition); // string array result + String str[]; + for (int i = 0; i < listString.size(); i++) { + str=listString.get(i); + for (int j = 0; j < str.length; j++) { + System.out.print(str[j]+" "); + } + System.out.println(); + } +``` + +22. + +Q: Bee为什么没有findAll(),deleteAll()方法? +A: 在一个系统里,几乎是不会有删除整个表的应用场景的。即使写demo样例也很少。所在Bee还特意加了一个检测开关, + 以防止误删整个表的数据。 要是软删除(只标记一个字段状态表示不用该数据了),那直接用update就好了。 + findAll()应用的场景也很有限,除了配置表,只存储少量记录,会查询所有数据;像用户表,订单表等是不可能查询所有数据的, + 一般都是要分页(另外,Bee的分页功能比其它工具的都好用,性能也高)。在Bee,查询所有数据,可以用: + suid.select(new ConstValue());//查询所有常量,假设表名对应的实体名为:ConstValue + + +23. + +Q: Bee为什么没有save方法? +A: 别的ORM框架,将insert与update合为一个save方法,每次操作前都要查询一次数据,看数据库是否存在该记录, + 以确定是要用insert还是update. 更新操作时,entity要设置id值,以便让查询确定该实体是否存在。 + 相当于更新操作,只能以id为where 条件,一次只能更新一条(有更新多条的需要时,这种做法效率不会高)。 + 当使用mysql数据库且JPA主键策略为@GeneratedValue(strategy = GenerationType.IDENTITY),全局更新未带version数据时, + 更新操作会变为保存操作。 + 但在很多业务场景,insert与update是明确可以区分开的,特别是在互联网应用。 + 要是用save反而会降低系统的性能。 + 如果确实有需要,可自己封装一个,参考: + + ```java + public int save(Orders orders) { + if(orders==null) return 0; + if(orders.getId()==null) return suidRich.insert(orders); + Orders one = suidRich.selectById(orders, orders.getId()); + if (one != null) + return suidRich.update(orders); + else + return suidRich.insert(orders); + } + ``` + + +24. + +Q: Bee为什么不需要写mapper,dao? +A: 这是Bee的一大优势,Bee的编码复杂度是O(1). Bee概念简单,易于使用,编码量少。 + Bee通过约定优于配置原则,通过封装,已经简化了开发. + +25. + +Q: Bee一对多查询? +A: Bee一对多查询不需要List. 呈现方式,像我们用DB客户端查询数据,结果是一个二维表. Bee是将这个二维表的每一行封装 +在一个主对象里,每个主对象会有一个从对象保存从表的数据. +详细例子可参考: + https://gitee.com/automvc/bee/wikis/(%E5%85%AD):%20%E5%A4%9A%E8%A1%A8%E6%9F%A5%E8%AF%A2(%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%96%B9%E5%BC%8F)?sort_id=2309685 + +26. + +Q: 联合主键如何查询或更新记录? +A: Bee通过约定优于配置原则,约定主键名称是id,这样可以使问题变量简单,处理的效率也更高. + 对于一些老的系统,有联合主键的,当作一般查询处理即可,即有两个字段作为主键,要用联合主键时,设置两个属性的值,框架就会负责解析(Suid的update方法,SuidRich的selectById等方法默认是id主键则不适用). + +27. + +Q: 表主键名称不是id或id类型是String类型,如何处理? +A: Suid的update方法,SuidRich的selectById等方法默认是将id为会字段用于where条件,以便确认要修改的记录. +没有id字段,则指定作为where的字段即可.如: suidRich.updateBy(noid, "uuid"); //noid为实体对象,"uuid"字段作为过滤的字段. +以下为详细例子. + + ```java + //Noid总共有以下4个字段. +// private String uuid; +// private String name; +// private Integer num; +// private String remark; + + public static void testNoId() { + Noid noid=new Noid(); + noid.setUuid("aaaaaa-no-id"); + noid.setName("test no id"); + suid.insert(noid); + + List list=suid.select(noid); + Printer.printList(list); + + noid.setUuid("aaaaaa-no-id"); + noid.setName("new name3"); +// suid.update(noid); //默认id作为where条件里的表达式,用于确定需要更新的记录 + suidRich.updateBy(noid, "uuid"); //没有id字段,则指定作为where的字段即可. + + List list2=suid.select(noid); + Printer.printList(list2); + } + ``` + +28. + +Q: 表名与实体名、字段名与属性名映射默认提供多种实现,且支持自定义映射规则扩展。 请问这个是怎么设置的,谢谢。 + How to set customized NameTranslate? +A: 实现NameTranslate接口, 并在NameTranslateHandle类设置setNameTranslat(NameTranslate nameTranslat) + +29. + +Q: 多数据源如何配置(多数据源实例)? +A: 相关用例可以查看, +https://github.com/automvc/bee-exam +或: +https://gitee.com/automvc/bee-exam +如: +https://gitee.com/automvc/bee-exam/blob/master/src/main/java/org/teasoft/exam/bee/osql/ds/RwDsExam.java +DiffDdExam.java + +若是用spring boot可参考: +https://gitee.com/automvc/bee-starter-demo + + +**其它相关资源:** + +gitee issue: [https://gitee.com/automvc/bee/issues?assignee\_id=&author\_id=&branch=&issue\_search=&label\_name=&milestone\_id=&program\_id=&scope=&sort=&state=closed](https://gitee.com/automvc/bee/issues?assignee_id=&author_id=&branch=&issue_search=&label_name=&milestone_id=&program_id=&scope=&sort=&state=closed)  + +gitee wiki: [https://gitee.com/automvc/bee/wikis](https://gitee.com/automvc/bee/wikis) + +github issue: [https://github.com/automvc/bee/issues?q=is%3Aissue+is%3Aclosed](https://github.com/automvc/bee/issues?q=is%3Aissue+is%3Aclosed)  + +github wiki: [https://github.com/automvc/bee/wiki](https://github.com/automvc/bee/wiki) \ No newline at end of file diff --git a/FAQ_CN.md b/FAQ_CN.md index fc7a11539e096b754c204abf804751ee6911e544..eae69ea97c54c08ab67a176cfae2f38727bb7c4b 100644 --- a/FAQ_CN.md +++ b/FAQ_CN.md @@ -1,4 +1,4 @@ -常见问题收集: +Bee常见疑问收集: 1. @@ -20,6 +20,7 @@ A: Bee采用约定优于配置的方式,默认实现有三种方式, 且支持 #default value is :1 bee.osql.naming.translateType=1 ``` +一般情况下,字段命名转换,MySQL设置为1, Oracle设置为2. 3. @@ -76,16 +77,20 @@ A: Hibernate的概念太复杂,学习成本高,更新会先查询再更新 10. -Q: Bee如何提高Java web软件开发效率? +Q: Bee如何提高Java web软件开发效率? +自动生成Javabean实例,自动生成Controller类实例 -A: 除了可以不需要写dao代码外(编码复杂度为O(1)),还提供了表对应的实体Javabean自动生成工具, 根据模板自动生成Java web前后端代码;人性化的SQL日志,可输出直接运行的sql语句(有占位符的SQL不能直接运行,不方便调试). +A: 除了可以不需要写dao代码外(编码复杂度为O(1)),还提供了表对应的实体Javabean自动生成工具, 根据模板自动生成Java web前后端代码;人性化的SQL日志,可输出直接运行的sql语句(有占位符的SQL不能直接运行,不方便调试). +bee-exam工程,org.teasoft.exam.bee.osql.autogen包下: +GenBeanExam.java Javabean生成实例 +GenFilesExam.java SpringMVC Rest Controller生成实例 11. -Q: Bee支持缓存吗? 如何设置缓存? +Q: Bee支持缓存吗? 如何设置缓存? -A: 支持。还可以像调优JVM一样,对一级缓存进行调优。有暂时缓存,也有永久缓存,还有可以同步更新的永久缓存。 +A: 支持。还可以像调优JVM一样,对一级缓存进行调优。有暂时缓存,也有永久缓存,还有可以同步更新的永久缓存。 ```properties #cache=======================start @@ -119,8 +124,7 @@ bee.osql.cache.fullClearRate=0.2 #since 1.8.99 bee.osql.cache.keyUseMD5=true #cache=======================end - -``` +``` 12. @@ -129,7 +133,7 @@ Q: Bee设计原理? A: 参考wiki或公众号相关文章: (十一):如何设计ORM架构及Bee源码分析 (十二):为什么需要一个新的ORM框架 -13.Q: Bee查询自己怎么写筛选条件呢?像筛选状态大于2的 +13 (1).Q: Bee查询怎么写筛选条件(不是等号=的情况)呢?像筛选状态大于2的 ? 还有 update高级用法 A: 写法类似: Condition condition=new ConditionImpl(); condition .op("status", Op.gt, 2) // 会转化到SQL中的where status>2 详情参考wiki: (五): 复杂查询(面向对象方式) (十三):update高级用法说明 **更新的字段是在原来的基础上变化** @@ -144,6 +148,24 @@ suidRich.update(entity,condition); condition.setAdd("p", "step"); 会转化为: set p=p+step +13 (2). Q: SuidRich接口,update方法,如何区分SQL的set部分和where部分? 即哪些字段会用在set设置部分,哪些字段会用在where条件过虑部分? + +A: 当更新一个实体,是根据id来唯一关联一个实体时,用Suid接口的update(T entity)方法即可,该方法以id作为where条件,其它非null,非空字段转为要更新的值. +默认转换的如改价格, set price=22; 但要是比原价提高2,set price=price+2,此时不能通过将值放在实体进行默认转换,需要借助Condition,用:condition.setAdd("price", 2); +若用id可以唯一关联一个实体,可用: +updateById(T entity,Condition condition); + * SQL UPDATE语句包括两大部分SET和WHERE,SuidRich采取指定其中一样,另一样尽量采用默认的实现方式.所以有关更新的方法分为两部分: + *
update和updateBy. + *
update方法中,String updateFields参数(若有),可以指明要更新的字段,其余字段则有可能转为SQL UPDATE语句的WHERE部分(默认过 + *
滤NULL和空字符串,可通过IncludeType显示设置). + *
updateBy方法中,String whereFields(若有),可以指明用于SQL中WHERE的字段.当指定了whereFields, 没在whereFields的字段,将默认 + *
转换为SQL UPDATE语句的SET部分(默认过滤NULL和空字符串,可通过IncludeType显示设置). + *
同一个实体的某个属性的值,若用于WHERE部分了,再用于UPDATE SET部分就没有意义(因为此时它们的值是一样的),但可以用Condition的 + *
set(String fieldName, Number num)等方法设置;Condition的方法set,setMultiply,setAdd,setWithField,是在处理WHERE字段前 + *
已完成处理的,所以不受指定的WHERE条件字段的影响. + * + *
update和updateBy方法的Condition设置的字段都会被解析,不受IncludeType的限制,也不受updateFields参数和whereFields参数的影响. + 14.Q: Bee与Honey是什么关系? A: ORM Bee框架是采用接口与实现分离的设计方式.Bee是接口,而Honey则是Bee的实现. @@ -189,6 +211,7 @@ Q: 没有与表对应的实体Javabean,如何操作数据? A: 用map进行转换实体信息,查询/删除数据库中的数据. 参考bee-exam项目里: MapSuidExam + ```java MapSuid mapSuid = BeeFactoryHelper.getMapSuid(); MapSql mapSql = BeeFactoryHelper.getMapSql(); @@ -220,8 +243,8 @@ MapSuidExam Logger.info(map.get("password").toString()); } mapSuid.selectOne(mapSql); -``` - +``` + 20. Q:表对应的实体Javabean有些字段不想解析,如何实现? @@ -272,7 +295,7 @@ Q: Bee为什么没有findAll(),deleteAll()方法? A: 在一个系统里,几乎是不会有删除整个表的应用场景的。即使写demo样例也很少。所在Bee还特意加了一个检测开关, 以防止误删整个表的数据。 要是软删除(只标记一个字段状态表示不用该数据了),那直接用update就好了。 findAll()应用的场景也很有限,除了配置表,只存储少量记录,会查询所有数据;像用户表,订单表等是不可能查询所有数据的, - 一般都是要分页(另外,Bee的分页功能比其它工具的都好用,性能也高)。在Bee,查询所有数据,可以用: + 一般都是要分页(另外,Bee的分页功能比其它工具的都好用,性能也高)。在Bee,查询所有数据,类似用法如下: suid.select(new ConstValue());//查询所有常量,假设表名对应的实体名为:ConstValue @@ -286,20 +309,9 @@ A: 别的ORM框架,将insert与update合为一个save方法,每次操作前 更新操作会变为保存操作。 但在很多业务场景,insert与update是明确可以区分开的,特别是在互联网应用。 要是用save反而会降低系统的性能。 - 如果确实有需要,可自己封装一个,参考: - - ```java - public int save(Orders orders) { - if(orders==null) return 0; - if(orders.getId()==null) return suidRich.insert(orders); - Orders one = suidRich.selectById(orders, orders.getId()); - if (one != null) - return suidRich.update(orders); - else - return suidRich.insert(orders); - } - ``` + **V1.9.8 , SuidRich有提供save方法。 + 如果可以区分开,建议明确调用insert(entity)或者update(entity),这样更加安全和高效。 24. @@ -315,6 +327,287 @@ A: Bee一对多查询不需要List. 呈现方式,像我们用DB客户端查询 详细例子可参考: https://gitee.com/automvc/bee/wikis/(%E5%85%AD):%20%E5%A4%9A%E8%A1%A8%E6%9F%A5%E8%AF%A2(%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E6%96%B9%E5%BC%8F)?sort_id=2309685 +26. + +Q: 多表关联时,一对多查询,字段类型用List? + +A: 当为了前端显示方便等原因,需要将从表数据作为主表的list属性时,可以用该功能. + V1.9.8有该功能支持,参考例子: +https://gitee.com/automvc/bee-exam/blob/master/src/main/java/org/teasoft/exam/bee/osql/ListEntityTest.java + +27. + +Q: 联合主键如何查询或更新记录? +A: Bee通过约定优于配置原则,约定主键名称是id,这样可以使问题变量简单,处理的效率也更高. + 对于一些老的系统,有联合主键的,当作一般查询处理即可,即有两个字段作为主键,要用联合主键时,设置两个属性的值,框架就会负责解析(Suid的update方法,SuidRich的selectById等方法默认是id主键则不适用). + +28. + +Q: 表主键名称不是id或id类型是String类型,如何处理? +A: Suid的update方法,SuidRich的selectById等方法默认是将id为会字段用于where条件,以便确认要修改的记录. +没有id字段,则指定作为where的字段即可.如: suidRich.updateBy(noid, "uuid"); //noid为实体对象,"uuid"字段作为过滤的字段. +以下为详细例子. + + ```java + //Noid总共有以下4个字段. +// private String uuid; +// private String name; +// private Integer num; +// private String remark; + + public static void testNoId() { + Noid noid=new Noid(); + noid.setUuid("aaaaaa-no-id"); + noid.setName("test no id"); + suid.insert(noid); + + List list=suid.select(noid); + Printer.printList(list); + + noid.setUuid("aaaaaa-no-id"); + noid.setName("new name3"); +// suid.update(noid); //默认id作为where条件里的表达式,用于确定需要更新的记录 + suidRich.updateBy(noid, "uuid"); //没有id字段,则指定作为where的字段即可. + + List list2=suid.select(noid); + Printer.printList(list2); + } + ``` + +29. + +Q: 表名与实体名、字段名与属性名映射默认提供多种实现,且支持自定义映射规则扩展。 请问这个是怎么设置的,谢谢。 + How to set customized NameTranslate? +A: 实现NameTranslate接口, 并在NameTranslateHandle类设置setNameTranslat(NameTranslate nameTranslat) + +30. + +Q: 多表关联时,如何在SQL on部分加表达式,过滤数据? + +A: 使用Condition接口的opOn方法. + public Condition opOn(String field, Op Op, Object value); + +31. + +Q: 请问下Bee中批量更新是怎么处理的呢 +A: update 不像insert 有批量的接口。 因为用同一条语句可以更新多条记录. +如 update table_name set field1='abc' where field2='aa' and field3='bb', +符合where条件的记录都将被更新. +这种只用一条语句就可以更新多条记录,用SuidRich接口相关的update方法就好. +要是确实要多个update,可以自己写一个循环, 然后用同一个connection连接,提交效率. +beginSameConnection(); +//多个update语句 +endSameConnection(); + +32. + +Q: 在where条件里如何使用or + +A: 例子如下: + + ```java + condition + .lParentheses() // ( + .op("classno", Op.eq, "201") + .or() + .op("classno", Op.eq, "202") + .rParentheses() // ) + ; + ``` + + 会转化成: (classno="201" or classno="202") + + +33. + +Q: Bee多表关联查询, 用List和不用List的区别 + +A: 参考:https://blog.csdn.net/abckingaa/article/details/119859192   + +@JoinTable(mainField="table_id", subField="table_id",subClass="Columns", joinType=JoinType.JOIN) + private Columns columns; +// private List list; + +//注解里subClass属性,当两个实体在同一个包,包名,是可以省略的. + + +34. + +Q: Java ORM框架Bee如何使用事务 + +A: //单笔操作,默认自动提交事务 + +多笔操作要在一次事务提交,可使用: + + ```java + try { + + Transaction transaction=SessionFactory.getTransaction(); + transaction.begin(); //事务开始 + + //......放多个操作在这 + + transaction.commit();//提交事务,事务结束 + + } catch (BeeException e) { + Logger.error(e.getMessage()); + transaction.rollback(); + } + ``` + +具体例子如下: + + ```java +Transaction transaction=SessionFactory.getTransaction(); + try { + + transaction.begin(); + + Suid suid = BeeFactory.getHoneyFactory().getSuid(); + + User user=new User(); + user.setUsername("testuser"); + user.setPassword("bee-user"); + + suid.insert(user);//insert 1 + + Orders orders = new Orders(); + orders.setUserid("bee"); + orders.setName("Bee(ORM Framework)"); + orders.setTotal(new BigDecimal("91.99")); + orders.setRemark("test transaction"); + orders.setSequence("");//empty String test + + suid.insert(orders); //insert 2 + + transaction.commit(); + + List list = suid.select(orders); //可任意组合条件查询 + for (int i = 0; i < list.size(); i++) { + Logger.info(list.get(i).toString()); + } + + } catch (BeeException e) { + // e.printStackTrace(); + Logger.error(e.getMessage()); + transaction.rollback(); + } + ``` + +35. + +Q: Java ORM框架Bee分页实例 + +A: 分页实例如下(结合springMVC): + +分页相关的,只需要传页码和一页的数据条数;返回就返回一页的数据. + + ```java + @RequestMapping("/list") + public Result list(Orderhistory orderhistory, + @RequestParam(value = "page", defaultValue = "1", required = false) int page, + @RequestParam(value = "rows", defaultValue = "20", required = false) int rows) { + Result result =new Result(); + + int total = objSQLRichService.count(orderhistory); //可以用上缓存,提交效率 + List list=objSQLRichService.select(orderhistory, (page-1)*rows, rows); + result.setRows(list); + result.setTotal(total);//返回的总数据条数,有些前端框架需要. + + return result; + } + ``` + + +36. + +Q: 生成Javabean时,遇到Bee无法支持的类型,如何处理? + +A: +private [UNKNOWN TYPE]TEXT testData; +生成Javabean时,有[UNKNOWN TYPE], 则表示遇到了没能识别的类型. +可以在相应文件里配置 +如:Oracle, +在: +jdbcTypeToFieldType-Oracle.properties +文件里,配置: +DATE=Timestamp +可以将DATE指定转换为:Timestamp +Honey工程下,预设了部分文件 +jdbcTypeToFieldType-Oracle.properties +jdbcTypeToFieldType-H2.properties +jdbcTypeToFieldType-MySQL.properties +jdbcTypeToFieldType-PostgreSQL.properties +jdbcTypeToFieldType-SQLite.properties +jdbcTypeToFieldType-MariaDB.properties +jdbcTypeToFieldType.properties +等等.. +jdbcTypeToFieldType.properties是默认的,不需要指定数据库名称. +规则是: +#jdbcTypeToFieldType-{DbName}.properties,会覆盖 +jdbcTypeToFieldType.properties相同key的值 +可以只在jdbcTypeToFieldType.properties放配置. + +37. + +Q: 想问下如果我想查询某个字段值是空的记录该怎么调用suid呢? + +A: 例如,查email为空的用户信息. + +```java + Condition condition10=BeeFactoryHelper.getCondition(); + condition10.op("email", Op.eq, null); + List list10 = suid.select(new TestUser(), condition10); + +``` + //转成的sql为: + +```sql + +select id,email,last_name,name,password,username,createtime from test_user where email is null + + ``` + + //where email is not null + 使用: condition11.op("email", Op.nq, null); + +```java +condition11.op("email", Op.nq, null); +//condition11.op("email", Op.notEqual, null); //或者用这个 + ``` + +38. + +Q: 在Maven工程,使用Bee,编程时没有提示javadoc API信息.如何设置才可以? + Bee为什么没有显示Java API信息 + +A: 因为maven只下载了jar包,没有下载源码文件. +在IDE里,下载即可. +如Eclipse里, 工程右击, Maven-->Download Sources. +可在本地maven仓库验证,是否多了一个文件:bee-1.9.8-sources.jar + +39. + +Q: PreparedSQL 是否支持多数据源? + +A: PreparedSQL的方法中带有泛型T的是支持多数据源的; 没带有泛型的,在多数据源场景,会操作默认数据源。 + + + +其它: + +Q: 多数据源如何配置(多数据源实例)? +A: 相关用例可以查看, +https://github.com/automvc/bee-exam +或: +https://gitee.com/automvc/bee-exam +如: +https://gitee.com/automvc/bee-exam/blob/master/src/main/java/org/teasoft/exam/bee/osql/ds/RwDsExam.java +DiffDdExam.java + +若是用spring boot可参考: +https://gitee.com/automvc/bee-starter-demo + **其它相关资源:** diff --git a/README.md b/README.md index 050b24b7b504b359fe7816bff6737a9f10e8598a..d79ee65881810bc98109d9a745843c6654c8099c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Bee **Bee** is an ORM framework. **Bee** is an easy and high efficiency ORM framework. **Coding Complexity is O(1),it means that Bee will do the Dao for you**. -**You don't need to write the Dao by yourself anymore**. +**You don't need to write the Dao by yourself anymore**.Help you to focus more on the development of business logic. **Good Feature:** AI, Timesaving/Tasteful, Easy, Automatic (**AiTeaSoft Style**) **Bee** see: https://github.com/automvc/bee @@ -21,7 +21,7 @@ jdk1.7+ ## Feature & Function: **Support many Database**(MySQL,MariaDB,Oracle,H2,SQLite,PostgreSQL,SQL Server and so on) and easily extend。 -**Good performance, close to the speed of JDBC; Small files:Bee V1.8 jar 217k**, **V1.9.5 jar,315k**。 +**Good performance, close to the speed of JDBC; Small files:Bee V1.8 jar 217k**, **V1.9.5 jar,315k, V1.9.8 jar 310k**。 **V1.0** Single entity(table) Suid (select,update,insert,delete) object-oriented operation. @@ -96,23 +96,7 @@ fixed null bug about:PreparedSql's method select(String sql,Object preValues[]). 4.Fix bug about checkSelectField. **V1.9** -SuidRich add new methods support list parameter in batch insert. -enhance SuidRich function, SuidRich add method: - public List selectString(T entity,Condition condition); - public int updateById(T entity,Condition condition); - public String selectWithFun(T entity, FunctionType functionType, String fieldForFun, Condition condition); - public int count(T entity); - public int count(T entity, Condition condition); - public boolean exist(T entity); //check the record whether exist in table -SuidRich adjust methods selectById for unique entity and intelligently judge the Javabean id type of string id parameter. -Suid add method insertAndReturnId. -enhance aggregate function cont,sum,avg,min,max,Condition add method: - public Condition selectFun(FunctionType functionType,String fieldForFun); - public Condition selectFun(FunctionType functionType,String fieldForFun,String alias); -Condition add method:opWithField,setWithField support like :field1=field2 -Condition add method:selectDistinctField,support distinct as select distinct(userid) from table_name -MapSuid,no need Javabean, use map to set the entity information that needs to be transformed and operate the database(select/insert/delete record). -support read Excel(*.xls,*.xlsx), converting data into List and importing them into database(bee-ext). +(just a part) more table join select support more join condition. same Connection for some ORM operation. support different type muli-Ds at same time. @@ -132,6 +116,48 @@ fixed: about getRangeId(int sizeOfIds) of GenId. fixed: in jdk 11,LoggerFactory use log4j2,have exception. when entity is view(not table), recommend put in bee.osql.cache.never(bee.properties). +**V1.9.8**(2021 Mid-Autumn Day) +SuidRich add 4 method: +public int save(T entity); +public int update(T oldEntity,T newEntity); +public String selectJson(T entity, String selectField); +public String selectJson(T entity, String selectField, int start, int size); + +MoreTable(more table select): +support List type field for more tables join; +support two sub tables join(inner join,right join, left join); +support one sub table have another join sub table; +if all fields is null, the sub table field will set null; +annotation JoinTable add method:subClass() for List type field +Condition add method: +public Condition opOn(String field, Op Op, Object value); + +MapSuid(the Javabean corresponding to the table is not required): +add method update,count,paging select, add and adjust insert and insertAndReturnId. + +PreparedSqlLib support selectMapList method. +Read/Write multi-DataSource support different type DataSource. +Logger: two method support have parameter Throwable. +sql log support config the log level. +add class StreamUtil +enhance check field +use LinkedHashMap in List<Map> result for selectMapList(String sql). +Condition support condition.set("fieldName", null). +selectJson support config long to string +enhance autoGenBean ,support to generate SQL Json Script. +Add general search function support (simplify back-end complex query programming). +enhance multi-thread support. +custom the path of bee.properties. +Generate Javabean(GenBean) support type:JSON,TEXT. + +fix bug for ExecutableSql. +transfer the the field of 'order by'. +fix null bug in create() of ObjectCreatorFactory. +fix bug for max column number(excel in bee-ext). +fix bug about HoneyContext +fix bug about checkPackageByClass +fix bug about multi-thread safe in ConditionHelper. + ## [Function Detail](../../../bee/blob/master/Changed_Log.md) [click for: Function Detail](../../../bee/blob/master/Changed_Log.md) @@ -143,6 +169,8 @@ Test Evn : Local windows. DB: MySQL (Version 5.6.24). Test point: Batch Insert;Paging Select; Transaction(update and select). + + @@ -272,18 +300,18 @@ Quick Start: org.teasoft bee - 1.9.5 + 1.9.8 org.teasoft honey - 1.9.5 + 1.9.8 org.teasoft bee-ext - 1.9.5 + 1.9.8 ``` @@ -374,6 +402,9 @@ public class SuidExamEN { #### [Bee+Spring-boot Demo](../../../bee-starter-demo/) +### Bee Common Interface + + Rapid application development: ========= **Let Java more quicker programming than php and Rails.** diff --git a/README_CN.md b/README_CN.md index 5cc3ea87ddcb8f70f6825a1b405dc157876f8ace..52f20dd2458c4e07df7ab71bc44be7f5bb7030c0 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,19 +1,22 @@ Bee ========= -#### 工欲善其事必先利其器!——《论语·卫灵公》 +#### 工欲善其事必先利其器!——《论语·卫灵公》 +#### 为适应互联网时代软件需求量大,需求变更频繁,性能要求高等要求,ORM Bee应运而生! -**Bee** 是一个简单,易用,功能强大,开发速度快,编码少的 JAVA ORM 框架。 -Bee简单易用:单表操作、多表关联操作,可以不用写sql,极少语句就可以完成SQL操作;**概念简单**,10分钟即可入门。 -Bee功能强大:复杂查询也支持向对象方式,分页查询性能更高,一级缓存即可支持个性化优化;具有分布式特性。高级要求,还可以方便自定义SQL语句。 +**Bee**,互联网新时代的Java ORM框架,更快、更简单、更自动,开发速度快,运行快,更智能! +**Bee**,一个简单,易用,功能强大(编码少、开发速度快,运行快)的 JAVA ORM 框架。 +**Bee简单易用**:单表操作、多表关联操作,可以不用写sql,极少语句就可以完成SQL操作;**概念简单**,10分钟即可入门。 +**Bee功能强大**:复杂查询也支持向对象方式,分页查询性能更高,一级缓存即可支持个性化优化;具有分布式特性。高级要求,还可以方便自定义SQL语句。运行速度接近直接用JDBC的速度。 **如果说Mybatis在Hibernate之后不是重复造轮子,那Bee在Hibernate和Mybatis之后也不会是重复造轮子!** 择其优点,避其缺点,此外,还加有自己的优点! #### 磨刀不误砍柴工! Bee连磨刀的时间都帮你省了。 -**Bee** 是一个具有人工智能(AI)特性,省时/优雅、简易、自动( **AiTea:** Timesaving/Tasteful, Easy, Automatic) 的ORM软件框架(AiTeaSoft)(IT-->AiTea 的思维转变!)。 +**Bee** 是一个具有人工智能(**AI**)特性,**省时/优雅、简易、自动**( **AiTea:** Timesaving/Tasteful, Easy, Automatic) 的ORM软件框架(AiTeaSoft)(IT-->AiTea 的思维转变!)。 + Bee是一种更接近SQL语言思维的ORM框架, 一种开发速度和开发成本都不比Php,Ruby on Rail差的Java ORM框架, -而且它的编码复杂度是O(1),即用了Bee,**无论多少个表**,你都可以不用另外再写dao代码。 +而且它的编码复杂度是O(1),即用了Bee,**无论多少个表**,你都可以不用另外再写dao代码;**让你可以更专注业务逻辑的开发**。 **Bee** 网址: https://github.com/automvc/bee @@ -26,25 +29,28 @@ jdk1.7+ ## Bee主要功能特点介绍: **Bee概念简单**(10分钟即可入门)、功能强大。 Bee **简化了与DB交互的编码**工作量.连接,事务都可以由Bee框架负责管理。 +### 省时,开发速度快 +#### 简单易用 * 1.**接口简单,使用方便**。Suid接口中对应SQL语言的select,update,insert,delete操作提供**4个同名方法**。 * 2.使用了Bee,你可以不用再另外编写dao代码,直接调用Bee的api即可完成对DB的操作。 * 3.**约定优于配置**:Javabean没有注解,也不需要xml映射文件,只是纯的Javabean即可,甚至get,set方法不用也可以。 * 4.**智能化自动过滤**null和空字符串,不再需要写判断非空的代码。 -* 5.**动态/任意组合**查询条件,不需要提前准备dao接口,有新的查询需求也不用修改或添加接口。 -* 6.支持原生SQL排序, **原生语句分页**(不需要将全部数据查出来)。 -* 7.支持**直接返回Json**格式查询结果; 链式编程。 -* 8.支持**事务**、多个ORM操作使用同一连接、**for update**,支持**批处理**操作,支持原生SQL(**自定义sql**语句),支持**存储过程**。 -* 9.支持**只查询一部分字段**。 +* 5.支持**只查询一部分字段**。 +#### 自动,功强强大 +* 6.**动态/任意组合**查询条件,不需要提前准备dao接口,有新的查询需求也不用修改或添加接口。 +* 7.支持原生SQL排序, **原生语句分页**(不需要将全部数据查出来)。 +* 8.支持**直接返回Json**格式查询结果; 链式编程。 +* 9.支持**事务**、多个ORM操作使用同一连接、**for update**,支持**批处理**操作,支持原生SQL(**自定义sql**语句),支持**存储过程**。 * 10.支持面向对象方式复杂查询、**多表查询**(无n+1问题; 支持:一对一,一对多,多对一,多对多)。 -* 11.**一级缓存**,概念简单,功能强大;一级缓存也可以**像JVM一样进行细粒度调优**;**智能缓存**,支持更新配置表,**不用重启**。 +* 11.**一级缓存**,概念简单,功能强大;一级缓存也可以**像JVM一样进行细粒度调优**;**支持可更新的长久缓存列表**,更新配置表,**不需要重启**。 * 12.表名与实体名、字段名与属性名映射默认提供多种实现,且支持**自定义映射规则扩展**。 * 13.**多种DB**支持轻松扩展(MySQL,MariaDB,Oracle,H2,SQLite,PostgreSQL,SQL Server等直接可用)。 -* 14.支持**读写分离**一主多从, 仅**分库**等**多数据源**模式(对以前的代码无需修改,该功能对代码是透明的,即无需额外编码),仅分库**可同时使用多种类型数据库**。 +* 14.支持**读写分离**一主多从, 仅**分库**等**多数据源**模式(对以前的代码无需修改,该功能对代码是透明的,即无需额外编码),**可同时使用多种类型数据库**。 * 15.**分布式**环境下生成**连续单调递增**(在一个workerid内),**全局唯一**数字**id**;提供自然简单的分布式主键生成方式。 * 16.**支持同库分表,动态表名映射**。 * 17.可以不用表对应的Javabean也能操作DB。 * 18.**无**第三方插件依赖;可零配置使用。 -* 19.**性能好:接近JDBC的速度;文件小:Bee V1.8 jar 仅217k**, **V1.9.5 jar,仅315k**。 +* 19.**性能好:接近JDBC的速度;文件小:Bee V1.8 仅217k**, **V1.9.5 仅315k,V1.9.8 仅310k**。 辅助功能: * 20.支持自动生成表对应的Javabean,根据Javabean创建表,Javaweb**后端代码**根据**模板自动生成**;能打印非占位符的**可执行sql**,方便调试。 * 21.支持**读取Excel**,从Excel导入数据到DB,操作简单。 @@ -52,41 +58,63 @@ Bee **简化了与DB交互的编码**工作量.连接,事务都可以由Bee框 ## 最新功能介绍: **V1.9** -SuidRich新增支持List参数的批量插入方法. -增强SuidRich功能, SuidRich增加方法: - public List selectString(T entity,Condition condition); - public int updateById(T entity,Condition condition); - public String selectWithFun(T entity, FunctionType functionType, String fieldForFun, Condition condition); - public int count(T entity); - public int count(T entity, Condition condition); - public boolean exist(T entity); //判断记录是否存在 -SuidRich调整selectById方法且String类型参数的id智能识别Javabean的id类型. -Suid新增insertAndReturnId方法. -加强聚合函数cont,sum,avg,min,max功能,Condition增加方法: - public Condition selectFun(FunctionType functionType,String fieldForFun); - public Condition selectFun(FunctionType functionType,String fieldForFun,String alias); -Condition 添加方法:opWithField,setWithField 支持像:field1=field2的表达式 -Condition 添加方法:selectDistinctField,支持distinct像 select distinct(userid) from table_name -MapSuid,无需Javabean,用map承载需要转换的实体信息,操作数据库(查询,插入,删除数据). -支持读取Excel(*.xls,*.xlsx),并将数据转成List,且导入到数据库(bee-ext). +(只是一部分) 多表关联查询支持多个关联条件. 多个ORM操作使用同一个Connection. 支持同时使用不同数据库(多个数据源). 支持长度大于0空字符串忽略处理,如"     ". 增加Ignore注解,忽略Javabean字段,不进行转换. 用模板生成文件支持自定义起止标签. -完善DB连接管理. 加强代码质量(测试覆盖率达70%以上,关键代码达90%以上). 增强链式编程:Select,Update. -调整bee.properties,HoneyConfig配置信息. 整合Spring boot,提供bee-spring-boot-starter. 支持利用Javabean生成表. 修复多表分页查询时,同名字段在部分数据库会混淆的缺陷(oracle). 修复缺陷:update默认主键为id时,无id字段或id为null时,异常处理. -修复缺陷:cache bug. -修复缺陷:有关GenId的 getRangeId(int sizeOfIds)方法. 修复缺陷:jdk 11下,LoggerFactory在配置log4j2时,报错. -强烈建议:使用视图时,声明视图不放缓存(因会产生脏数据). + +**V1.9.8**(2021中秋节) +SuidRich增加4个方法: +public int save(T entity); +public int update(T oldEntity,T newEntity); +public String selectJson(T entity, String selectField); +public String selectJson(T entity, String selectField, int start, int size); + +MoreTable(多表查询): +支持子表实体字段为List类型的多表关联查询. +支持两个子表的join关联查询(inner join,right join, left join); +支持一个子表里还有一个子表的关联查询. +修复问题:当一个子表的属性都为null时,子表字段直接设置为null. +注解 JoinTable添加方法:subClass()用于List类型字段的多表关联查询. +Condition新增方法,用于在关联查询时的on表达式达到提前过滤数据: +public Condition opOn(String field, Op Op, Object value); + +MapSuid(不用Javabean实体结构操作数据库): +新增update,count,查询分页,新增和调整insert and insertAndReturnId. +至此,MapSuid的select,update,insert,delete及分页功能已完备. + +PreparedSqlLib新增selectMapList方法. +多数据源读写模式,支持不同类型数据源,方便数据库间转移数据. +Logger: 两个方法支持有Throwable参数. +sql输出日志支持logger不同级别输出设置. +增加流的工具类StreamUtil. +增强检测字段合法性,包括MapSuid使用的字段. +use LinkedHashMap in List<Map> result for selectMapList(String sql). +Condition支持condition.set("fieldName", null). +selectJson支持通过配置将long转为string. +增强autoGenBean ,支持生成Json格式的SQL脚本(SQL Json Script). +添加通用查询功能支持(简化后端复杂查询编程). +增强多线程支持. +可指定bee.properties所在路径. +自动生成Javabean(GenBean)支持类型:JSON,TEXT. + +fix bug for ExecutableSql. +transfer the the field of 'order by'. +fix null bug in create() of ObjectCreatorFactory. +fix bug for max column number(excel in bee-ext). +fix bug about HoneyContext. +fix bug about checkPackageByClass. +fix bug about multi-thread safe in ConditionHelper. ## [详细完整功能介绍](../../../bee/blob/master/Changed_Log_CN.md) [点击链接可查看 详细完整功能介绍](../../../bee/blob/master/Changed_Log_CN.md) @@ -99,6 +127,8 @@ MapSuid,无需Javabean,用map承载需要转换的实体信息,操作数据 数据库: MySQL (Version 5.6.24). 测试点: 批量插入;分页查询;事务(update and select). + +
@@ -230,18 +260,18 @@ OrdersService.java org.teasoft bee - 1.9.5 + 1.9.8 org.teasoft honey - 1.9.5 + 1.9.8 org.teasoft bee-ext - 1.9.5 + 1.9.8 ``` @@ -336,6 +366,17 @@ public class SuidExam { #### [Bee+Spring-boot Demo](../../../bee-starter-demo/) +### API-DOC +[API-V1.9.5](https://gitee.com/automvc/bee/attach_files/692020/download) + +API-V1.9.8(最新版) 下载代码含有 bee-1.9.8-javadoc.zip + +### Bee架构介绍 + + +### Bee常用接口介绍 + + 综合应用: ========= **Java快速编程, 让Java的开发速度超过php和Rails。** @@ -344,6 +385,8 @@ public class SuidExam { [Bee+Spring+SpringMVC](../../../../aiteasoft/bee-spring-springmvc) **包括仅分库多数据源实例** +[Bee+Spring+SpringMVC开发学校教务管理与分数管理系统](../../../../aiteasoft/schoolsys) + **更快的开发Spring Cloud微服务的新组合:** [Bee + Spring Boot](../../../bee-springboot) diff --git a/batch-insert-compare.png b/batch-insert-compare.png new file mode 100644 index 0000000000000000000000000000000000000000..bd21b3b1a8c2e354c06f6ca80b380c34631e5f3c Binary files /dev/null and b/batch-insert-compare.png differ diff --git a/bee-1.9.8-javadoc.zip b/bee-1.9.8-javadoc.zip new file mode 100644 index 0000000000000000000000000000000000000000..0d6601dfdb3f190f5fd919913a693f3df37646c0 Binary files /dev/null and b/bee-1.9.8-javadoc.zip differ diff --git a/common-interface.jpg b/common-interface.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a92bc44fd4eb00c546b0d3433db47e11f71acedd Binary files /dev/null and b/common-interface.jpg differ diff --git a/common-interface_en.jpg b/common-interface_en.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6f34b040a82a92763306a3e5985762ae54ee4d96 Binary files /dev/null and b/common-interface_en.jpg differ diff --git a/pom.xml b/pom.xml index 2eae1f042972e85077f5a240a9d63ebe2ad6961e..fc340a7aa659ee923a1a18e5c8025acff39bb338 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0org.teasoftbee - 1.9.5 + 1.9.8jar diff --git a/src/main/java/org/teasoft/bee/file/FileCreator.java b/src/main/java/org/teasoft/bee/file/FileCreator.java index 524d0923f8520abca3e2716f6b9827dabb29222c..fe39cfd8a17a8453b52d3ba916b28cfab7711860 100644 --- a/src/main/java/org/teasoft/bee/file/FileCreator.java +++ b/src/main/java/org/teasoft/bee/file/FileCreator.java @@ -55,4 +55,12 @@ public interface FileCreator extends FileReader{ * @since 1.7.2 */ public void genAppendFile(String fullPathAndName, String content); + + /** + * set charsetName + * @param charsetName + * @since 1.8.9 + */ + public void setCharsetName(String charsetName); + } diff --git a/src/main/java/org/teasoft/bee/osql/BeeException.java b/src/main/java/org/teasoft/bee/osql/BeeException.java index 8c0bb1827de467344546d08accdf693b8a18395e..6ef5bcea368504ca241095dac67cee4317a52a1d 100644 --- a/src/main/java/org/teasoft/bee/osql/BeeException.java +++ b/src/main/java/org/teasoft/bee/osql/BeeException.java @@ -30,18 +30,63 @@ public class BeeException extends RuntimeException{ super(); } + /** Constructs a new runtime exception with the specified detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for + * later retrieval by the {@link #getMessage()} method. + */ public BeeException(String message) { super(message); } + /** + * Constructs a new runtime exception with the specified detail message and + * cause.

Note that the detail message associated with + * {@code cause} is not automatically incorporated in + * this runtime exception's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ public BeeException(String message, Throwable cause) { super(message, cause); } + /** Constructs a new runtime exception with the specified cause and a + * detail message of (cause==null ? null : cause.toString()) + * (which typically contains the class and detail message of + * cause). This constructor is useful for runtime exceptions + * that are little more than wrappers for other throwables. + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ public BeeException(Throwable cause) { super(cause); } + /** + * Constructs a new runtime exception with the specified detail + * message, cause, suppression enabled or disabled, and writable + * stack trace enabled or disabled. + * + * @param message the detail message. + * @param cause the cause. (A {@code null} value is permitted, + * and indicates that the cause is nonexistent or unknown.) + * @param enableSuppression whether or not suppression is enabled + * or disabled + * @param writableStackTrace whether or not the stack trace should + * be writable + * + */ protected BeeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/src/main/java/org/teasoft/bee/osql/Condition.java b/src/main/java/org/teasoft/bee/osql/Condition.java index 964b74fe49c646bf9d77171351bb2bc43f4c23eb..021a99295811d8134f81583e6cfe4a36a63fc9bf 100644 --- a/src/main/java/org/teasoft/bee/osql/Condition.java +++ b/src/main/java/org/teasoft/bee/osql/Condition.java @@ -64,6 +64,18 @@ public interface Condition extends ConditionAssistant { */ public Condition op(String field, Op Op, Object value); + + /** + * 表达式将对应 table1 JoinType table2 on field Op value + * eg: opOn("table2.valid",Op.eq,"1") table1 left join table2 on table1.id=table2.id and table2.valid='1' + * it is different from where part: table1 left join table2 on table1.id=table2.id where valid='1' + * @param field + * @param Op 操作符.operator. + * @param value 字段对应的值.value of the field. + * @return Condition + */ + public Condition opOn(String field, Op Op, Object value); + /** * 添加一个表达式条件.Add a expression condition. *
此方法不能用于SQL的update set. diff --git a/src/main/java/org/teasoft/bee/osql/DatabaseConst.java b/src/main/java/org/teasoft/bee/osql/DatabaseConst.java index 13c98194b3fd6d46ed08ded5d0de012d06a1cfe1..3a85b337773951f65452c2b0cd129c233de03e61 100644 --- a/src/main/java/org/teasoft/bee/osql/DatabaseConst.java +++ b/src/main/java/org/teasoft/bee/osql/DatabaseConst.java @@ -6,6 +6,8 @@ package org.teasoft.bee.osql; * @since 1.0 */ public final class DatabaseConst { + + private DatabaseConst() {} public static final String MYSQL = "MySQL"; public static final String MariaDB = "MariaDB"; diff --git a/src/main/java/org/teasoft/bee/osql/MapSql.java b/src/main/java/org/teasoft/bee/osql/MapSql.java index 666401d47b7f9166375167c55813a67d3f56961e..c1d4b863dc811a0b24563998d79ad94e2f780413 100644 --- a/src/main/java/org/teasoft/bee/osql/MapSql.java +++ b/src/main/java/org/teasoft/bee/osql/MapSql.java @@ -17,6 +17,8 @@ package org.teasoft.bee.osql; +import java.util.Map; + /** * 用Map承载SQL信息.Record SQL information with map. * @author Kingstar @@ -39,18 +41,50 @@ public interface MapSql { */ public void put(String fieldName, Object value); -// /** -// * 用于update的Set部分 -// * @param fieldName -// * @param value -// */ -// public void putNew(String fieldName, Object value); + /** + * 设置用于SQL select,delete,update中where过虑的字段信息;也可用于SQL insert,设置插入的字段及相应值 + * Set the field information used for where filtering in SQL select,delete, also can use in SQL insert. + * @param map 字段和值组成的map对象 + */ + public void put(Map map); + + /** + * 设置需要更新的字段和值,用于update的Set部分 + * Set the fields and values that need to be updated for the set part of SQL update + * @param fieldName + * @param value + * @since 1.9.8 + */ + public void putNew(String fieldName, Object value); + + /** + * 设置需要更新的字段和值,用于update SQL的Set部分 + * Set the fields and values that need to be updated for the set part of SQL update + * @param map 需要更新的字段和值组成的map对象. A map object consisting of fields and values that need to be updated + * @since 1.9.8 + */ + public void putNew(Map map); /** - * 用于Javabean与DB转换时配置信息设置 + * 设置用于过滤或处理规则的配置.Set the configuration for filtering or processing rule. * @param MapSqlSetting 设置的MapSqlSetting Key * @param value 设置的值 */ public void put(MapSqlSetting MapSqlSetting, boolean value); + + /** + * 分页查询时,设置开始页.Set the start page when paging query. + * 当用于count()时,忽略此方法 + * @param start + * @since 1.9.8 + */ + public void start(Integer start); + /** + * 分页查询时,设置一页的数据记录数量.During paging query, set the number of data records on one page. + * 当用于count()时,忽略此方法 + * @param size + * @since 1.9.8 + */ + public void size(Integer size); } diff --git a/src/main/java/org/teasoft/bee/osql/MapSqlKey.java b/src/main/java/org/teasoft/bee/osql/MapSqlKey.java index adacba255454e766cda7870c19d5bf32d152df60..54edda2a3ee40b7f38d11a22b77bbe9e5be0e5fe 100644 --- a/src/main/java/org/teasoft/bee/osql/MapSqlKey.java +++ b/src/main/java/org/teasoft/bee/osql/MapSqlKey.java @@ -30,7 +30,7 @@ public enum MapSqlKey { Table("Table"), /** - * 声明需要查询的字段.Declare the select fields. + * 声明需要查询的字段,多个用逗号隔开.Declare the select fields,if more than one,separate with comma. */ SelectColumns("SelectColumns"), @@ -49,7 +49,8 @@ public enum MapSqlKey { */ OrderBy("OrderBy") -// Start("Start"), +// , +// Start("Start"), // Size("Size"), ; diff --git a/src/main/java/org/teasoft/bee/osql/MapSuid.java b/src/main/java/org/teasoft/bee/osql/MapSuid.java index 8660bdd8ae18d8eb2a71e4c811f8db3c47a3d9b7..3d5b2b97bc6e12dd1f55a5e1580af21c82837f6d 100644 --- a/src/main/java/org/teasoft/bee/osql/MapSuid.java +++ b/src/main/java/org/teasoft/bee/osql/MapSuid.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.Map; /** - * 使用Map而非具体实体的数据库操作接口,默认不处理null和空字符串(与Suid,SuidRich风格兼容) + * 使用Map而非Javabean实体的数据库操作接口,默认不处理null和空字符串(与Suid,SuidRich风格兼容) *
Database operation interface using map instead of specific entity, *
the null and empty string are not handled by default. * Suid (select,update,insert,delete) @@ -56,19 +56,22 @@ public interface MapSuid { /** * 使用MapSql查询数据.Use MapSql to select data. - *
one map element as : field-name:value + *
one map element as : fieldName:value * @param mapSql MapSql instance * @return 包装在一个Map中的一行数据.returns a row of data wrapped in a map. */ public Map selectOne(MapSql mapSql); - + /** - * 使用MapSql查询数据.Use MapSql to select data. + * 更新记录,并返回受影响的行数.Update the record and return the number of rows affected. * @param mapSql MapSql instance - * @return 成功删除的记录数. the numbers of delete records successfully. + * MapSql的put方法用于SQL语句的where部分,putNew用于update类型SQL的set部分. + * MapSql' put method for SQL where part, putNew for update SQL 's set part. + * @return 成功更新的记录数,若失败则返回小于0的整数. the numbers of update records successfully,if fails, return integer less than 0. + * @since 1.9.8 */ - public int delete(MapSql mapSql); - + public int update(MapSql mapSql); + /** * 插入并返回记录的id值.Insert and return the id value of the record. * id值可由Bee自动生成分布式id. @@ -77,9 +80,30 @@ public interface MapSuid { *
Note: if id is generated by DB, consider whether DB supports it, *
and the corresponding JDBC driver supports returning id. * @param mapSql MapSql instance - * @return 若成功,返回插入记录的id值;若失败则返回-1. - *
If successful, return the id value of the inserted record; If fails, return -1. + * @return 若成功,返回插入记录的id值;若失败则返回小于0的数. + *
If successful, return the id value of the inserted record; if fails, return number less than 0. */ - public long insert(MapSql mapSql); - + public long insertAndReturnId(MapSql mapSql); + + /** + * 插入记录,并返回成功插入的记录数.Inserts record and returns the number of the record successfully inserted. + * @param mapSql MapSql instance + * @return 成功插入的记录数,若失败则返回小于0的整数.the numbers of insert records successfully,if fails, return integer less than 0. + */ + public int insert(MapSql mapSql); + + /** + * 使用MapSql删除记录.Use MapSql to delete record. + * @param mapSql MapSql instance + * @return 成功删除的记录数,若失败则返回小于0的整数. the numbers of delete records successfully,if fails, return integer less than 0. + */ + public int delete(MapSql mapSql); + + /** + * 统计符合条件的记录数.count the number of qualified record. + * @param mapSql MapSql instance + * @return 符合条件的记录数,若失败则返回小于0的整数.the number of qualified record,if fails, return integer less than 0. + * @since 1.9.8 + */ + public int count(MapSql mapSql); } diff --git a/src/main/java/org/teasoft/bee/osql/MoreTable.java b/src/main/java/org/teasoft/bee/osql/MoreTable.java index 6c3f0725a70e0b60c2c0e85fe3b42fa3e9dbaa13..20faec070fdd57cc66da260c1262b9163014106e 100644 --- a/src/main/java/org/teasoft/bee/osql/MoreTable.java +++ b/src/main/java/org/teasoft/bee/osql/MoreTable.java @@ -22,7 +22,7 @@ import java.util.List; /** * 多表查询.More table select. *

- * example: + * example1:

public class Orders{

private Long id; @@ -74,6 +74,52 @@ public class Orders{

}

} +

-------------------------------- +

example2: List type sub entity field + +

@Entity("Clazz") +

public class Clazz0 implements Serializable { +

+

private static final long serialVersionUID = 1591972382398L; +

+

private Integer id; +

private String classname; +

private String place; +

private String teachername; +

private String remark; +

+

@JoinTable(mainField="id", subField="classno", joinType=JoinType.LEFT_JOIN,subClass="Student") +

private List studentList=new ArrayList<>(); +

//subClass="Student", if sub Entity and main Entity in the same package, can use class name only. +

//full like, subClass="org.teasoft.exam.bee.osql.entity.Student") +

+

//... get,set method +

} +

+

public class Student implements Serializable { +

+

private static final long serialVersionUID = 1591622324231L; +

+

private Integer id; +

private Integer sid; +

private String name; +

private Integer age; +

private Boolean sex; +

private String majorid; +

private Boolean flag; +

private Integer classno; +

+

//... get,set method +

} +

+

public static void main(String[] args) { +

+

MoreTable moreTable = BeeFactoryHelper.getMoreTable(); +

Clazz0 c0=new Clazz0(); +

List list0=moreTable.select(c0); +

Printer.printList(list0); //print list +

} + * @author Kingstar * @since 1.7 */ diff --git a/src/main/java/org/teasoft/bee/osql/PreparedSql.java b/src/main/java/org/teasoft/bee/osql/PreparedSql.java index 8da849e7505631473ea6841fcd268c34f42bbd6f..af5644c849353a336449971e7eac073f04552453 100644 --- a/src/main/java/org/teasoft/bee/osql/PreparedSql.java +++ b/src/main/java/org/teasoft/bee/osql/PreparedSql.java @@ -149,6 +149,9 @@ public interface PreparedSql { /** * 用函数查询结果.Select result with function. SQL function: max,min,avg,sum,count.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sql SQL select statement * @param preValues 按下标顺序给sql的占位符设值的Object数组. * @return 返回函数统计的值.如果统计的结果集为空,除了count返回0,其它都返回空字符. @@ -158,6 +161,9 @@ public interface PreparedSql { /** * 用函数查询结果.Select result with function. SQL function: max,min,avg,sum,count.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sqlStr SQL select statement * @param map map结构的参数,通过map的key与sqlStr中变量名对应. * @return 返回函数统计的值.如果统计的结果集为空,除了count返回0,其它都返回空字符. @@ -167,6 +173,9 @@ public interface PreparedSql { /** * 查询并将每一行结果转成String数组.Select and transform every record to string array.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sql SQL select statement * @param preValues parameter values for placeholder * @return 可包含多个String数组结构的多条记录的list. list can contain more than one record with String array struct. @@ -193,6 +202,9 @@ public interface PreparedSql { /** * 查询并将每一行结果转成String数组.Select and transform every record to string array.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sqlStr SQL select statement * @param map parameter values for placeholder * @return 可包含多个String数组结构的多条记录的list. list can contain more than one record with String array struct. @@ -217,6 +229,9 @@ public interface PreparedSql { /** * 用可带问号的占位语句查询结果,并以json格式返回.Select and return json format result.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sql SQL select statement * @param preValues 占位符对应的参数数组.parameter values for placeholder * @return 返回json格式结果集.json format result . @@ -240,6 +255,9 @@ public interface PreparedSql { /** * 查询结果,并以json格式返回.Select and return json format result.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sqlStr SQL select statement * @param map 占位符对应的参数map.parameter values for placeholder * @return 返回json格式结果集.json format result . @@ -264,6 +282,9 @@ public interface PreparedSql { /** * 查询结果,并以json格式返回.Select and return json format result.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sqlStr 无参数的sql查询语句.SQL select statement * @return 返回json格式结果集.json format result . */ @@ -272,6 +293,9 @@ public interface PreparedSql { /** * 通过无参数的sql查询语句数据.Select record(s) via the sql statement. * 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * eg: select * from orders where userid=10001 * @param sql 无参数的sql查询语句.SQL select statement * @return 返回returnType类型的实体List. @@ -281,6 +305,9 @@ public interface PreparedSql { /** * 用函数查询结果.Select result with function. SQL function: max,min,avg,sum,count.

* 注意:因没有与entity关联,没有应用上缓存. Notice:can not use the cache because don't relay the entity. + *
因没有与entity关联,在多数据源情况下,只会从默认数据源中获取数据. + *
Because it is not associated with entity, in the case of multiple Datasources, + *
will be select the record from the default Datasource. * @param sql SQL select statement * @return 返回函数统计的值.如果统计的结果集为空,除了count返回0,其它都返回空字符. */ @@ -324,4 +351,22 @@ public interface PreparedSql { */ @Deprecated public int modify(String sql); + + /** + * 查询记录并返回元素为Map的List结构数据.Query records and return list structure data whose element is Map. + * @param sql SQL语句.SQL statement. + * @return List>结构的多行记录. + *
the multi-line record of List> structure. + */ + public List> selectMapList(String sql); + + /** + * 查询记录并返回元素为Map的List结构数据.Query records and return list structure data whose element is Map. + * @param sql SQL语句.SQL statement. + * @param start 开始下标(从0或1开始,eg:MySQL是0,Oracle是1). start index,min value is 0 or 1(eg:MySQL is 0,Oracle is 1). + * @param size 结果集大小 大于等于1. fetch result size (>0). + * @return List>结构的多行记录. + *
the multi-line record of List> structure. + */ + public List> selectMapList(String sql,int start,int size); } diff --git a/src/main/java/org/teasoft/bee/osql/Suid.java b/src/main/java/org/teasoft/bee/osql/Suid.java index 1f9137051eef1d550aa9c65a69db18a7ca0b3c7d..ebc8eb4e9150dd6b43a59e6d1bd1f0ae67373950 100644 --- a/src/main/java/org/teasoft/bee/osql/Suid.java +++ b/src/main/java/org/teasoft/bee/osql/Suid.java @@ -52,23 +52,30 @@ public interface Suid { * The entity corresponding to table and can not be null.
* The ID field of entity cannot be null and as filter condition.
* The not null and not empty field will update to database except ID. - * @return 成功更新的记录数.the numbers of update records successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update records successfully, if fails,return integer less than 0. * @see SuidRich#update(Object,java.lang.String) */ public int update(T entity); - /** * 根据实体对象entity插入数据.According to entity object insert record. * @param entity 与表对应的实体对象,且不能为空. table's entity(do not allow null).
* entity中非null且非空字符串将插入到数据库
* The entity corresponding to table and can not be null.
* The not null and not empty field will insert to database. - * @return 成功插入的记录数.the numbers of insert records successfully. + * @return 成功插入的记录数,若失败则返回小于0的整数.the numbers of insert records successfully, if fails,return integer less than 0. */ public int insert(T entity); - + /** + * 根据实体对象entity插入数据,并返回主键id值.According to entity object insert record and return id value. + * @param entity 与表对应的实体对象,且不能为空. table's entity(do not allow null).
+ * entity中非null且非空字符串将插入到数据库
+ * The entity corresponding to table and can not be null.
+ * The not null and not empty field will insert to database. + * @return 若成功,返回插入记录的id值;若失败则返回小于0的数. + *
If successful, return the id value of the inserted record; if fails, return number less than 0. + */ public long insertAndReturnId(T entity); /** @@ -78,7 +85,7 @@ public interface Suid { * The entity corresponding to table and can not be null.
* If the field value is not null and not empty field as filter condition,
* the operator is equal sign.eg:field=value - * @return 成功删除的记录数. the numbers of delete records successfully. + * @return 成功删除的记录数,若失败则返回小于0的整数. the numbers of delete records successfully, if fails,return integer less than 0. */ public int delete(T entity); @@ -101,7 +108,7 @@ public interface Suid { * @param condition entity默认有值的字段会转成field=value的形式,其它形式可通过condition指定.
* If the field of entity is not null or empty, it will be translate to field=value.Other can define with condition. *
若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) - * @return 成功删除的记录行数. the number of deleted record(s) successfully. + * @return 成功删除的记录行数,若失败则返回小于0的整数. the number of deleted record(s) successfully, if fails,return integer less than 0. * @since 1.7.2 */ public int delete(T entity,Condition condition); diff --git a/src/main/java/org/teasoft/bee/osql/SuidRich.java b/src/main/java/org/teasoft/bee/osql/SuidRich.java index 1a99ebac885f7cc35968b0488a6f69a68b7621d9..4325dfdc617e6ea148de9acff9ba20acc3f651e2 100644 --- a/src/main/java/org/teasoft/bee/osql/SuidRich.java +++ b/src/main/java/org/teasoft/bee/osql/SuidRich.java @@ -135,7 +135,7 @@ public interface SuidRich extends Suid { /** * 查询一个实体.Select one record. - * @param entity 实体类对象 + * @param entity 实体类对象.table's entity(do not allow null). * @return 只返回一个实体,数量不为1时返回null.return one record,if the size do not equal one, return null. */ public T selectOne(T entity); @@ -205,7 +205,7 @@ public interface SuidRich extends Suid { *
除了updateFields中声明要更新的字段,其它非空,非null的字段作为过滤条件,转成SQL的where表达式. *
For the list of fields to be updated, multiple fields are separated by commas (those fields will be updated). *
This attribute cannot be empty. By default, each field will be converted to a set expression of SQL update. - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. */ public int update(T entity,String updateFields); @@ -218,14 +218,14 @@ public interface SuidRich extends Suid { *
This attribute cannot be empty and is not affected by the includeType parameter. By default, each field will be *
converted to a set expression of SQL update. * @param includeType 空字符串与null是否作为过滤条件.whether null string and null as a filter conditions. - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. */ public int update(T entity,String updateFields,IncludeType includeType); /** * 批量插入数据.Insert records by batch type. * @param entity 与表对应的实体对象数组,且不能为空. table's entity array(do not allow null). - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. */ public int insert(T[] entity); @@ -233,7 +233,7 @@ public interface SuidRich extends Suid { * 批量插入数据.Insert records by batch type. * @param entity 与表对应的实体对象,且不能为空. table's entity array(do not allow null). * @param batchSize 批操作数量大小.batch size. - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. */ public int insert(T[] entity,int batchSize); @@ -242,7 +242,7 @@ public interface SuidRich extends Suid { *
Insert record by batch type,and can point out which field(s) don't need to insert. * @param entity 与表对应的实体对象数组,且不能为空. table's entity array(do not allow null). * @param excludeFields 声明不用插入的字段列表.fields list that don't need to insert . - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. */ public int insert(T[] entity,String excludeFields); @@ -252,14 +252,14 @@ public interface SuidRich extends Suid { * @param entity 与表对应的实体对象数组,且不能为空. table's entity array(do not allow null). * @param batchSize 批操作数量大小.batch size. * @param excludeFields 声明不用插入的字段列表.Don't insert fields list. - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. */ public int insert(T[] entity,int batchSize,String excludeFields); /** * 批量插入数据.Insert records by batch type. * @param entityList 与表对应的实体对象链表,且不能为空. table's entity list(do not allow null). - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. * @since 1.9 */ public int insert(List entityList); @@ -268,7 +268,7 @@ public interface SuidRich extends Suid { * 批量插入数据.Insert records by batch type. * @param entityList 与表对应的实体对象链表,且不能为空. table's entity list(do not allow null). * @param batchSize 批操作数量大小.batch size. - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. * @since 1.9 */ public int insert(List entityList,int batchSize); @@ -278,7 +278,7 @@ public interface SuidRich extends Suid { *
Insert record by batch type,and can point out which field(s) don't need to insert. * @param entityList 与表对应的实体对象链表,且不能为空. table's entity list(do not allow null). * @param excludeFields 声明不用插入的字段列表.fields list that don't need to insert . - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. * @since 1.9 */ public int insert(List entityList,String excludeFields); @@ -289,7 +289,7 @@ public interface SuidRich extends Suid { * @param entityList 与表对应的实体对象链表,且不能为空. table's entity list(do not allow null). * @param batchSize 批操作数量大小.batch size. * @param excludeFields 声明不用插入的字段列表.Don't insert fields list. - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数;失败时返回-1. the number of inserted record(s) successfully;if fails, return -1. * @since 1.9 */ public int insert(List entityList,int batchSize,String excludeFields); @@ -311,7 +311,7 @@ public interface SuidRich extends Suid { * @param entity 与表对应的实体对象,且不能为空;entity中id字段不能为空,作为过虑条件.id为null将引发ObjSQLException. *
table's entity(do not allow null),The id field in entity cannot be empty as a filtering condition. * @param includeType 空字符串与null是否包含设置 - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. */ public int update(T entity,IncludeType includeType); @@ -319,7 +319,7 @@ public interface SuidRich extends Suid { * 根据实体对象entity插入数据.Insert record according to entity. * @param entity 与表对应的实体对象,且不能为空.table's entity(do not allow null). * @param includeType 空字符串与null是否包含设置 - * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @return 成功插入的记录行数,若失败则返回小于0的整数. the number of inserted record(s) successfully,if fails, return integer less than 0. */ public int insert(T entity,IncludeType includeType); @@ -328,7 +328,7 @@ public interface SuidRich extends Suid { * @param entity 与表对应的实体对象,且不能为空,id为null不作为过滤条件.table's entity(do not allow null). * * @param includeType 空字符串与null是否包含设置 - * @return 成功删除的记录行数. the number of deleted record(s) successfully. + * @return 成功删除的记录行数,若失败则返回小于0的整数. the number of deleted record(s) successfully,if fails, return integer less than 0. */ public int delete(T entity,IncludeType includeType); @@ -343,47 +343,71 @@ public interface SuidRich extends Suid { public String selectJson(T entity,IncludeType includeType); /** - * 根据id查询记录.Select record by id. + * 查询实体时,只查询部分一部分字段,并返回Json字符串.Just select some fields,and return Json string. + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @param selectFields 需要查询的字段,多个用逗号隔开. select fields,if more than one,separate with comma. + * @return 包含多个实体的部分字段的Json字符串 + * @since 1.9.8 + */ + public String selectJson(T entity, String selectFields); + + /** + * 只查询部分一部分字段,且可以分页 ,并返回Json字符串 + *
Just select some fields,and can specify page information. * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @param selectFields 需要查询的字段,多个用逗号隔开. select fields,if more than one,separate with comma. + * @param start 开始下标(从0或1开始,eg:MySQL是0,Oracle是1). + *
start index,min value is 0 or 1(eg:MySQL is 0,Oracle is 1). + * @param size 结果集大小 大于等于1. fetch result size (>0). + * @return 包含多个实体的部分字段的Json字符串 + * @since 1.9.8 + */ + public String selectJson(T entity, String selectFields, int start, int size); + + /** + * 根据id查询记录.Select record by id. + * @param returnType 实体类对象,且不能为空.table's entity(do not allow null). * @param id 实体id字段的值.value of entity's id field. * @return 返回id对应的实体.return one entity which owns this id. * @since 1.9 */ - public T selectById(T entity,Integer id); + public T selectById(T returnType,Integer id); /** * 根据id查询记录.Select record by id. - * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @param returnType 实体类对象,且不能为空.table's entity(do not allow null). + *
returnType的属性值,不会被解析.The property value of returnType will not be parsed. * @param id 实体id字段的值.value of entity's id field. * @return 返回id对应的实体.return one entity which owns this id. * @since 1.9 */ - public T selectById(T entity,Long id); - + public T selectById(T returnType,Long id); /** * 根据id查询记录.Select record by id. - * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @param returnType 实体类对象,且不能为空.table's entity(do not allow null). + *
returnType的属性值,不会被解析.The property value of returnType will not be parsed. * @param id 实体id字段的值.value of entity's id field. * @return 返回id对应的实体.return one entity which owns this id. * @since 1.9 */ - public T selectById(T entity,String id); + public T selectById(T returnType,String id); /** * 根据id查询记录.Select record by id. - * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @param returnType 实体类对象,且不能为空.table's entity(do not allow null). + *
entity的属性值,不会被解析.The property value of returnType will not be parsed. * @param ids 实体id字段的值,多个用逗号隔开.values of entity's id field,if more than one,separate with comma. * @return 可包含多个实体(多条记录)的list. list which contains more than one entity. * @since 1.9 */ - public List selectByIds(T entity,String ids); + public List selectByIds(T returnType,String ids); /** * 根据id删除记录.Delete record by id. * @param c 实体类类型,且不能为空 * @param id 实体id字段的值. value of entity's id field. - * @return 成功删除的记录行数. the number of deleted record(s) successfully. + * @return 成功删除的记录行数,若失败则返回小于0的整数. the number of deleted record(s) successfully,if fails, return integer less than 0. * @since 1.4 */ public int deleteById(Class c,Integer id); @@ -392,7 +416,7 @@ public interface SuidRich extends Suid { * 根据id删除记录.Delete record by id. * @param c 实体类类型,且不能为空 * @param id 实体id字段的值. value of entity's id field. - * @return 成功删除的记录行数. the number of deleted record(s) successfully. + * @return 成功删除的记录行数,若失败则返回小于0的整数. the number of deleted record(s) successfully,if fails, return integer less than 0. * @since 1.4 */ public int deleteById(Class c,Long id); @@ -401,7 +425,7 @@ public interface SuidRich extends Suid { * 根据id删除记录.Delete record by id. * @param c 实体类类型,且不能为空 * @param ids 实体id字段的值,多个用逗号隔开.ids values of entity's id field,if more than one,separate with comma. - * @return 成功删除的记录行数. the number of deleted record(s) successfully. + * @return 成功删除的记录行数,若失败则返回小于0的整数. the number of deleted record(s) successfully,if fails, return integer less than 0. * @since 1.4 */ public int deleteById(Class c,String ids); @@ -455,7 +479,7 @@ public interface SuidRich extends Suid { * 没指定为whereFields的字段,作为set部分,默认只处理非空,非null的字段 * @param whereFields 作为SQL中where条件的字段列表,多个字段用逗号隔开(列表中有的字段都会作为条件); * 指定作为条件的,都转换.id为null不作为过滤条件 - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. * @since 1.6 */ public int updateBy(T entity,String whereFields); @@ -467,7 +491,7 @@ public interface SuidRich extends Suid { * @param whereFields 作为SQL中where条件的字段列表,多个字段用逗号隔开(列表中有的字段都会作为条件); * 指定作为条件的,都转换.id为null不作为过滤条件 * @param includeType 空字符串与null是否作为过滤条件.whether null string and null as a filter conditions. - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. * @since 1.6 */ public int updateBy(T entity,String whereFields,IncludeType includeType); @@ -482,7 +506,7 @@ public interface SuidRich extends Suid { *
Notice:the method op of condition also maybe converted to the where expression. * @param condition 用来设置默认情况不能表达的条件. * 若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. * @since 1.7.2 */ public int updateBy(T entity,String whereFields,Condition condition); @@ -494,7 +518,7 @@ public interface SuidRich extends Suid { * @param condition 用来设置默认情况不能表达的条件. * 若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) *
需要注意的是,condition用op设置的条件,也有可能转换为where部分的过滤条件. - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. * @since 1.9 */ public int updateById(T entity,Condition condition); @@ -512,7 +536,8 @@ public interface SuidRich extends Suid { *
converted to a set expression of SQL update. * @param condition * 若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * 一个字段既在指定的updateFields,也用在了Condition.set(arg1,arg2)等方法设置,entity里相应的字段会按规则转化到where部分.(V1.9.8) + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. * @since 1.7.2 */ public int update(T entity,String updateFields,Condition condition); @@ -520,16 +545,33 @@ public interface SuidRich extends Suid { /** * 更新记录,高级条件可通过Condition参数设置 Update record,and can help with Condition. *
当SQL update的set表达式通过Condition定义时,可以不用再指定set使用的字段. + *
此方法相当于调用update(T entity,String updateFields,Condition condition)方法时,将updateFields设置为"". + *
it is equivalent to update(entity,"",condition),updateFields value is "". * @param entity 实体类对象,不能为空.table's entity(do not allow null). - * entity默认有值的字段会转成field=value的形式,其它形式可通过condition指定.
- * If the field of entity is not null or empty, it will be translate to field=value.Other can define with condition.
+ * entity默认有值的字段会转成field=value的形式(转到where部分),其它形式可通过condition指定.
+ * If the field of entity is not null or empty, it will be translate to field=value in where part.Other can define with condition.
* @param condition * 若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) - * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. * @since 1.8 */ public int update(T entity,Condition condition); + /** + * 更新实体,oldEntity的非null,非空属性作为过虑条件;newEntity的非null,非空属性作为需要更新的字段对应值 + *
Update the entity. The non null and non empty attributes of oldEntity are taken as + *
the filtering conditions; The non null and non empty properties of newEntity are + *
used as the corresponding values of the properties to be updated + * 新旧实体必须是相同类型. + * Old and new entities must be of the same type. + * oldEntity转化为SQL的Where部分,newEntity改转化为Set部分. + * oldEntity is converted to Where part of SQL, and newEntity is converted to Set part. + * @param oldEntity 含有旧值属性的实体.Entity with old value field. + * @param newEntity 含有新值属性的实体.Entity with new value field. + * @return 成功更新的记录数,若失败则返回小于0的整数.the numbers of update record(s) successfully,if fails, return integer less than 0. + */ + public int update(T oldEntity,T newEntity); + /** * 为动态表名、实体名参数设置值.set dynamic parameter for dynamic table & entity name *
本方法的调用要早于select,update,insert,delete等方法. @@ -551,4 +593,15 @@ public interface SuidRich extends Suid { * @since 1.9 */ public boolean exist(T entity); + + /** + * 保存一个实体(一条记录).save one entity(one record). + * 如果可以区分开,建议明确调用insert(entity)或者update(entity),这样更加安全和高效. + * If it can be distinguished, it is recommended to explicitly call insert (entity) + *
or update (entity), which is more secure and efficient. + * @param entity + * @return 返回受影响的行数,若失败则返回小于0的整数.the numbers of effect record(s),if fails, return integer less than 0. + * @since 1.9.8 + */ + public int save(T entity); } diff --git a/src/main/java/org/teasoft/bee/osql/annotation/JoinTable.java b/src/main/java/org/teasoft/bee/osql/annotation/JoinTable.java index 682f2633dc258fc4246d976f0c16c098379986ec..96bd82020193853384cfb58ae5f905ca50e70e5b 100644 --- a/src/main/java/org/teasoft/bee/osql/annotation/JoinTable.java +++ b/src/main/java/org/teasoft/bee/osql/annotation/JoinTable.java @@ -52,5 +52,14 @@ public @interface JoinTable { * @return subtable alias. */ String subAlias() default ""; + + /** + * 从表的class类型;与主表实体在同一包下,可以只写类名.(在使用List类型的从表时才有效) + * Subtable class type, if it has same package with main table,the package name can be omitted. + * (effect when using a list type Subtable) + * @return sub Class name. + * @since 1.9.8 + */ + String subClass() default ""; } diff --git a/src/main/java/org/teasoft/bee/osql/chain/Select.java b/src/main/java/org/teasoft/bee/osql/chain/Select.java index 14190aa4862d59e11f61a07e44c33c6d4a325f57..10daf2f7c7820cfdee420f9363e6b446482687be 100644 --- a/src/main/java/org/teasoft/bee/osql/chain/Select.java +++ b/src/main/java/org/teasoft/bee/osql/chain/Select.java @@ -26,7 +26,7 @@ import org.teasoft.bee.osql.OrderType; */ public interface Select extends ToSql{ - //<==============condition + //<==============condition start /** * 添加左括号.add "(" @@ -73,7 +73,7 @@ public interface Select extends ToSql{ public Select in(String field, String valueList); public Select notIn(String field, String valueList); - //=============> + //==============condition end> public Select select() ; @@ -108,9 +108,7 @@ public interface Select extends ToSql{ public Select size(int size) ; public Select exists(Select subSelect) ; -// public Select exists(String subSelect); public Select notExists(Select subSelect); -// public Select notExists(String subSelect); public Select in(String field, Select subSelect); public Select notIn(String field, Select subSelect); diff --git a/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java b/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java index 643f511b266d59891add26b9ec9c2d09093f070a..86a7166109a79a64162662202035285e966f0da6 100644 --- a/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java +++ b/src/main/java/org/teasoft/bee/osql/chain/UnionSelect.java @@ -16,8 +16,6 @@ */ package org.teasoft.bee.osql.chain; -import org.teasoft.bee.osql.chain.Select; - /** * UnionSelect接口,用于链式风格写SQL语句.UnionSelect interface for SQL with chain programming. * @author Kingstar diff --git a/src/main/java/org/teasoft/bee/osql/exception/BeeErrorNameException.java b/src/main/java/org/teasoft/bee/osql/exception/BeeErrorNameException.java new file mode 100644 index 0000000000000000000000000000000000000000..1ba5b5c0ad80e2022d5890d4d90fd005ea3bf712 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/exception/BeeErrorNameException.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016-2021 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.teasoft.bee.osql.exception; + +import org.teasoft.bee.osql.BeeException; + +/** + * 变量名命名异常.Bee error name exception. + * @author Kingstar + * @since 1.9.8 + */ +public class BeeErrorNameException extends BeeException { + static final long serialVersionUID = -875516993124222236L; + + + public BeeErrorNameException() { + super(); + } + + public BeeErrorNameException(String message) { + super(message); + } + + public BeeErrorNameException(String message, Throwable cause) { + super(message, cause); + } + + public BeeErrorNameException(Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalParameterException.java b/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalParameterException.java index fbc8f95ab9874048468188bcea1ee982aba0a4ca..d8a0d913b4432f82a56cc8cdba7b1a74e620a442 100644 --- a/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalParameterException.java +++ b/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalParameterException.java @@ -20,7 +20,7 @@ package org.teasoft.bee.osql.exception; import org.teasoft.bee.osql.BeeException; /** - * Bee非法参数异常.Bee illegal parameter exception. + * 非法的Bee参数异常.Bee illegal parameter exception. * @author Kingstar * @since 1.5 */ diff --git a/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalSQLException.java b/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalSQLException.java new file mode 100644 index 0000000000000000000000000000000000000000..40ef6e42ea85c82716d3bdf85f2e82ab94f4b997 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/exception/BeeIllegalSQLException.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016-2021 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.teasoft.bee.osql.exception; + +import org.teasoft.bee.osql.BeeException; + +/** + * 非法的Bee SQL异常.Bee Illegal SQLException + * @author Kingstar + * @since 1.9.8 + */ +public class BeeIllegalSQLException extends BeeException { + + static final long serialVersionUID = -875516993124222232L; + + public BeeIllegalSQLException() { + super(); + } + + public BeeIllegalSQLException(String message) { + super(message); + } + + public BeeIllegalSQLException(String message, Throwable cause) { + super(message, cause); + } + + public BeeIllegalSQLException(Throwable cause) { + super(cause); + } + +} diff --git a/src/main/java/org/teasoft/bee/osql/search/Operator.java b/src/main/java/org/teasoft/bee/osql/search/Operator.java new file mode 100644 index 0000000000000000000000000000000000000000..d2078ba93e784cc5c4842557af33f582f6417748 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/search/Operator.java @@ -0,0 +1,96 @@ +/* + * Copyright 2013-2021 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.teasoft.bee.osql.search; + +/** + * 较全的操作符 + * More complete operators + * @author Kingstar + * @since 1.9.8 + */ +public enum Operator { + + /** + * eq is : = + */ + eq("="), + + /** + * gt is : > + */ + gt(">"), + + /** + * lt is : < + */ + lt("<"), + + /** + * nq is : != + */ + nq("!="), // <> + + /** + * ge is : >= + */ + ge(">="), + + /** + * le is : <= + */ + le("<="), + + like("like"), + notLike("not like"), + + in("in"), + notIn("not in"), + + between("between"), + notBetween("notBetween"), + + + //select specific + groupBy("groupBy"), + having("having"), + orderBy("orderBy"), + + //select specific + distinct("distinct"), + max("max"), + min("min"), + sum("sum"), + avg("avg"), + count("count"), + + + or("or"), + and("and") + ; + + private String operator; + + Operator(String operator){ + this.operator=operator; + } + + public String getOperator() { + return operator; + } + +} diff --git a/src/main/java/org/teasoft/bee/osql/search/Search.java b/src/main/java/org/teasoft/bee/osql/search/Search.java new file mode 100644 index 0000000000000000000000000000000000000000..99b948996a646de24d517c9668a39ff8badf964b --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/search/Search.java @@ -0,0 +1,122 @@ +/* + * Copyright 2013-2021 the original author.All rights reserved. + * Kingstar(honeysoft@126.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.teasoft.bee.osql.search; + +/** + * 为了过滤查询记录的结构体.Struct for search the record. + *

+ * eg: + * new Search("id",Operator.between,"100030","100035","or"); + * --> or id between 100030 and 100035 + + * @author Kingstar + * @since 1.9.8 + */ +public class Search { + + private String field; + private Operator op; + private String value1; + + // when like,notLike, value2 is:Left,Right,LeftRight + // when function, value2 is: alias name + //between, notBetween value2 is:second para + // other Operator,value2 is null + private String value2; + + private String op2; //or , and is default + + public Search() {} + + public Search(String field, Operator operator, String value1, String value2) { + super(); + this.field = field; + this.op = operator; + this.value1 = value1; + this.value2 = value2; + } + + public Search(String field, Operator operator, String value1, String value2, String op2) { + super(); + this.field = field; + this.op = operator; + this.value1 = value1; + this.value2 = value2; + this.op2 = op2; + } + + public String getField() { + return field; + } + public void setField(String field) { + this.field = field; + } + public Operator getOp() { + return op; + } + public void setOp(Operator operator) { + this.op = operator; + } + + public String getValue1() { + return value1; + } + + public void setValue1(String value1) { + this.value1 = value1; + } + + /** + * when like,notLike, value2 is:Left,Right,LeftRight + * when function, value2 is: alias name + * between, notBetween value2 is:second para + * other Operator,value2 is null + * @return value2 + */ + public String getValue2() { + return value2; + } + + /** + * when like,notLike, value2 is:Left,Right,LeftRight + * when function, value2 is: alias name + * between, notBetween value2 is:second para + * other Operator,value2 is null + * @param value2 + */ + public void setValue2(String value2) { + this.value2 = value2; + } + + /** + * it will be : "or", "and" , "(" , ")" , "or (", ") or", "and (", ") and" + * @return operator2 + */ + public String getOp2() { + return op2; + } + + /** + * it will be : "or", "and" , "(" , ")" , "or (", ") or", "and (", ") and" + * @param operator2 + */ + public void setOp2(String operator2) { + this.op2 = operator2; + } + +} diff --git a/src/main/java/org/teasoft/bee/osql/service/ObjSQLRichAbstractServiceImpl.java b/src/main/java/org/teasoft/bee/osql/service/ObjSQLRichAbstractServiceImpl.java index 2ce3e3cdcaade3a7cf80bdb20aaa504d6f5ac2ae..79e3b835e20846cce1fd78ebbb6b0971df6e14ca 100644 --- a/src/main/java/org/teasoft/bee/osql/service/ObjSQLRichAbstractServiceImpl.java +++ b/src/main/java/org/teasoft/bee/osql/service/ObjSQLRichAbstractServiceImpl.java @@ -317,11 +317,35 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic //Add the business logic if need. return getSuidRich().setDynamicParameter(para, value); } - + @Override public boolean exist(T entity) { //Add the business logic if need. return getSuidRich().exist(entity); } + + @Override + public int update(T oldEntity, T newEntity) { + //Add the business logic if need. + return getSuidRich().update(oldEntity, newEntity); + } + + @Override + public String selectJson(T entity, String selectField) { + //Add the business logic if need. + return getSuidRich().selectJson(entity, selectField); + } + + @Override + public String selectJson(T entity, String selectField, int start, int size) { + //Add the business logic if need. + return getSuidRich().selectJson(entity, selectField, start, size); + } + + @Override + public int save(T entity) { + //Add the business logic if need. + return getSuidRich().save(entity); + } } diff --git a/src/test/java/org/teasoft/bee/BeeExam.java b/src/test/java/org/teasoft/bee/BeeExam.java index 8cce73e47cb6011981090507a6b5333f59ce3641..91c54337e6d32dc0509d19dbf91d765012d73405 100644 --- a/src/test/java/org/teasoft/bee/BeeExam.java +++ b/src/test/java/org/teasoft/bee/BeeExam.java @@ -65,6 +65,24 @@ public class BeeExam { Assert.assertEquals(isFinished,true); +// V1.9.8 +// 2021-10-22 (yyyy-MM-dd) +// Instructions Counters +// Element Coverage +// Bee 98.0% +// Honey 73.1% +// +// Method Counters +// Element Coverage +// Bee 97.5% +// Honey 78.2% +// +// Type Counters +// Element Coverage +// Bee 100.0% +// Honey 97.1% + +// V1.9.5 // 2021-04-01 (yyyy-MM-dd) // Instructions Counters // Element Coverage diff --git a/src/test/java/org/teasoft/bee/change-log.txt b/src/test/java/org/teasoft/bee/change-log.txt index 894943b45c7d1083c2b8be3fe71f84efe4f65d98..39a132a59b13595745c6f615a06f5eb42b42fafb 100644 --- a/src/test/java/org/teasoft/bee/change-log.txt +++ b/src/test/java/org/teasoft/bee/change-log.txt @@ -68,7 +68,7 @@ bee-exam(v1.8.99)-normal(MySQL)-2020-10-17 21.42.02.730-UPPER.txt Optimize the way of setting DB information with Honeyconfig: bee-exam(v1.8.99)-normal(MySQL)-2020-10-24 21.40.20.605.txt -V1.9 +V1.9(V1.9.5) bee-exam(v1.9)-normal(MySQL)-2020-12-29 14.59.21.09.txt bee-exam(v1.9)-normal(MySQL)-2021-01-17 23.52.19.330.txt bee-exam(v1.9)-normal(MySQL)-2021-02-07 11.56.33.739.txt @@ -122,3 +122,13 @@ bee-exam(v1.9)2021-05-02 02.54.26.717-normal(H2).txt bee-exam(v1.9)2021-05-02 02.54.34.977-normal(PostgreSQL).txt bee-exam(v1.9)2021-05-02 02.54.55.328-normal(Microsoft SQL Server).txt bee-exam(v1.9)2021-05-02 02.55.16.45-cache(MySQL).txt + +test V1.9.8 with well-known and major database +bee-exam(v1.9.8)2021-10-22 13.28.59.122-normal(MySQL).txt +bee-exam(v1.9.8)2021-10-22 13.29.18.02-normal(Oracle).txt +bee-exam(v1.9.8)2021-10-22 13.29.41.620-normal(SQLite).txt +bee-exam(v1.9.8)2021-10-22 13.30.00.709-normal(H2).txt +bee-exam(v1.9.8)2021-10-22 13.30.07.72-normal(PostgreSQL).txt +bee-exam(v1.9.8)2021-10-22 13.30.26.941-normal(Microsoft SQL Server).txt +bee-exam(v1.9.8)2021-10-22 13.30.36.536-normal(MySQL).txt +bee-exam(v1.9.8)2021-10-22 13.30.58.799-cache(MySQL).txt