JdbcEntityDaoSupport 类添加 update 方法,方便使用。
This commit is contained in:
parent
e916d067f3
commit
cb07c0befd
@ -56,6 +56,10 @@ public abstract class JdbcEntityDaoSupport<T extends Entity<ID>, ID extends Seri
|
||||
return Boolean.TRUE.equals(isExists);
|
||||
}
|
||||
|
||||
protected final int update(String sql, SqlParameterSource parameterSource) {
|
||||
return this.jdbc.update(sql, parameterSource);
|
||||
}
|
||||
|
||||
protected abstract T mapRow(ResultSet rs) throws SQLException;
|
||||
|
||||
protected void setRowMapper(@Nonnull RowMapper<T> rowMapper) {
|
||||
|
@ -34,7 +34,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
|
||||
@Override
|
||||
protected final void doDelete(@Nonnull Account entity) {
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
UPDATE sys_account SET deleted = id, "version" = "version" + 1
|
||||
WHERE id = :id AND deleted = 0 AND "version" = :version
|
||||
""",
|
||||
@ -132,15 +132,16 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
|
||||
@Override
|
||||
protected final Account doInsert(@Nonnull Account entity) {
|
||||
String sql = """
|
||||
INSERT INTO sys_account
|
||||
(id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status, created_by, create_time)
|
||||
VALUES
|
||||
(:id, :email, :mobilePhone, :username, :password, :salt, :avatar, :sex, :nickname, :status, :createdBy, :createTime)
|
||||
""";
|
||||
long id = IdUtil.getSnowflakeNextId();
|
||||
SqlParameterSource params = generateParamSource(id, entity);
|
||||
int i = jdbc.update(sql, params);
|
||||
int i = update("""
|
||||
INSERT INTO sys_account
|
||||
(id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
created_by, create_time)
|
||||
VALUES
|
||||
(:id, :email, :mobilePhone, :username, :password, :salt, :avatar, :sex, :nickname, :status,
|
||||
:createdBy, :createTime)
|
||||
""",
|
||||
generateParamSource(id, entity));
|
||||
AssertResult.update(i, 1);
|
||||
this.accountRoleDAO.insertAccountRoleRefs(id, entity.getRoleIds());
|
||||
return entity;
|
||||
@ -148,7 +149,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
|
||||
@Override
|
||||
protected final Account doUpdate(@Nonnull Account entity) {
|
||||
String sql = """
|
||||
int i = update("""
|
||||
UPDATE sys_account
|
||||
SET "email" = :email,
|
||||
"mobile_phone" = :mobilePhone,
|
||||
@ -163,9 +164,8 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
"update_time" = :updateTime,
|
||||
"version" = "version" + 1
|
||||
WHERE id = :id AND deleted = 0 AND "version" = :version
|
||||
""";
|
||||
SqlParameterSource params = generateParamSource(entity);
|
||||
int i = this.jdbc.update(sql, params);
|
||||
""",
|
||||
generateParamSource(entity));
|
||||
AssertResult.update(i, 1);
|
||||
this.accountRoleDAO.saveAccountRoleRefs(entity);
|
||||
return entity;
|
||||
|
@ -42,7 +42,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
@Override
|
||||
protected final Dict doInsert(@Nonnull Dict entity) {
|
||||
long id = IdUtil.getSnowflakeNextId();
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
INSERT INTO sys_dict_type (dict_type, dict_label, create_time, created_by)
|
||||
VALUES (:dictType, :dictLabel, :createTime, :createdBy)
|
||||
""",
|
||||
@ -54,7 +54,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
|
||||
@Override
|
||||
protected final Dict doUpdate(@Nonnull Dict entity) {
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
UPDATE sys_dict_type
|
||||
SET dict_type = :dictType,
|
||||
dict_label = :dictLabel,
|
||||
@ -71,7 +71,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
|
||||
@Override
|
||||
protected final void doDelete(@Nonnull Dict entity) {
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
UPDATE sys_dict_type SET deleted = id, "version" = "version" + 1
|
||||
WHERE id = :id AND deleted = 0 AND "version" = :version
|
||||
""",
|
||||
|
@ -61,7 +61,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
:component, :cache, :resource, :createTime, :createdBy)
|
||||
""";
|
||||
MapSqlParameterSource paramSource = generateParamSource(id, entity);
|
||||
int i = this.jdbc.update(sql, paramSource);
|
||||
int i = update(sql, paramSource);
|
||||
AssertResult.update(i, 1);
|
||||
this.actionDAO.saveActions(id, entity.getActions());
|
||||
return entity;
|
||||
@ -91,7 +91,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
""";
|
||||
|
||||
// 更新菜单
|
||||
int i = this.jdbc.update(sql, generateParamSource(entity));
|
||||
int i = update(sql, generateParamSource(entity));
|
||||
AssertResult.update(i, 1);
|
||||
|
||||
// 保存权限
|
||||
@ -102,7 +102,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
|
||||
@Override
|
||||
protected final void doDelete(@Nonnull Menu entity) {
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
UPDATE sys_menu SET deleted = id, "version" = "version" + 1
|
||||
WHERE id = :id AND deleted = 0 AND "version" = :version
|
||||
""",
|
||||
|
@ -46,7 +46,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
|
||||
@Override
|
||||
protected final void doDelete(@Nonnull Role entity) {
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
UPDATE sys_account SET deleted = id, "version" = "version" + 1
|
||||
WHERE id = :id AND deleted = 0 AND "version" = :version
|
||||
""",
|
||||
@ -64,7 +64,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
@Override
|
||||
protected final Role doInsert(@Nonnull Role entity) {
|
||||
long id = IdUtil.getSnowflakeNextId();
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
INSERT INTO sys_role
|
||||
(id, "name", identifier, status, remarks, create_time, created_by)
|
||||
VALUES
|
||||
@ -78,7 +78,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
|
||||
@Override
|
||||
protected final Role doUpdate(@Nonnull Role entity) {
|
||||
int i = this.jdbc.update("""
|
||||
int i = update("""
|
||||
UPDATE sys_role
|
||||
SET "name" = :name,
|
||||
"identifier" = :identifier,
|
||||
|
Loading…
x
Reference in New Issue
Block a user