From 7640fffaaf4c48dc0e90ac2f444f5244ed6f6704 Mon Sep 17 00:00:00 2001 From: aiteasoft Date: Mon, 25 Apr 2022 10:05:45 +0000 Subject: [PATCH 1/2] update src/main/java/org/teasoft/bee/osql/BeeSql.java. --- .../java/org/teasoft/bee/osql/BeeSql.java | 69 ++++++++----------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/teasoft/bee/osql/BeeSql.java b/src/main/java/org/teasoft/bee/osql/BeeSql.java index 3a6a146..f3ab72c 100644 --- a/src/main/java/org/teasoft/bee/osql/BeeSql.java +++ b/src/main/java/org/teasoft/bee/osql/BeeSql.java @@ -21,12 +21,10 @@ import java.util.List; import java.util.Map; /** - * 直接用sql语句操作数据库的接口 - *
在该接口中的sql字符串要是DB能识别的SQL语句 - *
该接口为Bee框架使用的底层接口,不建议用户直接使用 - *
The interface of operating database with SQL statement directly - *
The SQL string in this interface is the SQL statement that DB can recognize - *
BeeSql is the underlying interface used by Bee framework, and it is not recommended for users to use it directly + * The interface of operating database with SQL statement directly. + *
The SQL string in this interface is the SQL statement that DB can recognize. + *
BeeSql is the underlying interface used by Bee framework, and it is not + *
recommended for users to use it directly. * @author Kingstar * Create on 2013-6-30 22:05:36 * @since 1.0 @@ -34,92 +32,85 @@ import java.util.Map; public interface BeeSql { /** - * 根据sql查询数据,数据类型与entity类型一致 - *
According to SQL query data, data type is consistent with entity type. + * According to SQL query data, data type is consistent with entity type. * @param sql SQL select statement - * @param entity 与表对应的实体对象,且不能为空 - * entity corresponding to table and can not be null. - * @return 可包含多个实体(多条记录)的list. list can contain more than one entity. + * @param entity The entity corresponding to table and can not be null. + * @return List can contain more than one entity. */ public List select(String sql,T entity ); /** - * 多表查询的方法.根据sql查询数据,数据类型与entity类型一致 - *
According to SQL query more table data, data type is consistent with entity type. + * According to SQL query more table data, data type is consistent with entity type. * @param sql SQL select statement - * @param entity 与表对应的实体对象,且不能为空 - * entity corresponding to table and can not be null. - * @return 可包含多个实体(多条记录)的list. list can contain more than one entity. + * @param entity The entity corresponding to table and can not be null. + * @return List can contain more than one entity. * @since 1.7 */ public List moreTableSelect(String sql,T entity ); /** - * 查询部分字段.Select some field. + * Select some field. * @param sql SQL select statement - * @param entity - * @return entity的list,这些entity只有查询的部分字段会设值.list entity which just has some field. + * @param entity The entity corresponding to table and can not be null. + * @return List entity which just has some field. */ public List selectSomeField(String sql,T entity ); /** - * 用函数查询结果.Select result with function. SQL function: max,min,avg,sum,count. + * Select result with function. SQL function: max,min,avg,sum,count. * @param sql SQL select statement - * @return 函数统计的值.如果统计的结果集为空,除了count返回0,其它都返回空字符. + * @return The value of function statistics. + *
If the result set of statistics is empty,the count return 0,the other return empty string. + * */ public String selectFun(String sql) ; /** - * 查询并将每一行结果转成String数组.Select and transform every record to string array. + * Select and transform every record to string array. * @param sql SQL select statement - * @return List,每个元素是一行记录转换成的string数组. - * List, every element is string array(transform from record). + * @return List, every element is string array(transform from record). */ public List select(String sql); /** - * 查询并将每一行结果转成Map.Select and transform every record to 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). + * @return List, every element is a Map(transform from record). * @since 1.9 */ public List> selectMapList(String sql); /** - * 查询结果,并以json格式返回.Select and return json format result. + * Select and return json format result. * @param sql SQL select statement - * @return json格式结果集.json format result . + * @return json format result . */ public String selectJson(String sql); /** - * 操作update,insert,delete.对应Jdbc的executeUpdate方法 - *
Operate update,insert,delete. corresponding to Jdbc executeUpdate method. + * Operate update,insert,delete. corresponding to Jdbc executeUpdate method. * @param sql SQL statement to execute - * @return 成功操作的记录行数. the number of affected successfully records. + * @return the number of affected successfully records. */ public int modify(String sql); public long insertAndReturnId(String sql); /** - * 提交一批命令到数据库 * Submits a batch of commands to the database. - * @param sqls 要执行的sql语句数组 Array of SQL statements to execute - * @return 受影响的行数 Affected rows. + * @param sqls Array of SQL statements to execute + * @return Affected rows. */ public int batch(String sqls[]); /** - * 提交一批命令到数据库 * Submits a batch of commands to the database. - * @param sqls 要执行的sql语句数组 Array of SQL statements to execute - * @param batchSize 一个批次提交的命令数目 the size of commands in a batch - * @return 受影响的行数 Affected rows. + * @param sqls Array of SQL statements to execute + * @param batchSize the size of commands in a batch + * @return Affected rows. */ public int batch(String []sqls,int batchSize); } -- Gitee From 446934c612a2c77d6c71535d43d10ae55cbc5e39 Mon Sep 17 00:00:00 2001 From: aiteasoft Date: Mon, 25 Apr 2022 10:07:00 +0000 Subject: [PATCH 2/2] update src/main/java/org/teasoft/bee/osql/Condition.java. --- .../java/org/teasoft/bee/osql/Condition.java | 175 +++++++++--------- 1 file changed, 88 insertions(+), 87 deletions(-) diff --git a/src/main/java/org/teasoft/bee/osql/Condition.java b/src/main/java/org/teasoft/bee/osql/Condition.java index 7dab9b3..6576162 100644 --- a/src/main/java/org/teasoft/bee/osql/Condition.java +++ b/src/main/java/org/teasoft/bee/osql/Condition.java @@ -18,36 +18,37 @@ package org.teasoft.bee.osql; /** - * 为面向对象方式操作数据库提供封装的条件.Condition for operate DB with Object Oriented Programming way. - *
用户需要保证SQL的书写顺序,如order by应在group by的后面. - *
setMultiply,setAdd,set等方法仅用于SQL Update语句的set部分. + * Condition for operate DB with Object Oriented Programming way. *
Users need to ensure the order of SQL writing, such as order by should be behind group by. *
The methods setMultiply,setAdd,set just use in SQL Update 'set' part. + *
Field name will be translated according the config. * @author Kingstar * @since 1.6 */ 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). + * For setting the start of the page(only for select of SQL). + *
There is no restriction on writing order. + * @param start Start index,min value is 0 or 1(eg:MySQL is 0,Oracle is 1). * @return Condition */ public Condition start(Integer start); /** - * 添加用于分页时设置每页返回的记录数量(仅用于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). + * For setting the size of the page(only for select of SQL). + * There is no restriction on writing order. + * @param size Fetch result size (>0). * @return Condition */ public Condition size(Integer size); /** - * 设置IncludeType过滤参数.op,between,notBetween方法设置的字段,不受includeType的值影响.Set IncludeType. - *
如果Condition没有使用该方法设置,则按默认过滤方式处理. - *
无书写顺序限制.There is no restriction on writing order. + * Set the IncludeType filter parameter. The fields set by op, between and + *
notbetween methods are not affected by the value of IncludeType. + *
If the condition is not set with this method, it will be processed + *
according to the default filtering method. + *
There is no restriction on writing order. * @param includeType * @return Condition * @since 1.7 @@ -55,67 +56,67 @@ public interface Condition extends ConditionAssistant { public Condition setIncludeType(IncludeType includeType); /** - * 添加一个表达式条件.Add a expression condition. - *
此方法不能用于SQL的update set. - * @param field 字段名.field name - * @param op 操作符.operator. - * @param value 字段对应的值.value of the field. + * Add a expression condition. + *
This method cannot be used for SQL update set part. + * @param field Field name + * @param op operator + * @param value Value of the field. * @return Condition */ 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. + * The expression will correspond to: 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 Field name + * @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. - * eg: opWithField(field1,Op.gt,field2)-->where field1>field2 - * @param field1 first field - * @param op 操作符.operator. - * @param field2 second field + * Add a expression condition. + *
This method cannot be used for SQL update set part. + *
eg: opWithField(field1,Op.gt,field2)-->where field1>field2 + * @param field1 first field name + * @param op operator + * @param field2 second field name * @return Condition * @since 1.9 */ public Condition opWithField(String field1, Op op, String field2); /** - * 默认自动加 'and'.Default will automatically add 'and'. + * Default will automatically add 'and'. * * @return Condition */ public Condition and(); /** - * 添加 'or'.Add 'or'. + * Add 'or'. * * @return Condition */ public Condition or(); /** - * 添加左括号.Add left parentheses. + * Add left parentheses. * @return Condition */ public Condition lParentheses(); /** - * 添加右括号.Add right parentheses. + * Add right parentheses. * @return Condition */ public Condition rParentheses(); /** - * + * transform to: field between low and high; * @param field * @param low * @param high @@ -133,7 +134,7 @@ public interface Condition extends ConditionAssistant { public Condition notBetween(String field, Number low, Number high); /** - * between + * field between 'low' and 'high'; * @param field * @param low * @param high @@ -159,66 +160,66 @@ public interface Condition extends ConditionAssistant { /** * having - * eg: having(FunctionType.MIN, "field", Op.ge, 60)-->having min(field)>=60 - * @param functionType SQL函数类型 - * @param field 实体字段,会被命名转换(如果需要). - * @param op 操作类型 - * @param value 值 + *
eg: having(FunctionType.MIN, "field", Op.ge, 60)-->having min(field)>=60 + * @param functionType FunctionType + * @param field Entity field,it will be translated according the config. + * @param op operator + * @param value Value of the field. * @return Condition */ public Condition having(FunctionType functionType, String field, Op op, Number value); /** * order by - * eg: orderBy("price")-->order by price - * @param field 用于排序的字段名.field name. + *
eg: orderBy("price")-->order by price + * @param field field name. * @return Condition */ public Condition orderBy(String field); /** * order by - * eg: orderBy("price", OrderType.DESC)-->order by price desc - * @param field 用于排序的字段名.field name. - * @param orderType 排序类型(asc或desc). order type(asc or desc) + *
eg: orderBy("price", OrderType.DESC)-->order by price desc + * @param field Field name. + * @param orderType order type(asc or desc) * @return Condition */ public Condition orderBy(String field, OrderType orderType); /** * order by - * eg: orderBy(FunctionType.MAX, "total", OrderType.DESC)-->order by max(total) desc - * @param functionType SQL函数类型.Function type of SQL. - * @param field 用于排序的字段名.field name. - * @param orderType 排序类型(asc或desc). order type(asc or desc) + *
eg: orderBy(FunctionType.MAX, "total", OrderType.DESC)-->order by max(total) desc + * @param functionType Function type of SQL. + * @param field Field name. + * @param orderType order type(asc or desc) * @return Condition */ public Condition orderBy(FunctionType functionType, String field, OrderType orderType); /** - * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 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 + * @param field Field name. + * @param num number * @return Condition * @since 1.7.2 */ public Condition setAdd(String field,Number num); /** - * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 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 + * @param field Field name. + * @param num number * @return Condition * @since 1.7.2 */ public Condition setMultiply(String field,Number num); /** - * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 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 field Field name. * @param otherFieldName * @return Condition * @since 1.8 @@ -226,9 +227,9 @@ public interface Condition extends ConditionAssistant { public Condition setAdd(String field, String otherFieldName); /** - * 设置需要更新的字段(仅用于SQL的update set),字段在自身基础上变化.Set the fields to be updated (for only update of SQL),and the field change on itself. + * 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 field Field name. * @param otherFieldName other fieldName * @return Condition * @since 1.8 @@ -236,21 +237,21 @@ public interface Condition extends ConditionAssistant { public Condition setMultiply(String field, String otherFieldName); /** - * 设置需要更新的字段(仅用于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 + * 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)-->update table_name set maxid=1000 * @param fieldName field name - * @param num + * @param num number * @return Condition * @since 1.8 */ public Condition set(String fieldName, Number num); /** - * 设置需要更新的字段(仅用于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. + * 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 fieldName + * @param fieldName Field name * @param value * @return Condition * @since 1.8 @@ -260,66 +261,66 @@ public interface Condition extends ConditionAssistant { /** * set one field with other field value - * eg: setWithField(field1,field2)--> set field1=field2 - * @param field1 first field - * @param field2 second field + *
eg: setWithField(field1,field2)--> set field1=field2 + * @param field1 first field name + * @param field2 second field name * @return Condition * @since 1.9 */ public Condition setWithField(String field1, String field2); /** - * 指定需要查询的部分字段(仅用于SQL的select).Specify the partial fields to be queried (only for select of SQL). - * @param fieldList 需要查询的字段,一个参数指定多个字段时用逗号隔开;也可以用变长参数. select fields,if more than one,separate with comma. + * Specify the partial fields to be queried (only for select of SQL). + * @param fieldList select fields,if more than one,separate with comma or use variable-length arguments. * @return Condition * @since 1.8 - * @since 1.11 支持变长参数 + * @since 1.11 support variable-length arguments */ public Condition selectField(String... fieldList); /** - * 设置字段fieldName为distinct(fieldName) - * eg: selectDistinctField(fieldName) --> distinct(fieldName) - * @param fieldName 要设置为distinct的字段 + * set fieldName for distinct(fieldName) + *
eg: selectDistinctField(fieldName) --> distinct(fieldName) + * @param fieldName Field name * @return Condition * @since 1.9 */ public Condition selectDistinctField(String fieldName); /** - * 设置字段fieldName为distinct(fieldName) + * set fieldName for distinct(fieldName) * eg: selectDistinctField(fieldName,alias) --> distinct(fieldName) as alias - * @param fieldName 要设置为distinct的字段 - * @param alias 别名 + * @param fieldName Field name + * @param alias Name of alias * @return Condition * @since 1.9 */ public Condition selectDistinctField(String fieldName, String alias); /** - * 设置使用函数查询结果.set select result with function. + * set for select result with function. *
eg: condition.selectFun(FunctionType.COUNT, "*");-->count(*) - * @param functionType SQL函数类型.Function type of SQL. - * @param fieldForFun 用于函数统计的字段名.field name for function. + * @param functionType 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. + * set for 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. + * @param functionType Function type of SQL. + * @param fieldForFun field name for function. + * @param alias Name of alias 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. + * lock the select record with 'for update'. + *
There is no restriction on writing order. * @return Condition * @since 1.8 */ -- Gitee