Skip to content

Commit a4435ae

Browse files
committed
Improve error messages
1 parent ba65ff9 commit a4435ae

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/command/MappedObjectProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import java.util.Map;
88
import java.util.Objects;
99
import java.util.function.Function;
10+
import org.seasar.doma.DomaException;
1011
import org.seasar.doma.internal.jdbc.command.AbstractObjectProvider;
1112
import org.seasar.doma.jdbc.JdbcMappingVisitor;
1213
import org.seasar.doma.jdbc.criteria.def.PropertyDef;
1314
import org.seasar.doma.jdbc.criteria.statement.Row;
1415
import org.seasar.doma.jdbc.entity.Property;
1516
import org.seasar.doma.jdbc.query.Query;
17+
import org.seasar.doma.message.Message;
1618

1719
public class MappedObjectProvider<RESULT> extends AbstractObjectProvider<RESULT> {
1820
private final Function<Row, RESULT> mapper;
@@ -42,8 +44,7 @@ public RESULT get(ResultSet resultSet) throws SQLException {
4244
public <PROPERTY> PROPERTY get(PropertyDef<PROPERTY> propertyDef) {
4345
Integer index = indexMap.get(propertyDef);
4446
if (index == null) {
45-
throw new IllegalArgumentException(
46-
"The propertyDef is unknown. " + propertyDef.getName());
47+
throw new DomaException(Message.DOMA6002, propertyDef.getName());
4748
}
4849
Property<?, ?> property = propertyDef.asType().createProperty();
4950
try {

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/declaration/SelectFromDeclaration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.function.BiConsumer;
66
import java.util.function.Consumer;
77
import java.util.function.Function;
8+
import org.seasar.doma.DomaException;
89
import org.seasar.doma.internal.util.Pair;
910
import org.seasar.doma.jdbc.criteria.context.ForUpdate;
1011
import org.seasar.doma.jdbc.criteria.context.Join;
@@ -14,6 +15,7 @@
1415
import org.seasar.doma.jdbc.criteria.def.EntityDef;
1516
import org.seasar.doma.jdbc.criteria.def.PropertyDef;
1617
import org.seasar.doma.jdbc.criteria.statement.Row;
18+
import org.seasar.doma.message.Message;
1719

1820
public class SelectFromDeclaration {
1921

@@ -106,12 +108,10 @@ public <ENTITY1, ENTITY2> void associate(
106108
Objects.requireNonNull(second);
107109
Objects.requireNonNull(associator);
108110
if (!context.getEntityDefs().contains(first)) {
109-
throw new IllegalStateException(
110-
"The first is unknown. Ensure that you have added its constructor to the from function or the join functions.");
111+
throw new DomaException(Message.DOMA6001, "first");
111112
}
112113
if (!context.getEntityDefs().contains(second)) {
113-
throw new IllegalStateException(
114-
"The second is unknown. Ensure that you have added its constructor to the from function or the join functions.");
114+
throw new DomaException(Message.DOMA6001, "second");
115115
}
116116
//noinspection unchecked
117117
context.associations.put(new Pair<>(first, second), (BiConsumer<Object, Object>) associator);

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/query/BuilderSupport.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Objects;
55
import java.util.function.Consumer;
66
import java.util.function.Function;
7+
import org.seasar.doma.DomaException;
78
import org.seasar.doma.internal.jdbc.sql.PreparedSqlBuilder;
89
import org.seasar.doma.jdbc.Config;
910
import org.seasar.doma.jdbc.InParameter;
@@ -16,6 +17,7 @@
1617
import org.seasar.doma.jdbc.criteria.def.PropertyDef;
1718
import org.seasar.doma.jdbc.entity.EntityPropertyType;
1819
import org.seasar.doma.jdbc.entity.EntityType;
20+
import org.seasar.doma.message.Message;
1921

2022
public class BuilderSupport {
2123
private final Config config;
@@ -46,7 +48,7 @@ public void table(EntityDef<?> entityDef) {
4648
buf.appendSql(" ");
4749
String alias = aliasManager.getAlias(entityDef);
4850
if (alias == null) {
49-
throw new IllegalStateException("The alias is not found. " + entityType.getName());
51+
throw new DomaException(Message.DOMA6003, entityType.getName());
5052
}
5153
buf.appendSql(alias);
5254
}
@@ -65,7 +67,7 @@ public void column(PropertyDef<?> propertyDef) {
6567
if (aliasManager != null) {
6668
String alias = aliasManager.getAlias(p);
6769
if (alias == null) {
68-
throw new IllegalStateException("The alias is not found. " + p.getName());
70+
throw new DomaException(Message.DOMA6004, p.getName());
6971
}
7072
buf.appendSql(alias);
7173
buf.appendSql(".");

doma-core/src/main/java/org/seasar/doma/message/Message.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,14 @@ public enum Message implements MessageResource {
923923
+ "If the JDBC driver is not loaded automatically, load it explicitly using Class.forName. "
924924
+ "ex) Class.forName(\"oracle.jdbc.driver.OracleDriver\")"),
925925
DOMA5002("The url property is not specified."),
926+
927+
// criteria
928+
DOMA6001(
929+
"The parameter \"{0}\" is unknown. Ensure that you have passed it to the \"from\" method or the \"join\" method."),
930+
DOMA6002(
931+
"The propertyDef \"{0}\" is unknown. Ensure that you have passed it to the \"select\" method."),
932+
DOMA6003("The table alias is not found for the entityDef \"{0}\"."),
933+
DOMA6004("The column alias is not found for the propertyDef \"{0}\"."),
926934
;
927935

928936
private final String messagePattern;

0 commit comments

Comments
 (0)