Skip to content

Commit

Permalink
feat: SizeException 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
eunbii0213 committed Oct 13, 2023
1 parent 7b5306c commit ea2dcd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions jdbc/src/main/java/org/springframework/dao/SizeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.springframework.dao;

public class SizeException extends RuntimeException {

private static final long serialVersionUID = 1L;

public SizeException() {
super();
}

public SizeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public SizeException(String message, Throwable cause) {
super(message, cause);
}

public SizeException(String message) {
super(message);
}

public SizeException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import javax.sql.DataSource;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.SizeException;
import org.springframework.jdbc.datasource.DataSourceUtils;

public class JdbcTemplate {
Expand All @@ -26,7 +27,7 @@ public JdbcTemplate(final DataSource dataSource) {
public <T> T queryForObject(final String sql, final RowMapper<T> rowMapper, final Object... params) {
List<T> results = query(sql, rowMapper, params);
if (results.size() > 1) {
throw new DataAccessException("too many result. expected 1 but was " + results.size());
throw new SizeException("too many result. expected 1 but was " + results.size());
}
if (results.isEmpty()) {
throw new DataAccessException("no result");
Expand All @@ -37,7 +38,7 @@ public <T> T queryForObject(final String sql, final RowMapper<T> rowMapper, fina
public <T> T queryForObject(final Connection connection, final String sql, final RowMapper<T> rowMapper, final Object... params) {
List<T> results = query(connection, sql, rowMapper, params);
if (results.size() > 1) {
throw new DataAccessException("too many result. expected 1 but was " + results.size());
throw new SizeException("too many result. expected 1 but was " + results.size());
}
if (results.isEmpty()) {
throw new DataAccessException("no result");
Expand Down

0 comments on commit ea2dcd5

Please sign in to comment.