Refactor mybatis data access cud operation excepted class.
This commit is contained in:
@@ -8,11 +8,11 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
public final class MybatisAccountRepository implements AccountRepository, AccountReader {
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
private static final String SAVE_FQCN = "com.yam.app.account.domain.AccountRepository.save";
|
||||
private static final String UPDATE_FQCN = "com.yam.app.account.domain.AccountRepository.update";
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
public MybatisAccountRepository(SqlSessionTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
@@ -26,8 +26,8 @@ public final class MybatisAccountRepository implements AccountRepository, Accoun
|
||||
public void update(Account entity) {
|
||||
int result = template.update(UPDATE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem updating the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were updated than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ public final class MybatisAccountRepository implements AccountRepository, Accoun
|
||||
public void save(Account entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem saving the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
public final class MybatisArticleRepository implements ArticleReader, ArticleRepository {
|
||||
|
||||
private static final String SAVE_FQCN = "com.yam.app.article.domain.ArticleRepository.save";
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
public MybatisArticleRepository(SqlSessionTemplate template) {
|
||||
@@ -19,8 +20,8 @@ public final class MybatisArticleRepository implements ArticleReader, ArticleRep
|
||||
public void save(Article entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem saving the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
public final class MybatisArticleTagRepository implements ArticleTagRepository {
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
private static final String SAVE_FQCN = "com.yam.app.article.domain.ArticleTagRepository.save";
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
public MybatisArticleTagRepository(SqlSessionTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
@@ -18,8 +18,8 @@ public final class MybatisArticleTagRepository implements ArticleTagRepository {
|
||||
public void save(ArticleTag entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem saving the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
public final class MybatisTagRepository implements TagRepository {
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
private static final String SAVE_FQCN = "com.yam.app.article.domain.TagRepository.save";
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
public MybatisTagRepository(SqlSessionTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
@@ -18,8 +18,8 @@ public final class MybatisTagRepository implements TagRepository {
|
||||
public void save(Tag entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem saving the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ public final class MybatisCommentRepository implements CommentReader, CommentRep
|
||||
private static final String SAVE_FQCN = "com.yam.app.comment.domain.CommentRepository.save";
|
||||
private static final String UPDATE_FQCN = "com.yam.app.comment.domain.CommentRepository.update";
|
||||
private static final String DELETE_FQCN = "com.yam.app.comment.domain.CommentRepository.delete";
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
public MybatisCommentRepository(SqlSessionTemplate template) {
|
||||
@@ -22,9 +23,8 @@ public final class MybatisCommentRepository implements CommentReader, CommentRep
|
||||
public Long save(Comment entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Unintentionally, more records were saved than expected. : %s",
|
||||
entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
|
||||
return entity.getId();
|
||||
@@ -34,9 +34,8 @@ public final class MybatisCommentRepository implements CommentReader, CommentRep
|
||||
public void update(Comment entity) {
|
||||
int result = template.update(UPDATE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Unintentionally, more records were updated than expected. : %s",
|
||||
entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were updated than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,9 +43,8 @@ public final class MybatisCommentRepository implements CommentReader, CommentRep
|
||||
public void delete(Comment entity) {
|
||||
int result = template.update(DELETE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new IllegalStateException(
|
||||
String.format("Unintentionally, more records were soft-deleted than expected. : %s",
|
||||
entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were soft-deleted than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
public final class MybatisMemberRepository implements MemberRepository, MemberReader {
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
private static final String SAVE_FQCN = "com.yam.app.member.domain.MemberRepository.save";
|
||||
private static final String UPDATE_FQCN = "com.yam.app.member.domain.MemberRepository.update";
|
||||
|
||||
private final SqlSessionTemplate template;
|
||||
|
||||
public MybatisMemberRepository(SqlSessionTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
@@ -31,8 +31,8 @@ public final class MybatisMemberRepository implements MemberRepository, MemberRe
|
||||
public void save(Member entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem saving the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were saved than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public final class MybatisMemberRepository implements MemberRepository, MemberRe
|
||||
public void update(Member entity) {
|
||||
int result = template.update(UPDATE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem updating the object : %s", entity));
|
||||
throw new IllegalStateException(String.format(
|
||||
"Unintentionally, more records were updated than expected. : %s", entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user