aboutsummaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/iciql/Query.java5
-rw-r--r--src/com/iciql/QueryWhere.java8
-rw-r--r--src/com/iciql/TableDefinition.java25
3 files changed, 37 insertions, 1 deletions
diff --git a/src/com/iciql/Query.java b/src/com/iciql/Query.java
index a8aa8b2..e656c0d 100644
--- a/src/com/iciql/Query.java
+++ b/src/com/iciql/Query.java
@@ -176,6 +176,7 @@ public class Query<T> {
}
public <A> UpdateColumnSet<T, A> set(A field) {
+ from.getAliasDefinition().checkMultipleEnums(field);
return new UpdateColumnSet<T, A>(this, field);
}
@@ -453,6 +454,7 @@ public class Query<T> {
* @return a query condition to continue building the condition
*/
public <A> QueryCondition<T, A> where(A x) {
+ from.getAliasDefinition().checkMultipleEnums(x);
return new QueryCondition<T, A>(this, x);
}
@@ -551,6 +553,7 @@ public class Query<T> {
}
public Query<T> orderBy(Object expr) {
+ from.getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(this, expr, false, false, false);
addOrderBy(e);
return this;
@@ -566,6 +569,7 @@ public class Query<T> {
public Query<T> orderBy(Object... expressions) {
for (Object expr : expressions) {
+ from.getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(this, expr, false, false, false);
addOrderBy(e);
}
@@ -616,6 +620,7 @@ public class Query<T> {
}
public Query<T> groupBy(Object expr) {
+ from.getAliasDefinition().checkMultipleEnums(expr);
groupByExpressions.add(expr);
return this;
}
diff --git a/src/com/iciql/QueryWhere.java b/src/com/iciql/QueryWhere.java
index 0a07c40..7503ea1 100644
--- a/src/com/iciql/QueryWhere.java
+++ b/src/com/iciql/QueryWhere.java
@@ -130,6 +130,7 @@ public class QueryWhere<T> {
* @return a query condition to continue building the condition
*/
public <A> QueryCondition<T, A> and(A x) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(x);
query.addConditionToken(ConditionAndOr.AND);
return new QueryCondition<T, A>(query, x);
}
@@ -220,6 +221,7 @@ public class QueryWhere<T> {
* @return a query condition to continue building the condition
*/
public <A> QueryCondition<T, A> or(A x) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(x);
query.addConditionToken(ConditionAndOr.OR);
return new QueryCondition<T, A>(query, x);
}
@@ -377,6 +379,7 @@ public class QueryWhere<T> {
}
public QueryWhere<T> orderBy(Object field) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(field);
query.orderBy(field);
return this;
}
@@ -395,30 +398,35 @@ public class QueryWhere<T> {
}
public QueryWhere<T> orderByNullsFirst(Object expr) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(query, expr, false, true, false);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByNullsLast(Object expr) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(query, expr, false, false, true);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByDesc(Object expr) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(query, expr, true, false, false);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByDescNullsFirst(Object expr) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(query, expr, true, true, false);
query.addOrderBy(e);
return this;
}
public QueryWhere<T> orderByDescNullsLast(Object expr) {
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);
OrderExpression<T> e = new OrderExpression<T>(query, expr, true, false, true);
query.addOrderBy(e);
return this;
diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java
index f7bbc13..b85b941 100644
--- a/src/com/iciql/TableDefinition.java
+++ b/src/com/iciql/TableDefinition.java
@@ -415,7 +415,30 @@ public class TableDefinition<T> {
void checkMultipleBooleans() {
if (multiplePrimitiveBools) {
throw new IciqlException(
- "Can not explicitly reference multiple primitive booleans in a model class!");
+ "Can not explicitly reference a primitive boolean if there are multiple boolean fields in your model class!");
+ }
+ }
+
+ void checkMultipleEnums(Object o) {
+ if (o == null) {
+ return;
+ }
+ Class<?> clazz = o.getClass();
+ if (!clazz.isEnum()) {
+ return;
+ }
+
+ int fieldCount = 0;
+ for (FieldDefinition fieldDef : fields) {
+ Class<?> targetType = fieldDef.field.getType();
+ if (clazz.equals(targetType)) {
+ fieldCount++;
+ }
+ }
+
+ if (fieldCount > 1) {
+ throw new IciqlException(
+ "Can not explicitly reference {0} because there are {1} {0} fields in your model class!", clazz.getSimpleName(), fieldCount);
}
}