diff options
author | James Moger <james.moger@gmail.com> | 2012-01-04 22:12:56 -0500 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2012-01-04 22:12:56 -0500 |
commit | 0932e559b420d46f8394a464c466804c1df0ede1 (patch) | |
tree | 822a49e35ce8ff3d7dd37cff84cf9e19bce0e6ae /src/com/iciql | |
parent | cc0c4f0e0b632ebfb1635e5ed2fe9a2119240157 (diff) | |
download | iciql-0932e559b420d46f8394a464c466804c1df0ede1.tar.gz iciql-0932e559b420d46f8394a464c466804c1df0ede1.zip |
Disallow multiple instances of an enum within a model class
Diffstat (limited to 'src/com/iciql')
-rw-r--r-- | src/com/iciql/Query.java | 5 | ||||
-rw-r--r-- | src/com/iciql/QueryWhere.java | 8 | ||||
-rw-r--r-- | src/com/iciql/TableDefinition.java | 25 |
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);
}
}
|