将 find 方法的返回值改为 Optional<T>。
This commit is contained in:
@@ -5,6 +5,7 @@ import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -44,7 +45,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Account doFindById(@Nonnull Long id) {
|
||||
protected final Optional<Account> doFindById(@Nonnull Long id) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
@@ -56,7 +57,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account findByEmail(Email email) {
|
||||
public Optional<Account> findByEmail(Email email) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
@@ -68,7 +69,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account findByMobilePhone(MobilePhone mobilePhone) {
|
||||
public Optional<Account> findByMobilePhone(MobilePhone mobilePhone) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
@@ -80,7 +81,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account findByUsername(Username username) {
|
||||
public Optional<Account> findByUsername(Username username) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
@@ -143,7 +144,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
generateParamSource(id, entity));
|
||||
assertUpdateOneRow(i);
|
||||
this.accountRoleDAO.insertAccountRoleRefs(id, entity.getRoleIds());
|
||||
return entity;
|
||||
return find(id).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,7 +168,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
||||
generateParamSource(entity));
|
||||
assertUpdateOneRow(i);
|
||||
this.accountRoleDAO.saveAccountRoleRefs(entity);
|
||||
return entity;
|
||||
return find(entity.getId().orElseThrow()).orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,6 +6,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -15,6 +16,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
||||
@@ -34,7 +36,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dict doFindById(@Nonnull Long id) {
|
||||
public Optional<Dict> doFindById(@Nonnull Long id) {
|
||||
return queryForObject("SELECT id, dict_type, dict_label, \"version\" WHERE id = :id AND deleted = 0",
|
||||
"id", id);
|
||||
}
|
||||
@@ -49,7 +51,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
generateParamSource(id, entity));
|
||||
AssertResult.updateOneRow(i);
|
||||
this.dictValueDAO.insertDictValues(id, entity);
|
||||
return find(id);
|
||||
return find(id).orElseThrow(DataNotExistException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +68,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
||||
generateParamSource(entity));
|
||||
AssertResult.updateOneRow(i);
|
||||
this.dictValueDAO.updateDictValues(entity);
|
||||
return find(entity.getId().orElseThrow());
|
||||
return find(entity.getId().orElseThrow()).orElseThrow(DataNotExistException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -8,6 +8,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -17,6 +18,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
@@ -38,7 +40,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Menu doFindById(@Nonnull Long id) {
|
||||
protected final Optional<Menu> doFindById(@Nonnull Long id) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, parent_id, "type", "name", "path", title, icon, hidden, order_number, status, remarks,
|
||||
@@ -64,7 +66,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
int i = update(sql, paramSource);
|
||||
AssertResult.updateOneRow(i);
|
||||
this.actionDAO.saveActions(id, entity.getActions());
|
||||
return entity;
|
||||
return find(id).orElseThrow(DataNotExistException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +99,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
||||
// 保存权限
|
||||
Long id = entity.getId().orElseThrow();
|
||||
this.actionDAO.saveActions(id, entity.getActions());
|
||||
return entity;
|
||||
return find(entity.getId().orElseThrow()).orElseThrow(DataNotExistException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,6 +6,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -15,6 +16,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
||||
@@ -36,7 +38,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Role doFindById(@Nonnull Long id) {
|
||||
protected final Optional<Role> doFindById(@Nonnull Long id) {
|
||||
return queryForObject("""
|
||||
SELECT "id","name","identifier","status","remarks","version"
|
||||
FROM "sys_role"
|
||||
@@ -74,7 +76,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
AssertResult.updateOneRow(i);
|
||||
this.roleMenuRefDAO.saveRoleMenuRefs(id, entity);
|
||||
this.rolePermissionRefDAO.saveRolePermissionRefs(id, entity);
|
||||
return entity;
|
||||
return find(id).orElseThrow(DataNotExistException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +99,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
||||
this.roleMenuRefDAO.saveRoleMenuRefs(id, entity);
|
||||
this.rolePermissionRefDAO.clearRolePermissionRefs(entity);
|
||||
this.rolePermissionRefDAO.saveRolePermissionRefs(id, entity);
|
||||
return entity;
|
||||
return find(entity.getId().orElseThrow()).orElseThrow(DataNotExistException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user