改造 exists 相关方法。

pull/1/head
ZhouXY108 2023-02-16 14:35:10 +08:00
parent cbc2711540
commit f70e9575ea
5 changed files with 11 additions and 13 deletions

View File

@ -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 <T> Stream<T> queryForStream(String sql, String paramName, Object value, Class<T> 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) {

View File

@ -93,25 +93,25 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
@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());
}

View File

@ -81,7 +81,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> 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));
}

View File

@ -113,7 +113,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> 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);
}

View File

@ -58,7 +58,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> 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);
}