Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
1153d9e1
Commit
1153d9e1
authored
Jun 10, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
e4d40499
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
494 additions
and
94 deletions
+494
-94
SqlCond.java
...il-db/src/main/java/com/yanzuoguang/dao/cond/SqlCond.java
+56
-0
SqlCondBase.java
...b/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
+132
-0
SqlCondDefault.java
...rc/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
+73
-0
SqlCondEquals.java
...src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
+76
-0
BaseDaoSql.java
...db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
+1
-46
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+79
-29
SqlDataField.java
.../src/main/java/com/yanzuoguang/dao/impl/SqlDataField.java
+77
-19
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCond.java
0 → 100644
View file @
1153d9e1
package
com
.
yanzuoguang
.
dao
.
cond
;
import
com.yanzuoguang.dao.impl.SqlData
;
import
com.yanzuoguang.dao.impl.SqlDataField
;
import
java.util.List
;
import
java.util.Map
;
/**
* 判断值是否满足条件
*
* @author 颜佐光
*/
public
interface
SqlCond
{
/**
* 条件不满足
*/
int
COND_TYPE_NONE
=
0
;
/**
* 仅仅只是输入条件
*/
int
COND_TYPE_CONST_ONLY_PARA
=
1
;
/**
* 输入条件代码
*/
int
COND_TYPE_CODE_COND
=
2
;
/**
* 判断字段是否相等
*
* @return
*/
boolean
isField
(
String
...
field
);
/**
* 获取新的SQL语句
*
* @param sql
* @param sqlData
* @param model
* @param codeMap
* @return
*/
String
getSql
(
String
sql
,
SqlData
sqlData
,
SqlDataField
field
,
Object
model
,
Map
<
String
,
List
<
String
>>
codeMap
);
/**
* 将当前条件复制为新的对象
*
* @return
*/
SqlCond
copy
();
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
0 → 100644
View file @
1153d9e1
package
com
.
yanzuoguang
.
dao
.
cond
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.impl.SqlData
;
import
com.yanzuoguang.dao.impl.SqlDataField
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 包含的值字段
*
* @author 颜佐光
*/
public
abstract
class
SqlCondBase
implements
SqlCond
{
protected
List
<
String
>
fields
=
new
ArrayList
<>();
/**
* 构造函数
*
* @param fields
*/
public
SqlCondBase
(
List
<
String
>
fields
)
{
for
(
String
field
:
fields
)
{
if
(!
StringHelper
.
isEmpty
(
field
))
{
this
.
fields
.
add
(
field
);
}
}
}
/**
* 判断字段是否相等
*
* @param toFields
* @return
*/
@Override
public
boolean
isField
(
String
...
toFields
)
{
Map
<
String
,
Boolean
>
fromFields
=
new
HashMap
<>();
for
(
String
fromField
:
this
.
fields
)
{
String
from
=
fromField
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
fromFields
.
put
(
from
,
true
);
}
for
(
String
toField
:
toFields
)
{
String
to
=
toField
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
fromFields
.
remove
(
to
);
}
return
!
fromFields
.
isEmpty
();
}
/**
* 获取当前的字段
*
* @return
*/
protected
abstract
String
getFieldName
();
/**
* 当前条件是否相等
*
* @param model 请求参数实体
* @param sqlField 请求字段
* @return
*/
protected
abstract
int
getCondType
(
Object
model
,
SqlDataField
sqlField
);
/**
* 获取新的SQL语句
*
* @param sql
* @param sqlData
* @param field
* @param model
* @param codeMap
* @return
*/
@Override
public
String
getSql
(
String
sql
,
SqlData
sqlData
,
SqlDataField
field
,
Object
model
,
Map
<
String
,
List
<
String
>>
codeMap
)
{
if
(
field
.
getCond
()
!=
this
)
{
throw
new
CodeException
(
"不能处理非本条件的字段"
);
}
int
condType
=
getCondType
(
model
,
field
);
switch
(
condType
)
{
case
COND_TYPE_CONST_ONLY_PARA:
{
String
fieldName
=
this
.
getFieldName
();
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
sql
=
sql
.
replaceFirst
(
"\\?"
,
"@"
+
fieldName
+
" "
);
break
;
}
case
COND_TYPE_CODE_COND:
{
String
fieldName
=
this
.
getFieldName
();
// 判断代码片段是否合法
if
(
field
.
getCodes
().
size
()
%
2
==
1
)
{
throw
new
CodeException
(
"代码片段"
+
this
.
getClass
().
getSimpleName
()
+
":"
+
sqlData
.
getName
()
+
":"
+
fieldName
+
"为单数"
);
}
// 处理代码片段
for
(
int
i
=
0
;
i
<
field
.
getCodes
().
size
();
i
=
i
+
DaoConst
.
CODE_UNIT
)
{
String
codeName
=
field
.
getCodes
().
get
(
i
);
String
codeValue
=
field
.
getCodes
().
get
(
i
+
1
);
codeValue
=
codeValue
.
replaceAll
(
"\\?"
,
"@"
+
fieldName
+
" "
);
addCodeMap
(
codeMap
,
codeName
,
codeValue
);
}
break
;
}
case
COND_TYPE_NONE:
default
:
break
;
}
return
sql
;
}
/**
* 将代码片段添加到SQL语句中
*
* @param codeMap 映射关系
* @param name 执行的代码片段
* @param code 代码片段
*/
protected
void
addCodeMap
(
Map
<
String
,
List
<
String
>>
codeMap
,
String
name
,
String
code
)
{
if
(!
codeMap
.
containsKey
(
name
))
{
codeMap
.
put
(
name
,
new
ArrayList
<
String
>());
}
List
<
String
>
arr
=
codeMap
.
get
(
name
);
arr
.
add
(
code
);
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
0 → 100644
View file @
1153d9e1
package
com
.
yanzuoguang
.
dao
.
cond
;
import
com.yanzuoguang.dao.impl.SqlDataField
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* 包含的值字段
*
* @author 颜佐光
*/
public
class
SqlCondDefault
extends
SqlCondBase
{
public
SqlCondDefault
(
String
...
field
)
{
this
(
Arrays
.
asList
(
field
));
}
protected
SqlCondDefault
(
List
<
String
>
fields
)
{
super
(
fields
);
}
/**
* 获取当前的字段
*
* @return
*/
@Override
protected
String
getFieldName
()
{
return
fields
.
isEmpty
()
?
StringHelper
.
EMPTY
:
this
.
fields
.
get
(
0
);
}
/**
* 当前条件是否相等
*
* @return
*/
@Override
protected
int
getCondType
(
Object
model
,
SqlDataField
sqlField
)
{
// 判断是否包含输入参数
boolean
isInputField
=
!
this
.
fields
.
isEmpty
();
// 判断是否属于条件
boolean
isCond
=
sqlField
.
getCodes
().
size
()
>
0
&&
sqlField
.
isAuto
();
if
(
isInputField
&&
isCond
)
{
for
(
String
field
:
this
.
fields
)
{
// 获取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
if
(
StringHelper
.
isEmpty
(
val
)
||
StringHelper
.
isEmptyArray
(
val
))
{
continue
;
}
// 只要有值不为空,则条件满足
return
COND_TYPE_CODE_COND
;
}
}
else
if
(
isInputField
)
{
// 前台输入参数,直接参数对接到SQL语句中
return
COND_TYPE_CONST_ONLY_PARA
;
}
return
COND_TYPE_NONE
;
}
/**
* 将当前条件复制为新的对象
*
* @return
*/
@Override
public
SqlCond
copy
()
{
SqlCondDefault
cond
=
new
SqlCondDefault
(
this
.
fields
);
return
cond
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
0 → 100644
View file @
1153d9e1
package
com
.
yanzuoguang
.
dao
.
cond
;
import
com.yanzuoguang.dao.impl.SqlDataField
;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* 包含的值字段
*
* @author 颜佐光
*/
public
class
SqlCondEquals
extends
SqlCondBase
{
public
Object
val
;
public
SqlCondEquals
(
String
field
,
Object
val
)
{
this
(
Arrays
.
asList
(
field
),
val
);
}
public
SqlCondEquals
(
List
<
String
>
fields
,
Object
val
)
{
super
(
fields
);
this
.
val
=
val
;
}
/**
* 获取当前的字段
*
* @return
*/
@Override
protected
String
getFieldName
()
{
return
fields
.
isEmpty
()
?
StringHelper
.
EMPTY
:
this
.
fields
.
get
(
0
);
}
/**
* 当前条件是否相等
*
* @return
*/
@Override
protected
int
getCondType
(
Object
model
,
SqlDataField
sqlField
)
{
// 判断是否包含输入参数
boolean
isInputField
=
!
this
.
fields
.
isEmpty
();
// 判断是否属于条件
boolean
isCond
=
sqlField
.
getCodes
().
size
()
>
0
&&
sqlField
.
isAuto
();
if
(
isInputField
&&
isCond
)
{
for
(
String
field
:
this
.
fields
)
{
// 获取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
);
if
(
StringHelper
.
isEmpty
(
val
)
||
StringHelper
.
isEmptyArray
(
val
))
{
continue
;
}
if
(
StringHelper
.
compare
(
val
,
this
.
val
))
{
// 只要有值不为空,则条件满足
return
COND_TYPE_CODE_COND
;
}
}
return
COND_TYPE_NONE
;
}
return
COND_TYPE_NONE
;
}
/**
* 将当前条件复制为新的对象
*
* @return
*/
@Override
public
SqlCond
copy
()
{
SqlCondEquals
cond
=
new
SqlCondEquals
(
this
.
fields
,
this
.
val
);
return
cond
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoSql.java
View file @
1153d9e1
...
...
@@ -600,36 +600,7 @@ public abstract class BaseDaoSql {
private
String
handleCodeRelease
(
String
sql
,
SqlData
sqlData
,
Object
model
,
Map
<
String
,
List
<
String
>>
codeMap
)
{
// 循环处理字段
for
(
SqlDataField
field
:
sqlData
.
getSqlDataFields
())
{
// 获取值
Object
val
=
ObjectHelper
.
get
(
model
,
field
.
paraName
);
// 不需要输入参数,仅仅只是代码片段
boolean
isCode
=
StringHelper
.
isEmpty
(
field
.
paraName
);
// 判断是否属于
if
(!
isCode
)
{
// 判断是否属于条件
boolean
isCond
=
field
.
codes
.
size
()
>
0
&&
field
.
auto
;
// 处理参数
if
(!
isCond
)
{
// 进行SQL语句参数替换,后面增加一个空格,方便后续用正则表达式进行替换处理
sql
=
sql
.
replaceFirst
(
"\\?"
,
"@"
+
field
.
paraName
+
" "
);
}
if
(
isCond
&&
(
StringHelper
.
isEmpty
(
val
)
||
StringHelper
.
isEmptyArray
(
val
)))
{
continue
;
}
}
// 判断代码片段是否合法
if
(
field
.
codes
.
size
()
%
2
==
1
)
{
throw
new
CodeException
(
"代码片段"
+
this
.
getClass
().
getSimpleName
()
+
":"
+
sqlData
.
getName
()
+
":"
+
field
.
paraName
+
"为单数"
);
}
// 处理代码片段
for
(
int
i
=
0
;
i
<
field
.
codes
.
size
();
i
=
i
+
DaoConst
.
CODE_UNIT
)
{
String
codeName
=
field
.
codes
.
get
(
i
);
String
codeValue
=
field
.
codes
.
get
(
i
+
1
);
codeValue
=
codeValue
.
replaceAll
(
"\\?"
,
"@"
+
field
.
paraName
+
" "
);
addCodeMap
(
codeMap
,
codeName
,
codeValue
);
}
sql
=
field
.
getCond
().
getSql
(
sql
,
sqlData
,
field
,
model
,
codeMap
);
}
return
sql
;
}
...
...
@@ -716,7 +687,6 @@ public abstract class BaseDaoSql {
return
sql
;
}
/**
* 添加数组型参数
*
...
...
@@ -831,21 +801,6 @@ public abstract class BaseDaoSql {
}
}
/**
* 将代码片段添加到SQL语句中
*
* @param codeMap 映射关系
* @param name 执行的代码片段
* @param code 代码片段
*/
private
void
addCodeMap
(
Map
<
String
,
List
<
String
>>
codeMap
,
String
name
,
String
code
)
{
if
(!
codeMap
.
containsKey
(
name
))
{
codeMap
.
put
(
name
,
new
ArrayList
<
String
>());
}
List
<
String
>
arr
=
codeMap
.
get
(
name
);
arr
.
add
(
code
);
}
/**
* 根据缓存查询第一个单元格
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
1153d9e1
package
com
.
yanzuoguang
.
dao
.
impl
;
import
com.yanzuoguang.dao.DaoConst
;
import
com.yanzuoguang.dao.cond.SqlCond
;
import
com.yanzuoguang.dao.cond.SqlCondDefault
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -137,10 +140,8 @@ public class SqlData {
* @return
*/
public
SqlDataField
getField
(
String
fieldName
)
{
String
to
=
fieldName
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
for
(
SqlDataField
sqlDataField
:
this
.
sqlDataFields
)
{
String
from
=
sqlDataField
.
paraName
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
if
(
to
.
equals
(
from
))
{
if
(
sqlDataField
.
getCond
().
isField
(
fieldName
))
{
return
sqlDataField
;
}
}
...
...
@@ -158,24 +159,26 @@ public class SqlData {
* @param paraName 前台参数名称
*/
public
SqlData
add
(
String
paraName
)
{
return
addCodeExecute
(
paraName
,
""
,
false
);
return
addCodeExecute
(
getCondDefault
(
paraName
)
,
""
,
false
);
}
/**
* 添加常规代码片段,即不论如何都会将该代码片段增加到SQL语句中。
* 当前台参数传入值时,在 {WHERE} 条件中增加条件,并增加附加的代码片段
* <p>
* 例子:
* SqlData sql = new SqlData("SQL_NAME","SELECT * FROM TABLE {INNER} WHERE 1=1 {WHERE}");
* sql.addCode(
* "{INNER}", " INNER JOIN TABLE_B " ,
* "{WHERE}", " AND 1=1" ,
* sql.add("id" , " AND id = ? ",
* "{INNER}", " INNER JOIN TABLE_B "
* );
* 最终SQL语句为: (1=1 AND 会自动去掉)
* SELECT * FROM TABLE INNER JOIN TABLE_B WHERE
1=1"
* SELECT * FROM TABLE INNER JOIN TABLE_B WHERE
id = {@id}
*
* @param codes 代码片段
* @param paraName 前台参数名称
* @param condSql {WHERE}代码片段中的条件
* @param codes 扩展代码片段
*/
public
SqlData
add
Code
(
String
...
codes
)
{
return
add
CodeExecute
(
""
,
""
,
false
,
codes
);
public
SqlData
add
(
String
paraName
,
String
condSql
,
String
...
codes
)
{
return
add
(
getCondDefault
(
paraName
),
condSql
,
codes
);
}
/**
...
...
@@ -189,14 +192,15 @@ public class SqlData {
* 最终SQL语句为: (1=1 AND 会自动去掉)
* SELECT * FROM TABLE INNER JOIN TABLE_B WHERE id = {@id}
*
* @param
paraName 前台参数名称
* @param cond
{WHERE}代码片段中的条件
* @param codes
扩展代码片段
* @param
cond 前台参数对应的条件
* @param cond
Sql
{WHERE}代码片段中的条件
* @param codes 扩展代码片段
*/
public
SqlData
add
(
S
tring
paraName
,
String
cond
,
String
...
codes
)
{
return
addCodeExecute
(
paraName
,
cond
,
true
,
codes
);
public
SqlData
add
(
S
qlCond
cond
,
String
condSql
,
String
...
codes
)
{
return
addCodeExecute
(
cond
,
condSql
,
true
,
codes
);
}
/**
* 当前台参数传入值时,增加附加的代码片段
* <p>
...
...
@@ -213,7 +217,43 @@ public class SqlData {
* @param codes 代码片段
*/
public
SqlData
addPara
(
String
paraName
,
String
...
codes
)
{
return
addCodeExecute
(
paraName
,
""
,
true
,
codes
);
return
addPara
(
getCondDefault
(
paraName
),
codes
);
}
/**
* 当前台参数传入值时,增加附加的代码片段
* <p>
* 例子:
* SqlData sql = new SqlData("SQL_NAME","SELECT * FROM TABLE {INNER} WHERE 1=1 {WHERE}");
* sql.addPara("id" ,
* "{WHERE}", " AND id = ? ",
* "{INNER}", " INNER JOIN TABLE_B "
* );
* 最终SQL语句为: (1=1 AND 会自动去掉)
* SELECT * FROM TABLE INNER JOIN TABLE_B WHERE id = {@id}
*
* @param cond 字段
* @param codes 代码片段
*/
public
SqlData
addPara
(
SqlCond
cond
,
String
...
codes
)
{
return
addCodeExecute
(
cond
,
""
,
true
,
codes
);
}
/**
* 添加常规代码片段,即不论如何都会将该代码片段增加到SQL语句中。
* 例子:
* SqlData sql = new SqlData("SQL_NAME","SELECT * FROM TABLE {INNER} WHERE 1=1 {WHERE}");
* sql.addCode(
* "{INNER}", " INNER JOIN TABLE_B " ,
* "{WHERE}", " AND 1=1" ,
* );
* 最终SQL语句为: (1=1 AND 会自动去掉)
* SELECT * FROM TABLE INNER JOIN TABLE_B WHERE 1=1"
*
* @param codes 代码片段
*/
public
SqlData
addCode
(
String
...
codes
)
{
return
addCodeExecute
(
getCondDefault
(
StringHelper
.
EMPTY
),
""
,
false
,
codes
);
}
/**
...
...
@@ -232,10 +272,9 @@ public class SqlData {
* @param codes 扩展代码片段
*/
public
SqlData
addConst
(
String
paraName
,
String
cond
,
String
...
codes
)
{
return
addCodeExecute
(
paraName
,
cond
,
false
,
codes
);
return
addCodeExecute
(
getCondDefault
(
paraName
)
,
cond
,
false
,
codes
);
}
/**
* 不论前台参数是否有值,增加代码片段
* <p>
...
...
@@ -252,28 +291,29 @@ public class SqlData {
* @param codes 代码片段
*/
public
SqlData
addParaConst
(
String
paraName
,
String
...
codes
)
{
return
addCodeExecute
(
paraName
,
""
,
false
,
codes
);
return
addCodeExecute
(
getCondDefault
(
paraName
)
,
""
,
false
,
codes
);
}
/**
* 添加SQL语句的执行方法
*
* @param
paraName 参数名称
* @param cond
包含条件
* @param auto 未false时表示属于必须输入的参数
* @param codes 代码片段
* @param
condInput 输入条件
* @param cond
Sql 包含条件的Sql语句
* @param auto
未false时表示属于必须输入的参数
* @param codes
代码片段
* @return
*/
private
SqlData
addCodeExecute
(
S
tring
paraName
,
String
cond
,
boolean
auto
,
String
...
codes
)
{
SqlDataField
sql
=
new
SqlDataField
(
paraName
,
cond
);
private
SqlData
addCodeExecute
(
S
qlCond
condInput
,
String
condSql
,
boolean
auto
,
String
...
codes
)
{
SqlDataField
sql
=
new
SqlDataField
(
condInput
,
condSql
);
for
(
String
code
:
codes
)
{
sql
.
codes
.
add
(
code
);
sql
.
getCodes
()
.
add
(
code
);
}
sql
.
auto
=
auto
;
sql
.
setAuto
(
auto
)
;
this
.
sqlDataFields
.
add
(
sql
);
return
this
;
}
/**
* 删除字段
*
...
...
@@ -311,4 +351,14 @@ public class SqlData {
}
return
to
;
}
/**
* 获取默认条件
*
* @param paraName
* @return
*/
public
static
SqlCond
getCondDefault
(
String
paraName
)
{
return
new
SqlCondDefault
(
paraName
);
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlDataField.java
View file @
1153d9e1
package
com
.
yanzuoguang
.
dao
.
impl
;
import
com.yanzuoguang.dao.cond.SqlCond
;
import
com.yanzuoguang.dao.cond.SqlCondDefault
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
...
...
@@ -7,6 +9,7 @@ import java.util.List;
/**
* SQL语句的字段
*
* @author 颜佐光
*/
public
class
SqlDataField
{
...
...
@@ -14,17 +17,23 @@ public class SqlDataField {
/**
* 前台参数名称,当没有前台参数时,则把当前字段当常量代码片段处理
*/
p
ublic
String
paraName
=
StringHelper
.
EMPTY
;
p
rivate
SqlCond
cond
=
null
;
/**
* 是否根据前台参数自动添加,false时保持永久添加模式,
* 1. true为条件模式,即前台不输入参数时,则不增加相关代码片段
* 2. false为敞亮模式,不管前台是否输入,该参数和片段必然会增加到后台执行语句中
*/
p
ublic
boolean
auto
=
true
;
p
rivate
boolean
auto
=
true
;
/**
* 代码片段
*/
public
List
<
String
>
codes
=
new
ArrayList
<
String
>();
private
List
<
String
>
codes
=
new
ArrayList
<
String
>();
/**
* 条件对象
*/
public
SqlDataField
()
{
}
/**
* 构造函数
...
...
@@ -32,40 +41,47 @@ public class SqlDataField {
* @param paraName 前台输入字段
*/
public
SqlDataField
(
String
paraName
)
{
this
(
paraName
,
""
);
this
(
paraName
,
StringHelper
.
EMPTY
);
}
/**
* 构造函数
*
* @param paraName 前台输入字段
* @param cond
条件
* @param cond
Sql 条件语句
*/
public
SqlDataField
(
String
paraName
,
String
cond
)
{
this
.
paraName
=
paraName
;
this
.
add
(
cond
);
public
SqlDataField
(
String
paraName
,
String
condSql
)
{
this
(
new
SqlCondDefault
(
paraName
),
condSql
);
}
/**
*
复制实体
*
条件
*
* @
return
* @
param cond
*/
public
SqlDataField
copy
()
{
SqlDataField
to
=
new
SqlDataField
(
this
.
paraName
);
to
.
auto
=
this
.
auto
;
to
.
codes
.
addAll
(
this
.
codes
);
return
to
;
public
SqlDataField
(
SqlCond
cond
)
{
this
(
cond
,
StringHelper
.
EMPTY
);
}
/**
*
添加
条件
* 条件
*
* @param cond
* @param condSql
*/
public
SqlDataField
(
SqlCond
cond
,
String
condSql
)
{
this
.
cond
=
cond
;
this
.
add
(
condSql
);
}
/**
* 添加条件
*
* @param condSql
* @return
*/
public
SqlDataField
add
(
String
cond
)
{
return
this
.
add
(
"{WHERE}"
,
cond
);
public
SqlDataField
add
(
String
cond
Sql
)
{
return
this
.
add
(
"{WHERE}"
,
cond
Sql
);
}
/**
...
...
@@ -76,7 +92,7 @@ public class SqlDataField {
* @return
*/
public
SqlDataField
add
(
String
codeName
,
String
codeValue
)
{
if
(
""
.
equals
(
codeValue
)
||
codeValue
==
null
)
{
if
(
StringHelper
.
isEmpty
(
codeValue
)
)
{
return
this
;
}
this
.
codes
.
add
(
codeName
);
...
...
@@ -84,6 +100,21 @@ public class SqlDataField {
return
this
;
}
/**
* 复制实体
*
* @return
*/
public
SqlDataField
copy
()
{
SqlDataField
to
=
new
SqlDataField
();
if
(
this
.
cond
!=
null
)
{
to
.
cond
=
this
.
cond
.
copy
();
}
to
.
auto
=
this
.
auto
;
to
.
codes
.
addAll
(
this
.
codes
);
return
to
;
}
/**
* 清除所有的代码片段
*
...
...
@@ -93,4 +124,31 @@ public class SqlDataField {
this
.
codes
.
clear
();
return
this
;
}
public
SqlCond
getCond
()
{
if
(
this
.
cond
==
null
)
{
this
.
cond
=
new
SqlCondDefault
(
StringHelper
.
EMPTY
);
}
return
cond
;
}
public
void
setCond
(
SqlCond
cond
)
{
this
.
cond
=
cond
;
}
public
boolean
isAuto
()
{
return
auto
;
}
public
void
setAuto
(
boolean
auto
)
{
this
.
auto
=
auto
;
}
public
List
<
String
>
getCodes
()
{
return
codes
;
}
public
void
setCodes
(
List
<
String
>
codes
)
{
this
.
codes
=
codes
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment