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
d1e8dd30
Commit
d1e8dd30
authored
Jun 18, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
常规BUG的修改
parent
6653c4b2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
0 deletions
+79
-0
DaoConst.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
+28
-0
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+6
-0
SqlData.java
...il-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
+21
-0
TableSqlCache.java
...src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
+19
-0
TableStruct.java
...b/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
+5
-0
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/DaoConst.java
View file @
d1e8dd30
...
@@ -159,4 +159,32 @@ public class DaoConst {
...
@@ -159,4 +159,32 @@ public class DaoConst {
* 删除时记录操作状态的字段
* 删除时记录操作状态的字段
*/
*/
public
static
final
int
FIELD_REMOVE_UPDATE
=
5
;
public
static
final
int
FIELD_REMOVE_UPDATE
=
5
;
/**
* SQL语句类型-普通语句
*/
public
static
final
int
SQL_TYPE_COMMON
=
0
;
/**
* SQL语句类型-创建语句
*/
public
static
final
int
SQL_TYPE_CREATE
=
1
;
/**
* SQL语句类型-更新语句
*/
public
static
final
int
SQL_TYPE_UPDATE
=
2
;
/**
* SQL语句类型-删除语句
*/
public
static
final
int
SQL_TYPE_REMOVE
=
3
;
/**
* SQL语句类型-加载语句
*/
public
static
final
int
SQL_TYPE_LOAD
=
4
;
/**
* SQL语句类型-是否存在
*/
public
static
final
int
SQL_TYPE_EXINTS
=
5
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
d1e8dd30
...
@@ -163,6 +163,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
...
@@ -163,6 +163,12 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
InitDao
to
=
(
InitDao
)
model
;
InitDao
to
=
(
InitDao
)
model
;
to
.
init
();
to
.
init
();
}
}
List
<
SqlData
>
sqlArray
=
this
.
table
.
getSqlType
(
DaoConst
.
SQL_TYPE_EXINTS
);
if
(
sqlArray
!=
null
)
{
for
(
SqlData
sql
:
sqlArray
)
{
this
.
checkExist
(
sql
.
getName
(),
model
,
String
.
format
(
"%s已经存在"
,
sql
.
getName
()));
}
}
}
}
/**
/**
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/SqlData.java
View file @
d1e8dd30
...
@@ -11,6 +11,11 @@ import java.util.List;
...
@@ -11,6 +11,11 @@ import java.util.List;
*/
*/
public
class
SqlData
{
public
class
SqlData
{
/**
* SQL语句类型
*/
private
int
sqlType
=
DaoConst
.
SQL_TYPE_COMMON
;
/**
/**
* 对应的参数顺序
* 对应的参数顺序
*/
*/
...
@@ -33,6 +38,22 @@ public class SqlData {
...
@@ -33,6 +38,22 @@ public class SqlData {
this
(
""
,
""
);
this
(
""
,
""
);
}
}
/**
* Sql语句类型
* @return Sql语句类型
*/
public
int
getSqlType
()
{
return
sqlType
;
}
/**
* Sql语句类型
* @param sqlType Sql语句类型
*/
public
void
setSqlType
(
int
sqlType
)
{
this
.
sqlType
=
sqlType
;
}
public
List
<
SqlDataField
>
getSqlDataFields
()
{
public
List
<
SqlDataField
>
getSqlDataFields
()
{
return
sqlDataFields
;
return
sqlDataFields
;
}
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableSqlCache.java
View file @
d1e8dd30
...
@@ -34,6 +34,11 @@ public class TableSqlCache {
...
@@ -34,6 +34,11 @@ public class TableSqlCache {
*/
*/
private
MemoryCache
<
SqlData
>
sqls
=
new
MemoryCache
<
SqlData
>();
private
MemoryCache
<
SqlData
>
sqls
=
new
MemoryCache
<
SqlData
>();
/**
* 根据Sql语句类型进行缓存
*/
private
MemoryCache
<
List
<
SqlData
>>
sqlTypes
=
new
MemoryCache
<>();
/**
/**
* 构造函数
* 构造函数
*/
*/
...
@@ -60,10 +65,24 @@ public class TableSqlCache {
...
@@ -60,10 +65,24 @@ public class TableSqlCache {
public
SqlData
add
(
SqlData
sql
)
{
public
SqlData
add
(
SqlData
sql
)
{
if
(
sql
!=
null
)
{
if
(
sql
!=
null
)
{
this
.
sqls
.
put
(
sql
.
getName
(),
sql
);
this
.
sqls
.
put
(
sql
.
getName
(),
sql
);
String
keyType
=
String
.
valueOf
(
sql
.
getSqlType
());
this
.
sqlTypes
.
get
(
keyType
,
new
ArrayList
<>()).
add
(
sql
);
}
}
return
sql
;
return
sql
;
}
}
/**
* 获取所有的Sql语句执行类型
*
* @param sqlType Sql语句执行类型
* @return Sql语句列表
*/
public
List
<
SqlData
>
getSqlType
(
int
sqlType
)
{
String
keyType
=
String
.
valueOf
(
sqlType
);
return
sqlTypes
.
get
(
keyType
);
}
/**
/**
* 添加SQL
* 添加SQL
*
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/TableStruct.java
View file @
d1e8dd30
...
@@ -310,6 +310,7 @@ public class TableStruct {
...
@@ -310,6 +310,7 @@ public class TableStruct {
// 生成添加的SQL语句
// 生成添加的SQL语句
String
text
=
DaoConst
.
INSERT_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
String
text
=
DaoConst
.
INSERT_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
CREATE
,
text
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
CREATE
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_CREATE
);
String
flag
=
""
;
String
flag
=
""
;
if
(
this
.
getKeyType
()
==
String
.
class
)
{
if
(
this
.
getKeyType
()
==
String
.
class
)
{
sql
.
addParaConst
(
this
.
getKey
().
inputName
,
DaoConst
.
FIELD_CODE
,
this
.
getKey
().
name
,
DaoConst
.
VALUES_CODE
,
"?"
);
sql
.
addParaConst
(
this
.
getKey
().
inputName
,
DaoConst
.
FIELD_CODE
,
this
.
getKey
().
name
,
DaoConst
.
VALUES_CODE
,
"?"
);
...
@@ -331,6 +332,7 @@ public class TableStruct {
...
@@ -331,6 +332,7 @@ public class TableStruct {
// 生成添加的SQL语句
// 生成添加的SQL语句
String
text
=
DaoConst
.
UPDATE_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
String
text
=
DaoConst
.
UPDATE_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
UPDATE
,
text
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
UPDATE
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_UPDATE
);
TableFieldVo
removeField
=
this
.
getRemove
();
TableFieldVo
removeField
=
this
.
getRemove
();
TableFieldVo
versionField
=
this
.
getVersion
();
TableFieldVo
versionField
=
this
.
getVersion
();
sql
.
addParaConst
(
this
.
getKey
().
inputName
,
sql
.
addParaConst
(
this
.
getKey
().
inputName
,
...
@@ -365,6 +367,7 @@ public class TableStruct {
...
@@ -365,6 +367,7 @@ public class TableStruct {
// 生成添加的SQL语句
// 生成添加的SQL语句
String
text
=
DaoConst
.
UPDATE_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
String
text
=
DaoConst
.
UPDATE_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
REMOVE
,
text
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
REMOVE
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_REMOVE
);
sql
.
addCode
(
DaoConst
.
FIELD_CODE
,
"a."
+
removeField
.
name
+
"=1"
);
sql
.
addCode
(
DaoConst
.
FIELD_CODE
,
"a."
+
removeField
.
name
+
"=1"
);
for
(
TableFieldVo
field
:
this
.
getFieldActionList
(
DaoConst
.
FIELD_REMOVE_UPDATE
))
{
for
(
TableFieldVo
field
:
this
.
getFieldActionList
(
DaoConst
.
FIELD_REMOVE_UPDATE
))
{
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
FIELD_CODE
,
",a."
+
field
.
name
+
"=?"
);
sql
.
addParaConst
(
field
.
inputName
,
DaoConst
.
FIELD_CODE
,
",a."
+
field
.
name
+
"=?"
);
...
@@ -391,6 +394,7 @@ public class TableStruct {
...
@@ -391,6 +394,7 @@ public class TableStruct {
// 生成添加的SQL语句
// 生成添加的SQL语句
String
text
=
DaoConst
.
LOAD_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
String
text
=
DaoConst
.
LOAD_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
LOAD
,
text
);
SqlData
sql
=
new
SqlData
(
DaoConst
.
LOAD
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_LOAD
);
addWhereField
(
sql
,
"a."
,
false
);
addWhereField
(
sql
,
"a."
,
false
);
return
sql
;
return
sql
;
}
}
...
@@ -510,6 +514,7 @@ public class TableStruct {
...
@@ -510,6 +514,7 @@ public class TableStruct {
public
void
addExist
(
TableSqlCache
sqlTableData
,
String
sqlName
,
String
[]
fields
)
{
public
void
addExist
(
TableSqlCache
sqlTableData
,
String
sqlName
,
String
[]
fields
)
{
String
text
=
DaoConst
.
LOAD_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
String
text
=
DaoConst
.
LOAD_MODEL
.
replace
(
DaoConst
.
TABLE_CODE
,
this
.
name
);
SqlData
sql
=
new
SqlData
(
sqlName
,
text
);
SqlData
sql
=
new
SqlData
(
sqlName
,
text
);
sql
.
setSqlType
(
DaoConst
.
SQL_TYPE_EXINTS
);
sql
.
addPara
(
this
.
getKey
().
inputName
,
DaoConst
.
WHERE_CODE
,
" AND a."
+
this
.
getKey
().
name
+
"<>?"
);
sql
.
addPara
(
this
.
getKey
().
inputName
,
DaoConst
.
WHERE_CODE
,
" AND a."
+
this
.
getKey
().
name
+
"<>?"
);
for
(
String
field
:
fields
)
{
for
(
String
field
:
fields
)
{
sql
.
addParaConst
(
field
,
DaoConst
.
WHERE_CODE
,
" AND a."
+
field
+
"=?"
);
sql
.
addParaConst
(
field
,
DaoConst
.
WHERE_CODE
,
" AND a."
+
field
+
"=?"
);
...
...
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