diff --git a/Changed_Log.md b/Changed_Log.md index 925ef318267102051a7391d328e4277e7d7c7873..d84adc24506c884eb80517088afa6769aabdb618 100644 --- a/Changed_Log.md +++ b/Changed_Log.md @@ -186,4 +186,31 @@ fixed bug about Oracle more table paing. 1.Support lower and upper case option for SQL KeyWord. 2.Cache sql key support MD5 string. 3.Optimize the way of setting DB information with Honeyconfig. -4.Fix bug about checkSelectField. \ No newline at end of file +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); +SuidRich adjust methods selectById for unique entity and intelligently judge the Javabean id type of string id parameter. +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); +no Javabean, use map to set the entity information that needs to be transformed and operate the database(select/delete record). +support read excel(*.xls,*.xlsx), converting data into List and importing them into database(bee-ext). +more table join select support more join condition. +same Connection for some ORM operation. +IncludeType support exclude " ". +add Ignore Annotation, ignore the field which do not want to transfer. +support define start and end token when generate file by template. +enhance DB conn management. +enhance code quality. +update batchSize(bee.osql.insert.batchSize) in bee.properties. +fix the problem that the fields with the same name will be confused in some databases(oracle) when multi table paging query. +fixed: update is default by id,but no id field or id is null,will have exception. +fixed: cache bug. +when entity is view(not table), recommend put in bee.osql.cache.never(bee.properties). \ No newline at end of file diff --git a/Changed_Log_CN.md b/Changed_Log_CN.md index 7b995121b2338efda46251fed9ad70761c55fef7..e80bf88e37442168e21a1be3dac109446103da55 100644 --- a/Changed_Log_CN.md +++ b/Changed_Log_CN.md @@ -175,4 +175,31 @@ public String selectFun(String sql); 3.优化利用HoneyConfig设置DB信息的方式. 4.修复关于checkSelectField的bug. +**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); +SuidRich调整selectById方法且String类型参数的id智能识别Javabean的id类型. +加强聚合函数cont,sum,avg,min,max功能,Condition增加方法: + public Condition selectFun(FunctionType functionType,String fieldForFun); + public Condition selectFun(FunctionType functionType,String fieldForFun,String alias); +无Javabean,用map承载需要转换的实体信息,操作数据库(查询,删除数据). +支持读取Excel(*.xls,*.xlsx),并将数据转成List,且导入到数据库(bee-ext). +多表关联查询支持多个关联条件. +多个ORM操作使用同一个Connection. +支持长度大于0空字符串忽略处理,如"     ". +增加Ignore注解,忽略javabean字段,不进行转换. +用模板生成文件支持自定义起止标签. +完善DB连接管理. +加强代码质量. +更新bee.properties文件中batchSize(bee.osql.insert.batchSize). +修复多表分页查询时,同名字段在部分数据库会混淆的缺陷(oracle). +修改缺陷:update默认主键为id时,无id字段或id为null时,异常处理. +修改缺陷:cache bug. +强烈建议:使用视图时,声明视图不放缓存(因会产生脏数据). + \ No newline at end of file diff --git a/FAQ_CN.md b/FAQ_CN.md index 1fa83b19f4098480f373f879ea2c43845ec3c8aa..ed555bde6c0a36b6bd2e529dac1a25a07c4b3544 100644 --- a/FAQ_CN.md +++ b/FAQ_CN.md @@ -159,6 +159,112 @@ 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 = BeeFactory.getHoneyFactory().getMapSuid(); + MapSql mapSql = BeeFactory.getHoneyFactory().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(); + } +``` + + **其它相关资源:** 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)  diff --git a/README.md b/README.md index 496c43fb3ec5be2eda4e80fc461a13de961a72e6..b46b14b601f53a4f153dabea7df863c510bd4b3a 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,33 @@ fixed null bug about:PreparedSql's method select(String sql,Object preValues[]). 3.Optimize the way of setting DB information with Honeyconfig. 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); +SuidRich adjust methods selectById for unique entity and intelligently judge the Javabean id type of string id parameter. +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); +no Javabean, use map to set the entity information that needs to be transformed and operate the database(select/delete record). +support read excel(*.xls,*.xlsx), converting data into List and importing them into database(bee-ext). +more table join select support more join condition. +same Connection for some ORM operation. +IncludeType support exclude " ". +add Ignore Annotation, ignore the field which do not want to transfer. +support define start and end token when generate file by template. +enhance DB conn management. +enhance code quality. +update batchSize(bee.osql.insert.batchSize) in bee.properties. +fix the problem that the fields with the same name will be confused in some databases(oracle) when multi table paging query. +fixed: update is default by id,but no id field or id is null,will have exception. +fixed: cache bug. +when entity is view(not table), recommend put in bee.osql.cache.never(bee.properties). + ## [Function Detail](../../../bee/blob/master/Changed_Log.md) [click for: Function Detail](../../../bee/blob/master/Changed_Log.md) diff --git a/README_CN.md b/README_CN.md index ab08f6ae22ce9f9114022e6fb45b69d332e148bd..e3e8cd1a1048a6c4655aaab81f24458408f4c217 100644 --- a/README_CN.md +++ b/README_CN.md @@ -12,9 +12,11 @@ Bee功能强大:复杂查询也支持向对象方式,分页查询性能更 #### 磨刀不误砍柴工! Bee连磨刀的时间都帮你省了。 **Bee** 是一个具有人工智能(AI)特性,省时/优雅、简易、自动( **AiTea:** Timesaving/Tasteful, Easy, Automatic) 的ORM软件框架(AiTeaSoft)(IT-->AiTea 的思维转变!)。 Bee是一种更接近SQL语言思维的ORM框架, -一种开发速度和开发成本都不比php差的Java ORM框架, +一种开发速度和开发成本都不比Php,Ruby on Rail差的Java ORM框架, 而且它的编码复杂度是O(1),即用了Bee,**无论多少个表**,你都可以不用另外再写dao代码。 +**Bee** 网址: +https://github.com/automvc/bee **Bee在gitee** 的网址: https://gitee.com/automvc/bee @@ -44,56 +46,32 @@ jdk1.7+ ## 最新功能介绍: -**V1.8** -**增加分布式特性:** -**1**.添加**多数据源**支持(**读写分离**一主多从, 仅分库). -增加多数据源无需改动Java代码(对编码透明),只需添加配置信息即可. -添加**多数据源路由**接口. -添加多数据源路由实现算法. -添加多数据源配置. -支持配置信息刷新. -**2**.**分布式**环境下生成**全局唯一**数字**递增id**. -分布式环境下生成**连续单调递增**(在一个workerid内),全局唯一数字id. -**3**.**Bee分布式唯一id**算法特性:不依赖时钟,workerid可配置,易扩展. -具体算法实现:SerialUniqueId,OneTimeSnowflakeId,PearFlowerId. -提供id生成工厂:GenIdFactory,且可配置id生成器具体实现类. -**4**.可为所有表的Long型id字段自动生成全局唯一id主键. -**增强功能:** -**5**.**同库分表**支持,**动态表名映射**支持. -**实体与任意表名映射支持**. -Suid add one method: -public Suid setDynamicParameter(String para,String value); -add 2 annotation:**@Table,@Entity**. -**6**.添加**for update**功能,用于锁住某个表的一些记录. -public Condition forUpdate() -**7**.增加高级更新设置值支持,复杂查询、多表查询支持**只查部分字段**: -在Condition添加5个新方法. -**8**.支持SQL输出日志配置,占位参数可显示参数,**可输出直接可执行的sql**: -bee.osql.showSQL.showType=true -bee.osql.showSQL.showExecutableSql=true -**9**.SuidRich添加一个新方法 -PreparedSql添加三个新方法 -**10**.Oracle DATE字段在Javabean里转成java.sql.Date存入数据库时会丢失时分秒, -转成Timestamp可以解决这个问题。 -**11**.GenFiles**根据模板自动生成文件**代码添加支持首字母大写,如: #{entityName?up1}. -**修复原有问题:** -**12**.bug修复:缓存key生成;批插入后清缓存. -修复缺陷:解析json时多余的逗号错误. -修复null bug,关于方法:PreparedSql's method select(String sql,Object preValues[]). - -**v1.8.15**(2020-10-01 3节日) -1.增强对数据库H2,SQLite,PostgreSQL的支持. -2.优化分页功能,分页参数也用占位符. -3.可零配置使用. -4.完善梨花算法经常不使用时,产生连续尾数为0的偶数的问题(SerialUniqueId和OneTimeSnowflakeId这两种ID生成算法不会有这些缺陷). -5.完善日志Log功能. -6.修复json转换bug. - -**v1.8.99**(2020-10-25 重阳节) -1.SQL关键字支持可配置大写或小写输出. -2.SQL缓存key可用MD5字符. -3.优化利用HoneyConfig设置DB信息的方式. -4.修复关于checkSelectField的bug. +**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); +SuidRich调整selectById方法且String类型参数的id智能识别Javabean的id类型. +加强聚合函数cont,sum,avg,min,max功能,Condition增加方法: + public Condition selectFun(FunctionType functionType,String fieldForFun); + public Condition selectFun(FunctionType functionType,String fieldForFun,String alias); +无Javabean,用map承载需要转换的实体信息,操作数据库(查询,删除数据). +支持读取Excel(*.xls,*.xlsx),并将数据转成List,且导入到数据库(bee-ext). +多表关联查询支持多个关联条件. +多个ORM操作使用同一个Connection. +支持长度大于0空字符串忽略处理,如"     ". +增加Ignore注解,忽略javabean字段,不进行转换. +用模板生成文件支持自定义起止标签. +完善DB连接管理. +加强代码质量. +更新bee.properties文件中batchSize(bee.osql.insert.batchSize). +修复多表分页查询时,同名字段在部分数据库会混淆的缺陷(oracle). +修改缺陷:update默认主键为id时,无id字段或id为null时,异常处理. +修改缺陷:cache bug. +强烈建议:使用视图时,声明视图不放缓存(因会产生脏数据). ## [详细完整功能介绍](../../../bee/blob/master/Changed_Log_CN.md) [点击链接可查看 详细完整功能介绍](../../../bee/blob/master/Changed_Log_CN.md) @@ -334,6 +312,7 @@ public class SuidExam { } } //注意: 事务,分页,排序,范围查询,查询结果直接返回json等都支持,这里只是一个入门例子. +//更加应用参考,请查看: 更多例子 和 综合应用 . ``` diff --git a/pom.xml b/pom.xml index 9b1b6199dd63556c2fe87a1ac5230c24e7f637d0..e62bf3837d6ab003a32f0b31c7bd15c9b55eb57d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.teasoft bee - 1.8.99 + 1.9-SNAPSHOT jar diff --git a/src/main/java/org/teasoft/bee/osql/BeeSql.java b/src/main/java/org/teasoft/bee/osql/BeeSql.java index 33cf942b821e42f017d1d8cb9fe0d0d0f9541b6c..d02a8265b69b342727f9e4275e0417d5dee871e3 100644 --- a/src/main/java/org/teasoft/bee/osql/BeeSql.java +++ b/src/main/java/org/teasoft/bee/osql/BeeSql.java @@ -18,6 +18,7 @@ package org.teasoft.bee.osql; import java.util.List; +import java.util.Map; /** * 直接用sql语句操作数据库的接口 @@ -80,6 +81,15 @@ public interface BeeSql { */ public List select(String sql); + /** + * 查询并将每一行结果转成Map.Select and transform every record to Map. + * @param sql SQL select statement + * @return List,每个元素是一行记录转换成的Map. + * List, every element is a Map(transform from record). + * @since 1.9 + */ + public List> selectMapList(String sql); + /** * 查询结果,并以json格式返回.Select and return json format result. * @param sql SQL select statement diff --git a/src/main/java/org/teasoft/bee/osql/Condition.java b/src/main/java/org/teasoft/bee/osql/Condition.java index e3710842ab54255eb8ea7d41f8084e9b86408415..ad8e71d9e6418b1ce717273c8974e06fbaa614d3 100644 --- a/src/main/java/org/teasoft/bee/osql/Condition.java +++ b/src/main/java/org/teasoft/bee/osql/Condition.java @@ -19,7 +19,9 @@ package org.teasoft.bee.osql; /** * 为面向对象方式操作数据库提供封装的条件.Condition for operate DB with Object Oriented Programming way. - * 用户需要保证SQL的书写顺序,如order by应在group by的后面. + *
用户需要保证SQL的书写顺序,如order by应在group by的后面. + *
setMultiply,setAdd,set等方法仅用于SQL Update语句的set部分. + *
The methods setMultiply,setAdd,set just use in SQL Update 'set' part. * @author Kingstar * @since 1.6 */ @@ -27,6 +29,7 @@ public interface Condition extends ConditionAssistant { /** * 添加用于分页时设置开始的页数(仅用于SQL的select).For setting the start of the page(only for select of SQL). + *
无书写顺序限制.There is no restriction on writing order. * @param start 开始下标(从0或1开始,eg:MySQL是0,Oracle是1). start index,min value is 0 or 1(eg:MySQL is 0,Oracle is 1). * @return Condition */ @@ -34,6 +37,7 @@ public interface Condition extends ConditionAssistant { /** * 添加用于分页时设置每页返回的记录数量(仅用于SQL的select).For setting the size of the page(only for select of SQL). + *
无书写顺序限制.There is no restriction on writing order. * @param size 结果集大小 大于等于1. fetch result size (>0). * @return Condition */ @@ -41,7 +45,8 @@ public interface Condition extends ConditionAssistant { /** * 设置IncludeType过滤参数.op,between,notBetween方法设置的字段,不受includeType的值影响.Set IncludeType. - * 如果Condition没有使用该方法设置,则按默认过滤方式处理. + *
如果Condition没有使用该方法设置,则按默认过滤方式处理. + *
无书写顺序限制.There is no restriction on writing order. * @param includeType * @return Condition * @since 1.7 @@ -50,6 +55,7 @@ public interface Condition extends ConditionAssistant { /** * 添加一个表达式条件.Add a expression condition. + *
此方法不能用于SQL的update set. * @param field 字段名.field name * @param Op 操作符.operator. * @param value 字段对应的值.value of the field. @@ -136,7 +142,7 @@ public interface Condition extends ConditionAssistant { /** * eg: having(FunctionType.MIN, "field", Op.ge, 60)-->having min(field)>=60 - * @param functionType 函数类型 + * @param functionType SQL函数类型 * @param field 实体字段,会被命名转换(如果需要). * @param Op 操作类型 * @param value 值 @@ -161,7 +167,7 @@ public interface Condition extends ConditionAssistant { /** * eg: orderBy(FunctionType.MAX, "total", OrderType.DESC)-->order by max(total) desc - * @param functionType 函数类型.Function type of SQL. + * @param functionType SQL函数类型.Function type of SQL. * @param field 用于排序的字段名.field name. * @param orderType 排序类型(asc或desc). order type(asc or desc) * @return Condition @@ -169,7 +175,7 @@ public interface Condition extends ConditionAssistant { public Condition orderBy(FunctionType functionType, String field, OrderType orderType); /** - * 设置需要更新的字段(仅用于SQL的update),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. *
eg: setAdd("price",2.0)--> price=price+2.0 * @param field * @param num @@ -179,7 +185,7 @@ public interface Condition extends ConditionAssistant { public Condition setAdd(String field,Number num); /** - * 设置需要更新的字段(仅用于SQL的update),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. *
eg: setMultiply("price",1.05)--> price=price*1.05 * @param field * @param num @@ -189,7 +195,7 @@ public interface Condition extends ConditionAssistant { public Condition setMultiply(String field,Number num); /** - * 设置需要更新的字段(仅用于SQL的update),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. *
eg:setAdd("price","delta")--> price=price+delta * @param field * @param fieldName @@ -199,7 +205,7 @@ public interface Condition extends ConditionAssistant { public Condition setAdd(String field, String fieldName); /** - * 设置需要更新的字段(仅用于SQL的update),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. *
eg: setMultiply("price","delta")--> price=price*delta * @param field * @param fieldName another fieldName @@ -209,7 +215,7 @@ public interface Condition extends ConditionAssistant { public Condition setMultiply(String field, String fieldName); /** - * 设置需要更新的字段(仅用于SQL的update);当要更新的字段也需要用于where条件时,可用该方法 + * 设置需要更新的字段(仅用于SQL的update set);当要更新的字段也需要用于where条件时,可用该方法 *
Set the fields that need to be updated (only for update of SQL ); this method can be used when the set fields also need to be used for the where expression. *
eg: set("maxid", 1000)-->maxid=1000 * @param fieldNmae @@ -220,7 +226,7 @@ public interface Condition extends ConditionAssistant { public Condition set(String fieldNmae, Number num); /** - * 设置需要更新的字段(仅用于SQL的update);当要更新的字段也需要用于where条件时,可用该方法 + * 设置需要更新的字段(仅用于SQL的update set);当要更新的字段也需要用于where条件时,可用该方法 *
Set the fields that need to be updated (only for update of SQL); this method can be used when the set fields also need to be used for the where expression. *
eg: set("name", 'bee')-->name='bee' * @param fieldNmae @@ -240,7 +246,29 @@ public interface Condition extends ConditionAssistant { public Condition selectField(String fieldList); /** - * 锁定查询的部分记录(仅用于SQL的单个表select) + * 设置使用函数查询结果.set select result with function. + *
eg: condition.selectFun(FunctionType.COUNT, "*");-->count(*) + * @param functionType SQL函数类型.Function type of SQL. + * @param fieldForFun 用于函数统计的字段名.field name for function. + * @return Condition + * @since 1.9 + */ + public Condition selectFun(FunctionType functionType,String fieldForFun); + + /** + * 设置使用函数查询结果.set select result with function. + *
eg:selectFun(FunctionType.MAX, "score","maxScore")-->max(score) as maxScore + * @param functionType SQL函数类型.Function type of SQL. + * @param fieldForFun 用于函数统计的字段名.field name for function. + * @param alias 统计结果的别名.alias name for the function result. + * @return Condition + * @since 1.9 + */ + public Condition selectFun(FunctionType functionType,String fieldForFun,String alias); + + /** + * 锁定查询的部分记录(仅用于SQL的单个表select).lock the select record with 'for update'. + *
无书写顺序限制.There is no restriction on writing order. * @return Condition * @since 1.8 */ diff --git a/src/main/java/org/teasoft/bee/osql/IncludeType.java b/src/main/java/org/teasoft/bee/osql/IncludeType.java index 1afc736e7e8bdc3546cc7528acf1e9b9326989f5..7e0a7d4717586455482a966d2a6f7890ee84e5cc 100644 --- a/src/main/java/org/teasoft/bee/osql/IncludeType.java +++ b/src/main/java/org/teasoft/bee/osql/IncludeType.java @@ -8,9 +8,11 @@ package org.teasoft.bee.osql; public enum IncludeType { // -1 for both exclude 留用 + EXCLUDE_BOTH(-1), //v1.9 INCLUDE_NULL(0), INCLUDE_EMPTY(1), // "" - INCLUDE_BOTH(2); // NULL and "" + INCLUDE_BOTH(2), // NULL and "" + EXCLUDE_THREE(-3); //exclude: NULL and "" and " " private final int value; diff --git a/src/main/java/org/teasoft/bee/osql/LowerKey.java b/src/main/java/org/teasoft/bee/osql/LowerKey.java index 06410295f6c658a3b7abfd2f96583dddeecd51a9..ebe576d3067e230b8773712dec0d60082360e981 100644 --- a/src/main/java/org/teasoft/bee/osql/LowerKey.java +++ b/src/main/java/org/teasoft/bee/osql/LowerKey.java @@ -24,36 +24,36 @@ package org.teasoft.bee.osql; */ public class LowerKey implements SqlKeyWord { - public static String SPACE=" ", - select="select", - as="as", - from="from", - where="where", - insert="insert", - into="into", - values="values", - and="and", - or="or", - Null="null", - isNull="is null", - isNotNull="is not null", - update="update", - set="set", - delete="delete", - orderBy="order by", - count="count", - asc="asc", - on="on", - limit="limit", - offset="offset", - top="top", - - groupBy="group by", - having="having", - between="between", - notBetween="not between", - - forUpdate="for update"; + private static final String SPACE=" "; + private static final String select="select"; + private static final String as="as"; + private static final String from="from"; + private static final String where="where"; + private static final String insert="insert"; + private static final String into="into"; + private static final String values="values"; + private static final String and="and"; + private static final String or="or"; + private static final String Null="null"; + private static final String isNull="is null"; + private static final String isNotNull="is not null"; + private static final String update="update"; + private static final String set="set"; + private static final String delete="delete"; + private static final String orderBy="order by"; + private static final String count="count"; + private static final String asc="asc"; + private static final String on="on"; + private static final String limit="limit"; + private static final String offset="offset"; + private static final String top="top"; + + private static final String groupBy="group by"; + private static final String having="having"; + private static final String between="between"; + private static final String notBetween="not between"; + + private static final String forUpdate="for update"; @Override public String select() { diff --git a/src/main/java/org/teasoft/bee/osql/MapSql.java b/src/main/java/org/teasoft/bee/osql/MapSql.java new file mode 100644 index 0000000000000000000000000000000000000000..a79c7e5421299171e6b9183f5a6e6db8d7e85a22 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/MapSql.java @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * 用Map承载SQL信息.Record SQL information with map. + * @author Kingstar + * @since 1.9 + */ +public interface MapSql { + + /** + * 设置SQL用到的相关信息,Map的key由MapSqlKey提供.Set the relevant information used by SQL. The key of map is provided by MapSqlKey. + * @param MapSqlKey 设置的MapSqlKey Key + * @param value value + */ + public void put(MapSqlKey MapSqlKey, String value); + + /** + * 设置用于SQL中where过虑的字段信息.Set the field information used for where filtering in SQL. + * @param fieldName field name + * @param value value + */ + public void put(String fieldName, Object value); + + /** + * 用于Javabean与DB转换时配置信息设置 + * @param MapSqlSetting 设置的MapSqlSetting Key + * @param value 设置的值 + */ + public void put(MapSqlSetting MapSqlSetting, boolean value); + +} diff --git a/src/main/java/org/teasoft/bee/osql/MapSqlKey.java b/src/main/java/org/teasoft/bee/osql/MapSqlKey.java new file mode 100644 index 0000000000000000000000000000000000000000..adacba255454e766cda7870c19d5bf32d152df60 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/MapSqlKey.java @@ -0,0 +1,66 @@ +/* + * 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; + +/** + * 用于MapSuid的对应SQL功能的MapSql关键字.MapSql keyword for the corresponding SQL function of MapSuid. + * @author Kingstar + * @since 1.9 + */ +public enum MapSqlKey { + + /** + * 声明需要操作的表.Declare the table to be operated on. + */ + Table("Table"), + + /** + * 声明需要查询的字段.Declare the select fields. + */ + SelectColumns("SelectColumns"), + + /** + * 对应SQL的group by.It corresponds to the group by of SQL. + */ + GroupBy("GroupBy"), + + /** + * 对应SQL的having.It corresponds to the having of SQL. + */ + Having("Having"), + + /** + * 对应SQL的order by.It corresponds to the order by of SQL. + */ + OrderBy("OrderBy") + +// Start("Start"), +// Size("Size"), + ; + + String name; + + MapSqlKey(String name){ + this.name = name; + } + + public String getName(){ + return name; + } + +} diff --git a/src/main/java/org/teasoft/bee/osql/MapSqlSetting.java b/src/main/java/org/teasoft/bee/osql/MapSqlSetting.java new file mode 100644 index 0000000000000000000000000000000000000000..e56ef238c88d69876dcd720c47e674cc75d80f08 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/MapSqlSetting.java @@ -0,0 +1,55 @@ +/* + * 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; + +/** + * 用于MapSuid的MapSql配置信息.MapSql configuration information for MapSuid. + * @author Kingstar + * @since 1.9 + */ +public enum MapSqlSetting { + + /** + * 是否命令转换.Is naming transfer. value is 'true' or 'false',default is 'false' + * 真时,会根据配置的规则(bee.properties)如进行转换;假时不转换. + * if true, will transfer by the rule (eg: bee.properties). if false,do not transfer. + */ + IsNamingTransfer("IsNamingTransfer") , + + /** + * include Null.value is 'true' or 'false',default is 'false' + */ + IsIncludeNull("IsIncludeNull"), + + /** + * include empty string.value is 'true' or 'false',default is 'false' + */ + IsIncludeEmptyString("IsIncludeEmptyString") + ; + + String name; + + MapSqlSetting(String name){ + this.name = name; + } + + public String getName(){ + return name; + } + +} diff --git a/src/main/java/org/teasoft/bee/osql/MapSuid.java b/src/main/java/org/teasoft/bee/osql/MapSuid.java new file mode 100644 index 0000000000000000000000000000000000000000..3e2f39c37201bea297cba629b22cd2f6809a8fc1 --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/MapSuid.java @@ -0,0 +1,70 @@ +/* + * 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; + +import java.util.List; +import java.util.Map; + +/** + * 使用Map而非具体实体的数据库操作接口,默认不处理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) + * @author Kingstar + * @since 1.9 + */ +public interface MapSuid { + + /** + * 使用MapSql查询数据.Use MapSql to select data. + * @param mapSql MapSql instance + * @return List结构的多行记录. + *
the multi-line record of List structure. + */ + public List selectString(MapSql mapSql); + + /** + * 使用MapSql查询数据.Use MapSql to select data. + * @param mapSql MapSql instance + * @return Json格式的多行记录.multi-line record in JSON format. + */ + public String selectJson(MapSql mapSql); + + /** + * 使用MapSql查询数据.Use MapSql to select data. + * @param mapSql MapSql instance + * @return List>结构的多行记录. + *
the multi-line record of List> structure. + */ + public List> select(MapSql mapSql); + + /** + * 使用MapSql查询数据.Use MapSql to select data. + * @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. + * @param mapSql MapSql instance + * @return 成功删除的记录数. the numbers of delete records successfully. + */ + public int delete(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 283c6e34c97c3c385d5882fbe3d22e96fbde184d..5fcbf54d21d5dcccf205edf11920104dae572a1f 100644 --- a/src/main/java/org/teasoft/bee/osql/MoreTable.java +++ b/src/main/java/org/teasoft/bee/osql/MoreTable.java @@ -34,8 +34,9 @@ public class Orders{

private String sequence;

//@JoinTable(mainField="userid", subField="username") -

@JoinTable(mainField="userid", subField="username", joinType=JoinType.LEFT_JOIN) -

//@JoinTable(mainField="userid", subField="username",subAlias="myuser" , joinType=JoinType.RIGHT_JOIN) +

//@JoinTable(mainField="userid", subField="username", joinType=JoinType.LEFT_JOIN) //ok //... from orders left join user on orders.userid=user.username where ... +

@JoinTable(mainField="userid,name", subField="username,name", joinType=JoinType.JOIN) +

//@JoinTable(mainField="userid", subField="username",subAlias="myuser" , joinType=JoinType.FULL_JOIN)

//@JoinTable()

private User user;

diff --git a/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java b/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java index fd82fb5ca9f698e06d5ee35fbcde91f3ba185905..729e6c429a82653e2144582d37bdcb3e9d467264 100644 --- a/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java +++ b/src/main/java/org/teasoft/bee/osql/ObjToSQLRich.java @@ -35,7 +35,7 @@ public interface ObjToSQLRich extends ObjToSQL { public String toUpdateSQL(T entity,String updateFields); public String toUpdateSQL(T entity,String updateFields,IncludeType includeType); - public String toSelectFunSQL(T entity,FunctionType functionType, String FieldForFun) throws ObjSQLException; + public String toSelectFunSQL(T entity,FunctionType functionType, String FieldForFun,Condition condition); public String toSelectOrderBySQL(T entity, String orderFields) throws ObjSQLException; public String toSelectOrderBySQL(T entity, String orderFields,OrderType[] orderTypes) throws ObjSQLException; diff --git a/src/main/java/org/teasoft/bee/osql/Suid.java b/src/main/java/org/teasoft/bee/osql/Suid.java index 062c39fdee8fcdf31ef3c20e1fe154e3fe7ee44c..706f9b4a9a28b990b3ed64fa0fb09d5784aa4840 100644 --- a/src/main/java/org/teasoft/bee/osql/Suid.java +++ b/src/main/java/org/teasoft/bee/osql/Suid.java @@ -91,7 +91,6 @@ public interface Suid { */ public List select(T entity,Condition condition); - /** * 根据实体对象和Condition删记录.Delete the records according to entity and condition.
* 若condition没有设置IncludeType,默认过滤NULL和空字符串 @@ -113,4 +112,14 @@ public interface Suid { */ public Suid setDynamicParameter(String para,String value); + /** + * declare begin Same Connection for some ORM operation. + */ + public void beginSameConnection(); + + /** + * declare end Same Connection for some ORM operation. + */ + public void endSameConnection(); + } diff --git a/src/main/java/org/teasoft/bee/osql/SuidRich.java b/src/main/java/org/teasoft/bee/osql/SuidRich.java index 76728b1c44783e17ffe41c4ce5da7a60f3b133b0..42a8cf20f87236df894a7072a0489bc8ffd6f789 100644 --- a/src/main/java/org/teasoft/bee/osql/SuidRich.java +++ b/src/main/java/org/teasoft/bee/osql/SuidRich.java @@ -60,7 +60,7 @@ public interface SuidRich extends Suid { /** * 查询实体时,只查询部分一部分字段.Just select some fields. - * @param entity 实体类对象,且不能为空 + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). * @param selectFields 需要查询的字段,多个用逗号隔开. select fields,if more than one,separate with comma. * @return 可包含多个实体(多条记录)的list. list which contains more than one entity. */ @@ -69,7 +69,7 @@ public interface SuidRich extends Suid { /** * 查询实体时,只查询部分一部分字段,且可以分页 *
Just select some fields,and can specify page information. - * @param entity 实体类对象,且不能为空 + * @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). @@ -82,7 +82,7 @@ public interface SuidRich extends Suid { /** * 查询实体,每个字段都是以字符串类型返回 *
Select entity,every field will return the string type. - * @param entity 实体类对象,且不能为空 + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). * @return 可包含多个String数组结构的多条记录的list. list can contain more than one record with String array struct. */ public List selectString(T entity); @@ -90,12 +90,23 @@ public interface SuidRich extends Suid { /** * 查询部分字段,每个字段都是以字符串类型返回 *
Select some field, every field will return the string type. - * @param entity 实体类对象,且不能为空 + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). * @param selectFields 需要查询的字段,多个用逗号隔开. Select fields,if more than one,separate with comma. * @return 可包含多个String数组结构的多条记录的list. list can contain more than one record with String array struct. */ public List selectString(T entity,String selectFields); + + /** + * 不以具体实体结构返回数据,而是用字符数组的List + *
Instead of returning data in a entity structure, it uses a character array in List. + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @param condition condition.若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) + * @return 可包含多个String数组结构的多条记录的list. list can contain more than one record with String array struct. + * @since 1.9 + */ + public List selectString(T entity,Condition condition); + /** * 根据实体对象entity查询数据,并返回Json格式结果 *
Select and return data in Json format according to entity object. @@ -115,13 +126,43 @@ public interface SuidRich extends Suid { public T selectOne(T entity); /** - * 使用函数查询结果.Select result with function. + * 使用函数查询一个统计结果.Select result with one function,Just select one function. * @param entity 传入的实体对象,且不能为空 + * @param functionType MAX,MIN,SUM,AVG,COUNT * @param fieldForFun 需要使用函数的字段 + * @return 一个函数查询的结果.one function result. + */ + public String selectWithFun(T entity, FunctionType functionType, String fieldForFun); + + /** + * 使用函数查询一个统计结果,通过Condition可添加复杂过滤条件.只查询一个统计结果. + * Select result with one function,Just select one function. + * @param entity 传入的实体对象,且不能为空 * @param functionType MAX,MIN,SUM,AVG,COUNT - * @return 返回使用函数查询结果.Result select result with function. + * @param fieldForFun 需要使用函数的字段 + * @param condition condition.若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) + *
condition的selectFun方法将被忽略.will ignore the condition's selectFun method. + * @return 一个函数查询的结果.one function result. + * @since 1.9 */ - public String selectWithFun(T entity,FunctionType functionType,String fieldForFun); + public String selectWithFun(T entity, FunctionType functionType, String fieldForFun, Condition condition); //selectOneFun + + /** + * 统计记录总数.total number of statistical records. + * @param entity 实体类对象,且不能为空. table's entity(do not allow null). + * @return 统计记录行数. total number of records that satisfy the condition. + * @since 1.9 + */ + public int count(T entity); + + /** + * 统计记录总数.total number of statistical records. + * @param entity 实体类对象,且不能为空. table's entity(do not allow null). + * @param condition condition用于设置过滤条件.condition as filter the record. + * @return 统计记录行数. total number of records that satisfy the condition. + * @since 1.9 + */ + public int count(T entity, Condition condition); /** * 查询应用排序的结果,排序的字段默认按升序排列 @@ -136,7 +177,7 @@ public interface SuidRich extends Suid { * 查询应用排序的结果 * Select result with order. * @param entity 传入的实体对象,且不能为空 - * @param orderFields 排序字段列表,多个用逗号隔开 + * @param orderFields 排序字段列表,多个用逗号隔开.order fields,if more than one,separate with comma. * @param orderTypes 排序类型列表 * @return 可包含多个有排序的实体(多条记录)的list. list which contains more than one entity. */ @@ -146,7 +187,7 @@ public interface SuidRich extends Suid { * 更新记录,且可以指定需要更新的字段.Update record, can list update fields. * @param entity 实体类对象,不能为空 * @param updateFields 需要更新的字段列表,多个字段用逗号隔开(列表中有的字段都会更新),该属性不允许为空, - *
默认每个字段会被转化成SQL update的set表达式;其它非空,非null的字段作为过滤条件,转成SQL的where表达式. + *
除了updateFields中声明要更新的字段,其它非空,非null的字段作为过滤条件,转成SQL的where表达式. * @return 成功更新的记录数.the numbers of update record(s) successfully. */ public int update(T entity,String updateFields); @@ -163,15 +204,15 @@ public interface SuidRich extends Suid { /** * 批量插入数据.Insert records by batch type. - * @param entity 与表对应的实体对象,且不能为空. table's entity(do not allow null). + * @param entity 与表对应的实体对象数组,且不能为空. table's entity array(do not allow null). * @return 成功插入的记录行数. the number of inserted record(s) successfully. */ public int insert(T[] entity); /** * 批量插入数据.Insert records by batch type. - * @param entity 与表对应的实体对象,且不能为空. table's entity(do not allow null). - * @param batchSize + * @param entity 与表对应的实体对象,且不能为空. table's entity array(do not allow null). + * @param batchSize 批操作数量大小.batch size. * @return 成功插入的记录行数. the number of inserted record(s) successfully. */ public int insert(T[] entity,int batchSize); @@ -179,7 +220,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(do not allow null). + * @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. */ @@ -188,13 +229,53 @@ 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(do not allow null). + * @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. */ 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. + * @since 1.9 + */ + public int insert(List entityList); + + /** + * 批量插入数据.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. + * @since 1.9 + */ + public int insert(List entityList,int batchSize); + + /** + * 批量插入数据,且可以声明不用插入的字段列表 + *
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. + * @since 1.9 + */ + public int insert(List entityList,String excludeFields); + + /** + * 批量插入数据,且可以指定不用插入的字段列表 + *
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 batchSize 批操作数量大小.batch size. + * @param excludeFields 声明不用插入的字段列表.Don't insert fields list. + * @return 成功插入的记录行数. the number of inserted record(s) successfully. + * @since 1.9 + */ + public int insert(List entityList,int batchSize,String excludeFields); + /** * 根据实体对象entity查询数据.Select record according to entity. * @param entity 实体类对象,且不能为空. table's entity(do not allow null). @@ -208,9 +289,9 @@ public interface SuidRich extends Suid { public List select(T entity,IncludeType includeType); /** - * 根据实体对象entity更新数据.Update record according to entity. + * 根据实体对象entity中id更新该实体对象的数据.Update record according to entity. * @param entity 与表对应的实体对象,且不能为空;entity中id字段不能为空,作为过虑条件 - * id为null不作为过滤条件 + * id为null将引发ObjSQLException. * @param includeType 空字符串与null是否包含设置 * @return 成功更新的记录数.the numbers of update record(s) successfully. */ @@ -246,30 +327,40 @@ public interface SuidRich extends Suid { /** * 根据id查询记录.Select record by id. - * @param entity 实体类对象,且不能为空 + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). * @param id 实体id字段的值.value of entity's id field. - * @return 可包含多个实体(多条记录)的list. list which contains more than one entity. - * @since 1.4 + * @return 返回id对应的实体.return one entity which owns this id. + * @since 1.9 */ - public List selectById(T entity,Integer id); + public T selectById(T entity,Integer id); /** * 根据id查询记录.Select record by id. - * @param entity 实体类对象,且不能为空 + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). * @param id 实体id字段的值.value of entity's id field. - * @return 可包含多个实体(多条记录)的list. list which contains more than one entity. - * @since 1.4 + * @return 返回id对应的实体.return one entity which owns this id. + * @since 1.9 + */ + public T selectById(T entity,Long id); + + + /** + * 根据id查询记录.Select record by id. + * @param entity 实体类对象,且不能为空.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 List selectById(T entity,Long id); + public T selectById(T entity,String id); /** * 根据id查询记录.Select record by id. - * @param entity 实体类对象,且不能为空 - * @param ids 实体id字段的值,多个用逗号隔开.values of entity's id field. + * @param entity 实体类对象,且不能为空.table's entity(do not allow null). + * @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.4 + * @since 1.9 */ - public List selectById(T entity,String ids); + public List selectByIds(T entity,String ids); /** * 根据id删除记录.Delete record by id. @@ -292,13 +383,12 @@ public interface SuidRich extends Suid { /** * 根据id删除记录.Delete record by id. * @param c 实体类类型,且不能为空 - * @param ids 实体id字段的值,多个用逗号隔开.ids values of entity's id field. + * @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. * @since 1.4 */ public int deleteById(Class c,String ids); - /** * 根据实体对象entity查询数据.Select record according to entity. * @deprecated {@link Suid#select(Object,Condition)}方法中,可以通过condition设置includeType. @@ -317,6 +407,7 @@ public interface SuidRich extends Suid { /** * 根据实体对象entity查询数据,并以Json格式返回 *
Select and return data in Json format according to entity object. + * @deprecated {@link SuidRich#selectJson(Object,Condition)}方法中,可以通过condition设置includeType. * @param entity 与表对应的实体对象,且不能为空 * id为null不作为过滤条件 * @param includeType 空字符串与null是否包含设置 @@ -327,8 +418,22 @@ public interface SuidRich extends Suid { *
Json string, it transform from list which can contain more than one entity. * @since 1.6 */ + @Deprecated public String selectJson(T entity,IncludeType includeType,Condition condition); + /** + * 根据实体对象entity查询数据,并以Json格式返回 + *
Select and return data in Json format according to entity object. + * @param entity 与表对应的实体对象,且不能为空 + * id为null不作为过滤条件 + * @param condition entity默认有值的字段会转成field=value的形式,其它形式可通过condition指定.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 可包含多个实体(多条记录)的list转换成的json格式的字符串. + *
Json string, it transform from list which can contain more than one entity. + * @since 1.9 + */ + public String selectJson(T entity,Condition condition); /** * 更新记录,且可以指定作为条件的字段.Update record according to whereFields. @@ -358,7 +463,9 @@ public interface SuidRich extends Suid { * @param entity 实体类对象,不能为空 * 没指定为whereFields的字段,作为set部分(默认只处理非空,非null的字段) * @param whereFields 作为SQL中where条件的字段列表,多个字段用逗号隔开(列表中有的字段都会作为条件); - * 指定作为条件的,都转换.id为null不作为过滤条件 + * 指定作为条件的,都转换.id为null不作为过滤条件. + *
需要注意的是,用condition的op方法设置的条件,即使whereFields没有声明,也会转换. + *
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. @@ -366,6 +473,19 @@ public interface SuidRich extends Suid { */ public int updateBy(T entity,String whereFields,Condition condition); + /** + * 此方法,相当于SuidRich接口的 updateBy(entity,"id",condition); + * 更新记录,且可以指定作为条件的字段.Update record according to whereFields. + * @param entity 实体类对象,不能为空 + * entity中除了id字段,作为set部分(默认只处理非空,非null的字段) + * @param condition 用来设置默认情况不能表达的条件. + * 若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) + *
需要注意的是,condition用op设置的条件,也有可能转换为where部分的过滤条件. + * @return 成功更新的记录数.the numbers of update record(s) successfully. + * @since 1.9 + */ + public int updateById(T entity,Condition condition); + /** * 更新记录,且可以指定需要更新的字段,高级条件可通过Condition参数设置.Update record, can list update fields. @@ -374,6 +494,7 @@ public interface SuidRich extends Suid { * If the field of entity is not null or empty, it will be translate to field=value.Other can define with condition.
* @param updateFields 需要更新的字段列表,多个字段用逗号隔开(列表中有的字段都会更新),该属性不允许为空, *
默认updateFields的每个字段会被转化成SQL update的set表达式;其它非空,非null的字段作为过滤条件,转成SQL的where表达式. + *
condition中setMultiply,setAdd,set方法设置的字段不受此限制.The methods setMultiply,setAdd,set in condition are not subject to this restriction. * @param condition * 若condition没有设置IncludeType,默认过滤NULL和空字符串(但condition中op,between,notBetween方法设置的字段,不受includeType的值影响.) * @return 成功更新的记录数.the numbers of update record(s) successfully. diff --git a/src/main/java/org/teasoft/bee/osql/UpperKey.java b/src/main/java/org/teasoft/bee/osql/UpperKey.java index 13c20f43e1bdaedb8c4d8bb7f5947d49a40b8bcb..ac7fcc2d4813fe982a2e4a91c703d2bb736c63ae 100644 --- a/src/main/java/org/teasoft/bee/osql/UpperKey.java +++ b/src/main/java/org/teasoft/bee/osql/UpperKey.java @@ -24,38 +24,37 @@ package org.teasoft.bee.osql; */ public class UpperKey implements SqlKeyWord { - public static String SPACE=" ", - select="SELECT", - as="AS", - from="FROM", - where="WHERE", - insert="INSERT", - into="INTO", - values="VALUES", - and="AND", - or="OR", - Null="NULL", - isNull="IS NULL", - isNotNull="IS NOT NULL", - update="UPDATE", - set="SET", - delete="DELETE", - orderBy="ORDER BY", - count="COUNT", - asc="ASC", - on="ON", - - limit="LIMIT", - offset="OFFSET", - top="TOP", - - groupBy="GROUP BY", - having="HAVING", - between="BETWEEN", - notBetween="NOT BETWEEN", - - forUpdate="FOR UPDATE" ; - + private static final String SPACE=" "; + private static final String select="SELECT"; + private static final String as="AS"; + private static final String from="FROM"; + private static final String where="WHERE"; + private static final String insert="INSERT"; + private static final String into="INTO"; + private static final String values="VALUES"; + private static final String and="AND"; + private static final String or="OR"; + private static final String Null="NULL"; + private static final String isNull="IS NULL"; + private static final String isNotNull="IS NOT NULL"; + private static final String update="UPDATE"; + private static final String set="SET"; + private static final String delete="DELETE"; + private static final String orderBy="ORDER BY"; + private static final String count="COUNT"; + private static final String asc="ASC"; + private static final String on="ON"; + + private static final String limit="LIMIT"; + private static final String offset="OFFSET"; + private static final String top="TOP"; + + private static final String groupBy="GROUP BY"; + private static final String having="HAVING"; + private static final String between="BETWEEN"; + private static final String notBetween="NOT BETWEEN"; + + private static final String forUpdate="FOR UPDATE"; @Override public String select() { diff --git a/src/main/java/org/teasoft/bee/osql/annotation/Ignore.java b/src/main/java/org/teasoft/bee/osql/annotation/Ignore.java new file mode 100644 index 0000000000000000000000000000000000000000..e310459a0366b8f0edef6cbfd609f4341cec913f --- /dev/null +++ b/src/main/java/org/teasoft/bee/osql/annotation/Ignore.java @@ -0,0 +1,38 @@ +/* + * 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.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 忽略不想转换的字段.Ignore the field which do not want to transfer. + *
建议尽可能少用该注解,因为很多时间你可以用默认忽略null/空字符的特性达到同样的效果. + *
It is recommended that the annotation be used as little as possible, + *
because many times you can use the following features to achieve the same effect: + *
the null and empty string are not handled by default. + * @author Kingstar + * @since 1.9 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Ignore { + String value() default ""; +} diff --git a/src/main/java/org/teasoft/bee/osql/service/ObjSQLAbstractServiceImpl.java b/src/main/java/org/teasoft/bee/osql/service/ObjSQLAbstractServiceImpl.java index bb02b8957996791d1c286d10e9562b24fcb1a2a6..31dfc1ddbbb5af231580ed1b2171ab180172d28c 100644 --- a/src/main/java/org/teasoft/bee/osql/service/ObjSQLAbstractServiceImpl.java +++ b/src/main/java/org/teasoft/bee/osql/service/ObjSQLAbstractServiceImpl.java @@ -72,5 +72,17 @@ public abstract class ObjSQLAbstractServiceImpl implements ObjSQLService { //Add the business logic if need. return getSuid().setDynamicParameter(para, value); } + + @Override + public void beginSameConnection() { + //Add the business logic if need. + getSuid().beginSameConnection(); + } + + @Override + public void endSameConnection() { + //Add the business logic if need. + getSuid().endSameConnection(); + } } 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 b53dd533495cfba479d1679c51917e09ba934981..cbd0b3026ad4e499a4443b2408180f72f6e8a867 100644 --- a/src/main/java/org/teasoft/bee/osql/service/ObjSQLRichAbstractServiceImpl.java +++ b/src/main/java/org/teasoft/bee/osql/service/ObjSQLRichAbstractServiceImpl.java @@ -69,7 +69,6 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic //Add the business logic if need. return getSuidRich().insert(entity,excludeFieldList); } - @Override public int insert(T[] entity, int batchSize){ @@ -100,6 +99,24 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic //Add the business logic if need. return getSuidRich().selectWithFun(entity, functionType, fieldForFun); } + + @Override + public String selectWithFun(T entity, FunctionType functionType, String fieldForFun, Condition condition) { + //Add the business logic if need. + return getSuidRich().selectWithFun(entity, functionType, fieldForFun, condition); + } + + @Override + public int count(T entity) { + //Add the business logic if need. + return getSuidRich().count(entity); + } + + @Override + public int count(T entity, Condition condition) { + //Add the business logic if need. + return getSuidRich().count(entity, condition); + } @Override public List selectOrderBy(T entity, String orderFieldList) { @@ -118,7 +135,6 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic //Add the business logic if need. return getSuidRich().update(entity, updateFieldList, includeType); } - @Override public List select(T entity, IncludeType includeType) { @@ -169,21 +185,27 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic } @Override - public List selectById(T entity, Integer id) { + public T selectById(T entity, Integer id) { //Add the business logic if need. return getSuidRich().selectById(entity, id); } @Override - public List selectById(T entity, Long id) { + public T selectById(T entity, Long id) { + //Add the business logic if need. + return getSuidRich().selectById(entity, id); + } + + @Override + public T selectById(T entity, String id) { //Add the business logic if need. return getSuidRich().selectById(entity, id); } @Override - public List selectById(T entity, String ids) { + public List selectByIds(T entity, String ids) { //Add the business logic if need. - return getSuidRich().selectById(entity, ids); + return getSuidRich().selectByIds(entity, ids); } @Override @@ -217,6 +239,12 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic //Add the business logic if need. return getSuidRich().selectJson(entity, includeType,condition); } + + @Override + public String selectJson(T entity, Condition condition) { + //Add the business logic if need. + return getSuidRich().selectJson(entity, condition); + } @Override public int updateBy(T entity, String whereFields) { @@ -236,6 +264,12 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic return getSuidRich().updateBy(entity, whereFields, condition); } + @Override + public int updateById(T entity, Condition condition) { + //Add the business logic if need. + return getSuidRich().updateById(entity, condition); + } + @Override public int update(T entity, String updateFields, Condition condition) { //Add the business logic if need. @@ -247,5 +281,35 @@ public abstract class ObjSQLRichAbstractServiceImpl extends ObjSQLAbstractServic //Add the business logic if need. return getSuidRich().update(entity,condition); } + + @Override + public int insert(List entityList) { + //Add the business logic if need. + return getSuidRich().insert(entityList); + } + + @Override + public int insert(List entityList, int batchSize) { + //Add the business logic if need. + return getSuidRich().insert(entityList, batchSize); + } + + @Override + public int insert(List entityList, String excludeFields) { + //Add the business logic if need. + return getSuidRich().insert(entityList, excludeFields); + } + + @Override + public int insert(List entityList, int batchSize, String excludeFields) { + //Add the business logic if need. + return getSuidRich().insert(entityList, batchSize, excludeFields); + } + + @Override + public List selectString(T entity, Condition condition) { + //Add the business logic if need. + return getSuidRich().selectString(entity, condition); + } } diff --git a/src/test/java/org/teasoft/bee/BeeExam.java b/src/test/java/org/teasoft/bee/BeeExam.java index f8d08a47b1aabb85697b8c680fde8cdb171b0194..061d35cb53afc96104019613fb38ce807b38fd2b 100644 --- a/src/test/java/org/teasoft/bee/BeeExam.java +++ b/src/test/java/org/teasoft/bee/BeeExam.java @@ -53,6 +53,12 @@ public class BeeExam { // 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 +// 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 +// bee-exam(v1.9)-normal(MySQL)-2021-02-14 10.11.34.561.txt + // 测试用例请查看工程:bee-exam // 以下任意一个地址: // https://gitee.com/automvc/bee-exam diff --git a/src/test/java/org/teasoft/bee/change-log.txt b/src/test/java/org/teasoft/bee/change-log.txt index 3bad648bd9359677884d93c3981df482b4b67555..1bbfa99f41fc4c01b7d112424f566692ec99592e 100644 --- a/src/test/java/org/teasoft/bee/change-log.txt +++ b/src/test/java/org/teasoft/bee/change-log.txt @@ -67,3 +67,9 @@ 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 +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 +bee-exam(v1.9)-normal(MySQL)-2021-02-14 10.11.34.561.txt