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
9535b246
Commit
9535b246
authored
Jun 14, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
b9385cbb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
33 deletions
+75
-33
SqlCond.java
...il-db/src/main/java/com/yanzuoguang/dao/cond/SqlCond.java
+9
-9
SqlCondBase.java
...b/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
+40
-21
SqlCondDefault.java
...rc/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
+1
-1
SqlCondEquals.java
...src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
+12
-1
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+13
-1
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCond.java
View file @
9535b246
...
@@ -12,7 +12,7 @@ import java.util.Map;
...
@@ -12,7 +12,7 @@ import java.util.Map;
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
interface
SqlCond
{
public
interface
SqlCond
<
T
extends
SqlCond
>
{
/**
/**
* 条件不满足
* 条件不满足
...
@@ -29,14 +29,6 @@ public interface SqlCond {
...
@@ -29,14 +29,6 @@ public interface SqlCond {
*/
*/
int
COND_TYPE_CODE_COND
=
2
;
int
COND_TYPE_CODE_COND
=
2
;
/**
* 判断字段是否相等
*
* @return
*/
boolean
isField
(
String
...
field
);
/**
/**
* 获取字段值
* 获取字段值
*
*
...
@@ -62,4 +54,12 @@ public interface SqlCond {
...
@@ -62,4 +54,12 @@ public interface SqlCond {
* @return
* @return
*/
*/
SqlCond
copy
();
SqlCond
copy
();
/**
* 判断条件是否相等
*
* @param cond
* @return
*/
boolean
equals
(
T
cond
);
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondBase.java
View file @
9535b246
...
@@ -17,7 +17,7 @@ import java.util.Map;
...
@@ -17,7 +17,7 @@ import java.util.Map;
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
abstract
class
SqlCondBase
implements
SqlCond
{
public
abstract
class
SqlCondBase
<
T
extends
SqlCondBase
>
implements
SqlCond
<
T
>
{
protected
List
<
String
>
fields
=
new
ArrayList
<>();
protected
List
<
String
>
fields
=
new
ArrayList
<>();
...
@@ -34,26 +34,6 @@ public abstract class SqlCondBase implements SqlCond {
...
@@ -34,26 +34,6 @@ public abstract class SqlCondBase implements SqlCond {
}
}
}
}
/**
* 判断字段是否相等
*
* @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
();
}
/**
/**
* 获取字段值
* 获取字段值
*
*
...
@@ -139,4 +119,43 @@ public abstract class SqlCondBase implements SqlCond {
...
@@ -139,4 +119,43 @@ public abstract class SqlCondBase implements SqlCond {
List
<
String
>
arr
=
codeMap
.
get
(
name
);
List
<
String
>
arr
=
codeMap
.
get
(
name
);
arr
.
add
(
code
);
arr
.
add
(
code
);
}
}
/**
* 判断字段集合是否相等
*
* @param fromFields 来源字段
* @param toFields 目标字段
* @return
*/
protected
static
boolean
eqaulsField
(
List
<
String
>
fromFields
,
List
<
String
>
toFields
)
{
Map
<
String
,
Boolean
>
mapField
=
new
HashMap
<>();
for
(
String
fromField
:
fromFields
)
{
String
from
=
fromField
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
mapField
.
put
(
from
,
true
);
}
for
(
String
toField
:
toFields
)
{
String
to
=
toField
.
toLowerCase
().
replaceAll
(
"_"
,
""
);
mapField
.
remove
(
to
);
}
return
mapField
.
isEmpty
();
}
@Override
public
boolean
equals
(
Object
to
)
{
if
(
to
!=
null
&&
to
.
getClass
()
==
this
.
getClass
())
{
this
.
equals
((
T
)
to
);
}
return
super
.
equals
(
to
);
}
/**
* 判断条件是否相等
*
* @param cond
* @return
*/
@Override
public
boolean
equals
(
SqlCondBase
cond
)
{
return
SqlCondBase
.
eqaulsField
(
this
.
fields
,
cond
.
fields
);
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondDefault.java
View file @
9535b246
...
@@ -12,7 +12,7 @@ import java.util.List;
...
@@ -12,7 +12,7 @@ import java.util.List;
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
SqlCondDefault
extends
SqlCondBase
{
public
class
SqlCondDefault
extends
SqlCondBase
<
SqlCondDefault
>
{
public
SqlCondDefault
(
String
...
field
)
{
public
SqlCondDefault
(
String
...
field
)
{
this
(
Arrays
.
asList
(
field
));
this
(
Arrays
.
asList
(
field
));
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/cond/SqlCondEquals.java
View file @
9535b246
...
@@ -12,7 +12,7 @@ import java.util.List;
...
@@ -12,7 +12,7 @@ import java.util.List;
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
SqlCondEquals
extends
SqlCondBase
{
public
class
SqlCondEquals
extends
SqlCondBase
<
SqlCondEquals
>
{
public
Object
val
;
public
Object
val
;
...
@@ -62,4 +62,15 @@ public class SqlCondEquals extends SqlCondBase {
...
@@ -62,4 +62,15 @@ public class SqlCondEquals extends SqlCondBase {
SqlCondEquals
cond
=
new
SqlCondEquals
(
this
.
fields
,
this
.
val
);
SqlCondEquals
cond
=
new
SqlCondEquals
(
this
.
fields
,
this
.
val
);
return
cond
;
return
cond
;
}
}
/**
* 判断条件是否相等
*
* @param cond
* @return
*/
@Override
public
boolean
equals
(
SqlCondEquals
cond
)
{
return
SqlCondBase
.
eqaulsField
(
this
.
fields
,
cond
.
fields
)
&&
StringHelper
.
compare
(
this
.
val
,
cond
.
val
);
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
9535b246
...
@@ -140,8 +140,20 @@ public class SqlData {
...
@@ -140,8 +140,20 @@ public class SqlData {
* @return
* @return
*/
*/
public
SqlDataField
getField
(
String
fieldName
)
{
public
SqlDataField
getField
(
String
fieldName
)
{
SqlCondDefault
cond
=
new
SqlCondDefault
(
fieldName
);
return
getField
(
cond
);
}
/**
* 根据字段名称获取字段
*
* @param sqlCond
* @return
*/
public
SqlDataField
getField
(
SqlCond
sqlCond
)
{
for
(
SqlDataField
sqlDataField
:
this
.
sqlDataFields
)
{
for
(
SqlDataField
sqlDataField
:
this
.
sqlDataFields
)
{
if
(
sqlDataField
.
getCond
().
isField
(
fieldName
))
{
if
(
sqlDataField
.
getCond
().
equals
(
sqlCond
))
{
return
sqlDataField
;
return
sqlDataField
;
}
}
}
}
...
...
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