From 79466d180f9f975ea5ef6f0703e722459c023578 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 29 Jun 2023 01:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/jdbc/JdbcRepositorySupport.java | 19 ++++++++++--------- .../domain/model/dict/DictRepositoryImpl.java | 14 +++++++------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcRepositorySupport.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcRepositorySupport.java index 4969790..2de90d2 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcRepositorySupport.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/jdbc/JdbcRepositorySupport.java @@ -8,6 +8,9 @@ import javax.annotation.Nonnull; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; +import com.google.common.base.Preconditions; + +import xyz.zhouxy.plusone.commons.annotation.Overridable; import xyz.zhouxy.plusone.domain.AggregateRoot; import xyz.zhouxy.plusone.domain.IRepository; @@ -19,35 +22,33 @@ public abstract class JdbcRepositorySupport, ID exte super(namedParameterJdbcTemplate); } + @Overridable protected abstract void doDelete(@Nonnull T entity); + @Overridable protected abstract Optional doFindById(@Nonnull ID id); + @Overridable protected abstract T doInsert(@Nonnull T entity); + @Overridable protected abstract T doUpdate(@Nonnull T entity); @Override public final void delete(T entity) { - if (entity == null) { - throw new IllegalArgumentException("Cannot delete null."); - } + Preconditions.checkArgument(entity != null, "Cannot delete null."); doDelete(entity); } @Override public final Optional find(ID id) { - if (id == null) { - throw new IllegalArgumentException("Id cannot be null."); - } + Preconditions.checkArgument(id != null, "Id cannot be null."); return doFindById(id); } @Override public final T save(T entity) { - if (entity == null) { - throw new IllegalArgumentException("Cannot save null."); - } + Preconditions.checkArgument(entity != null, "Cannot save null."); return entity.getId().isPresent() ? doUpdate(entity) : doInsert(entity); } 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 482b039..e66f78a 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 @@ -7,6 +7,7 @@ import java.sql.SQLException; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; +import java.util.Set; import javax.annotation.Nonnull; @@ -94,13 +95,12 @@ public class DictRepositoryImpl extends JdbcRepositorySupport implem @Override protected final Dict mapRow(ResultSet rs) throws SQLException { - long id = rs.getLong("id"); - return new Dict( - id, - rs.getString("dict_type"), - rs.getString("dict_label"), - this.dictValueDAO.selectDictValuesByDictId(id), - rs.getLong("version")); + final long id = rs.getLong("id"); + final String dictType = rs.getString("dict_type"); + final String dictLabel = rs.getString("dict_label"); + final Set values = this.dictValueDAO.selectDictValuesByDictId(id); + final long version = rs.getLong("version"); + return new Dict(id, dictType, dictLabel, values, version); } @Override