From f70e9575eae53e505c4ce2551dff6ea19606746c Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 16 Feb 2023 14:35:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E9=80=A0=20exists=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java | 10 ++++------ .../domain/model/account/AccountRepositoryImpl.java | 8 ++++---- .../system/domain/model/dict/DictRepositoryImpl.java | 2 +- .../system/domain/model/menu/MenuRepositoryImpl.java | 2 +- .../system/domain/model/role/RoleRepositoryImpl.java | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java index aedc55a..95cb1ef 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/PlusoneJdbcDaoSupport.java @@ -1,6 +1,5 @@ package xyz.zhouxy.plusone.jdbc; -import java.sql.ResultSet; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -66,17 +65,16 @@ public abstract class PlusoneJdbcDaoSupport { } protected final Stream queryForStream(String sql, String paramName, Object value, Class elementType) { - return this.jdbc.queryForList(sql, new MapSqlParameterSource(paramName, value), elementType).stream(); + return queryForStream(sql, new MapSqlParameterSource(paramName, value), elementType); } protected final boolean queryExists(String sql, SqlParameterSource parameterSource) { - Boolean isExists = this.jdbc.query(sql, parameterSource, ResultSet::next); + Boolean isExists = this.jdbc.queryForObject(sql, parameterSource, Boolean.TYPE); return Boolean.TRUE.equals(isExists); } protected final boolean queryExists(String sql, String paramName, Object value) { - Boolean isExists = this.jdbc.query(sql, new MapSqlParameterSource(paramName, value), ResultSet::next); - return Boolean.TRUE.equals(isExists); + return queryExists(sql, new MapSqlParameterSource(paramName, value)); } protected final int update(String sql, SqlParameterSource parameterSource) { @@ -84,7 +82,7 @@ public abstract class PlusoneJdbcDaoSupport { } protected final int update(String sql, String paramName, Object value) { - return this.jdbc.update(sql, new MapSqlParameterSource(paramName, value)); + return update(sql, new MapSqlParameterSource(paramName, value)); } protected final int batchUpdate(String sql, SqlParameterSource[] batchArgs) { diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java index 5a8174f..7156d63 100644 --- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java +++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/AccountRepositoryImpl.java @@ -93,25 +93,25 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport @Override public boolean exists(Long id) { - return queryExists("SELECT 1 FROM sys_account WHERE id = :id AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE id = :id AND deleted = 0 LIMIT 1)", "id", id); } @Override public boolean existsUsername(Username username) { - return queryExists("SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)", "username", username.value()); } @Override public boolean existsEmail(Email email) { - return queryExists("SELECT 1 FROM sys_account WHERE email = :email AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE email = :email AND deleted = 0 LIMIT 1)", "email", email.value()); } @Override public boolean existsMobilePhone(MobilePhone mobilePhone) { - return queryExists("SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1)", "mobile_phone", mobilePhone.value()); } diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java index 98e5fe3..08a428b 100644 --- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java +++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/dict/DictRepositoryImpl.java @@ -81,7 +81,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport implem @Override public boolean exists(Long id) { - return queryExists("SELECT 1 FROM sys_dict_type WHERE id = :id AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_dict_type WHERE id = :id AND deleted = 0 LIMIT 1)", new MapSqlParameterSource("id", id)); } diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java index 895bd49..b2bea61 100644 --- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java +++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/menu/MenuRepositoryImpl.java @@ -113,7 +113,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport implem @Override public boolean exists(Long id) { - return queryExists("SELECT 1 FROM sys_menu WHERE id = :id AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_menu WHERE id = :id AND deleted = 0 LIMIT 1)", "id", id); } diff --git a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/role/RoleRepositoryImpl.java b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/role/RoleRepositoryImpl.java index 8bf24ac..8b08f6d 100644 --- a/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/role/RoleRepositoryImpl.java +++ b/plusone-system/plusone-system-infrastructure/src/main/java/xyz/zhouxy/plusone/system/domain/model/role/RoleRepositoryImpl.java @@ -58,7 +58,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport implem @Override public boolean exists(Long id) { - return queryExists("SELECT 1 FROM sys_role WHERE id = :id AND deleted = 0 LIMIT 1", + return queryExists("SELECT EXISTS (SELECT 1 FROM sys_role WHERE id = :id AND deleted = 0 LIMIT 1)", "id", id); }