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
164a8814
Commit
164a8814
authored
Jun 28, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常处理显示
parent
26d0bcb5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
57 deletions
+99
-57
BaseDao.java
yzg-util-db/src/main/java/com/yanzuoguang/dao/BaseDao.java
+31
-11
BaseDaoImpl.java
...b/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
+68
-46
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/dao/BaseDao.java
View file @
164a8814
...
...
@@ -41,6 +41,7 @@ public interface BaseDao {
/**
* 删除数据,可以用于父子表删除,如通过订单删除游客信息 visitorDao.remove({orderId:1});
* int field;
*
* @param model 需要删除的数据,可以是主键字符串(Int),或者是包含主键的实体,或者是包含其他非主键的实体完全匹配.
* @return 删除的记录数量
*/
...
...
@@ -107,7 +108,7 @@ public interface BaseDao {
* @param model 需要创建的数据
* @return 创建的主键编号
*/
List
<
String
>
createArray
(
Object
...
model
);
List
<
String
>
createArray
(
Object
...
model
);
/**
* 保存数据,有主键时修改,无主键时创建
...
...
@@ -116,6 +117,7 @@ public interface BaseDao {
* @return 保存的主键编号
*/
List
<
String
>
saveList
(
List
model
);
/**
* 保存数据,有主键时修改,无主键时创建
*
...
...
@@ -123,4 +125,22 @@ public interface BaseDao {
* @return 保存的主键编号
*/
List
<
String
>
saveArray
(
Object
...
model
);
/**
* 删除数据,可以用于父子表删除,如通过订单删除游客信息 visitorDao.remove({orderId:1});
* int field;
*
* @param model 需要删除的数据,可以是主键字符串(Int),或者是包含主键的实体,或者是包含其他非主键的实体完全匹配.
* @return 删除的记录数量
*/
int
removeList
(
List
model
);
/**
* 删除数据,可以用于父子表删除,如通过订单删除游客信息 visitorDao.remove({orderId:1});
* int field;
*
* @param model 需要删除的数据,可以是主键字符串(Int),或者是包含主键的实体,或者是包含其他非主键的实体完全匹配.
* @return 删除的记录数量
*/
int
removeArray
(
Object
...
model
);
}
yzg-util-db/src/main/java/com/yanzuoguang/dao/impl/BaseDaoImpl.java
View file @
164a8814
...
...
@@ -6,7 +6,10 @@ import com.yanzuoguang.util.base.ObjectHelper;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.*
;
import
com.yanzuoguang.util.vo.InitDao
;
import
com.yanzuoguang.util.vo.MapRow
;
import
com.yanzuoguang.util.vo.PageSizeData
;
import
com.yanzuoguang.util.vo.PageSizeReqVo
;
import
java.util.*
;
...
...
@@ -170,6 +173,37 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
/**
* 删除数据
*
* @param model 需要删除的数据
* @return 删除的主键编号
*/
@Override
public
int
remove
(
Object
model
)
{
// 获取来源主键
Object
from
=
model
;
String
keyString
=
getInputKey
(
from
);
// 当主键存在值时,直接通过主键删除
if
(!
StringHelper
.
isEmpty
(
keyString
))
{
// 去掉其他非主键的属性
from
=
new
HashMap
<
String
,
Object
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
this
.
setKeyString
(
from
,
keyString
);
// 调用删除日志
this
.
check
(
DaoConst
.
OPERATOR_TYPE_REMOVE
,
keyString
,
from
);
}
// 处理来源值
for
(
TableFieldVo
fieldVo
:
this
.
table
.
getTable
().
getRemoveUpdate
())
{
Object
fromValue
=
ObjectHelper
.
get
(
model
,
fieldVo
.
inputName
);
ObjectHelper
.
set
(
from
,
fieldVo
.
inputName
,
fromValue
);
}
// 调用删除语句
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
REMOVE
);
return
updateSql
(
sqlData
,
from
);
}
/**
* 创建数据,当不传入了主键时,则会自动生成主键,传入时不会生成。
*
...
...
@@ -193,11 +227,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
*/
@Override
public
List
<
String
>
createArray
(
Object
...
model
)
{
List
<
String
>
ret
=
new
ArrayList
<>();
for
(
Object
item
:
model
)
{
ret
.
add
(
this
.
create
(
item
));
}
return
ret
;
return
createList
(
Arrays
.
asList
(
model
));
}
/**
...
...
@@ -224,11 +254,7 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
*/
@Override
public
List
<
String
>
updateArray
(
Object
...
model
)
{
List
<
String
>
ret
=
new
ArrayList
<>();
for
(
Object
item
:
model
)
{
ret
.
add
(
this
.
update
(
item
));
}
return
ret
;
return
updateList
(
Arrays
.
asList
(
model
));
}
/**
...
...
@@ -238,13 +264,14 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @return 保存的主键编号
*/
@Override
public
List
<
String
>
saveList
(
List
model
){
public
List
<
String
>
saveList
(
List
model
)
{
List
<
String
>
ret
=
new
ArrayList
<>();
for
(
Object
item
:
model
)
{
ret
.
add
(
this
.
save
(
item
));
}
return
ret
;
}
/**
* 保存数据,有主键时修改,无主键时创建
*
...
...
@@ -252,13 +279,39 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @return 保存的主键编号
*/
@Override
public
List
<
String
>
saveArray
(
Object
...
model
){
List
<
String
>
ret
=
new
ArrayList
<>();
public
List
<
String
>
saveArray
(
Object
...
model
)
{
return
saveList
(
Arrays
.
asList
(
model
));
}
/**
* 删除数据,可以用于父子表删除,如通过订单删除游客信息 visitorDao.remove({orderId:1});
* int field;
*
* @param model 需要删除的数据,可以是主键字符串(Int),或者是包含主键的实体,或者是包含其他非主键的实体完全匹配.
* @return 删除的记录数量
*/
@Override
public
int
removeList
(
List
model
)
{
int
ret
=
0
;
for
(
Object
item
:
model
)
{
ret
.
add
(
this
.
save
(
item
)
);
ret
+=
this
.
remove
(
item
);
}
return
ret
;
}
/**
* 删除数据,可以用于父子表删除,如通过订单删除游客信息 visitorDao.remove({orderId:1});
* int field;
*
* @param model 需要删除的数据,可以是主键字符串(Int),或者是包含主键的实体,或者是包含其他非主键的实体完全匹配.
* @return 删除的记录数量
*/
@Override
public
int
removeArray
(
Object
...
model
)
{
return
removeList
(
Arrays
.
asList
(
model
));
}
/**
* 检测数据
*
...
...
@@ -281,37 +334,6 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
}
}
/**
* 删除数据
*
* @param model 需要删除的数据
* @return 删除的主键编号
*/
@Override
public
int
remove
(
Object
model
)
{
// 获取来源主键
Object
from
=
model
;
String
keyString
=
getInputKey
(
from
);
// 当主键存在值时,直接通过主键删除
if
(!
StringHelper
.
isEmpty
(
keyString
))
{
// 去掉其他非主键的属性
from
=
new
HashMap
<
String
,
Object
>(
DaoConst
.
COLLECTION_INIT_SIZE
);
this
.
setKeyString
(
from
,
keyString
);
// 调用删除日志
this
.
check
(
DaoConst
.
OPERATOR_TYPE_REMOVE
,
keyString
,
from
);
}
// 处理来源值
for
(
TableFieldVo
fieldVo
:
this
.
table
.
getTable
().
getRemoveUpdate
())
{
Object
fromValue
=
ObjectHelper
.
get
(
model
,
fieldVo
.
inputName
);
ObjectHelper
.
set
(
from
,
fieldVo
.
inputName
,
fromValue
);
}
// 调用删除语句
SqlData
sqlData
=
this
.
getSql
(
DaoConst
.
REMOVE
);
return
updateSql
(
sqlData
,
from
);
}
/**
* 加载数据
*
...
...
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