<td>TIMESTAMP</td></tr>\r
\r
<tr><td>java.lang.Enum.name()<br/>*default type*</td><td></td>\r
-<td>VARCHAR *(length > 0)* or CLOB *(length == 0)*<br/>*EnumType.NAME*</td></tr>\r
+<td>VARCHAR *(length > 0)* or CLOB *(length == 0)*<br/>*EnumType.NAME*<br/><i>can only **declare and explicitly reference** one instance of <u>each enum type</u> per model<br/>multiple instances of an enum type within a model is allowed if not using where/set/on/and/or/groupBy/orderBy(enum)</i></td></tr>\r
\r
<tr><td>java.lang.Enum.ordinal()</td><td></td>\r
-<td>INT<br/>*EnumType.ORDINAL*</td></tr>\r
+<td>INT<br/>*EnumType.ORDINAL*<br/><i>can only **declare and explicitly reference** one instance of <u>each enum type</u> per model<br/>multiple instances of an enum type within a model is allowed if not using where/set/on/and/or/groupBy/orderBy(enum)</i></td></tr>\r
\r
<tr><td>java.lang.Enum implements<br/>*com.iciql.Iciql.EnumId.enumId()*</td><td></td>\r
-<td>INT<br/>*EnumType.ENUMID*</td></tr>\r
+<td>INT<br/>*EnumType.ENUMID*<br/><i>can only **declare and explicitly reference** one instance of <u>each enum type</u> per model<br/>multiple instances of an enum type within a model is allowed if not using where/set/on/and/or/groupBy/orderBy(enum)</i></td></tr>\r
\r
<tr><td colspan="3"><b>Partially Supported Types</b><br/>\r
can not be directly referenced in an expression</td></tr>\r
\r
**%VERSION%** ([zip](http://code.google.com/p/iciql/downloads/detail?name=%ZIP%)|[jar](http://code.google.com/p/iciql/downloads/detail?name=%JAR%)) *released %BUILDDATE%*\r
\r
+- added *Query.toSQL()* and *QueryWhere.toSQL()* methods which, when combined with the following new methods, allows for generation of a parameterized, static sql string to be reused with a dynamic query or a PreparedStatement. \r
+ - QueryCondition.isParameter()\r
+ - QueryCondition.atLeastParameter()\r
+ - QueryCondition.atMostParameter()\r
+ - QueryCondition.exceedsParameter()\r
+ - QueryCondition.lessThanParameter()\r
+ - QueryCondition.likeParameter()\r
+ - QueryCondition.isNotParameter()\r
+- Disallow **declaring and explicitly referencing** multiple instances of an enum type within a single model.<br/>A runtime exception will be thrown if an attempt to use where/set/on/and/or/groupBy/orderBy(enum) and your model has multiple fields of a single enum type.\r
+\r
+**0.7.6** *released 2011-12-21*\r
+\r
- Iciql now tries to instantiate a default value from an annotated default value IFF the field object is null, it is specified *nullable = false*, and a defaultValue exists. This only applies to *db.insert* or *db.update*.\r
\r
**0.7.5** *released 2011-12-12*\r
}\r
\r
public <A> UpdateColumnSet<T, A> set(A field) {\r
+ from.getAliasDefinition().checkMultipleEnums(field);\r
return new UpdateColumnSet<T, A>(this, field);\r
}\r
\r
* @return a query condition to continue building the condition\r
*/\r
public <A> QueryCondition<T, A> where(A x) {\r
+ from.getAliasDefinition().checkMultipleEnums(x);\r
return new QueryCondition<T, A>(this, x);\r
}\r
\r
}\r
\r
public Query<T> orderBy(Object expr) {\r
+ from.getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(this, expr, false, false, false);\r
addOrderBy(e);\r
return this;\r
\r
public Query<T> orderBy(Object... expressions) {\r
for (Object expr : expressions) {\r
+ from.getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(this, expr, false, false, false);\r
addOrderBy(e);\r
}\r
}\r
\r
public Query<T> groupBy(Object expr) {\r
+ from.getAliasDefinition().checkMultipleEnums(expr);\r
groupByExpressions.add(expr);\r
return this;\r
}\r
* @return a query condition to continue building the condition\r
*/\r
public <A> QueryCondition<T, A> and(A x) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(x);\r
query.addConditionToken(ConditionAndOr.AND);\r
return new QueryCondition<T, A>(query, x);\r
}\r
* @return a query condition to continue building the condition\r
*/\r
public <A> QueryCondition<T, A> or(A x) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(x);\r
query.addConditionToken(ConditionAndOr.OR);\r
return new QueryCondition<T, A>(query, x);\r
}\r
}\r
\r
public QueryWhere<T> orderBy(Object field) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(field);\r
query.orderBy(field);\r
return this;\r
}\r
}\r
\r
public QueryWhere<T> orderByNullsFirst(Object expr) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(query, expr, false, true, false);\r
query.addOrderBy(e);\r
return this;\r
}\r
\r
public QueryWhere<T> orderByNullsLast(Object expr) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(query, expr, false, false, true);\r
query.addOrderBy(e);\r
return this;\r
}\r
\r
public QueryWhere<T> orderByDesc(Object expr) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(query, expr, true, false, false);\r
query.addOrderBy(e);\r
return this;\r
}\r
\r
public QueryWhere<T> orderByDescNullsFirst(Object expr) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(query, expr, true, true, false);\r
query.addOrderBy(e);\r
return this;\r
}\r
\r
public QueryWhere<T> orderByDescNullsLast(Object expr) {\r
+ query.getFrom().getAliasDefinition().checkMultipleEnums(expr);\r
OrderExpression<T> e = new OrderExpression<T>(query, expr, true, false, true);\r
query.addOrderBy(e);\r
return this;\r
void checkMultipleBooleans() {\r
if (multiplePrimitiveBools) {\r
throw new IciqlException(\r
- "Can not explicitly reference multiple primitive booleans in a model class!");\r
+ "Can not explicitly reference a primitive boolean if there are multiple boolean fields in your model class!");\r
+ }\r
+ }\r
+ \r
+ void checkMultipleEnums(Object o) {\r
+ if (o == null) {\r
+ return;\r
+ }\r
+ Class<?> clazz = o.getClass();\r
+ if (!clazz.isEnum()) {\r
+ return;\r
+ }\r
+ \r
+ int fieldCount = 0;\r
+ for (FieldDefinition fieldDef : fields) {\r
+ Class<?> targetType = fieldDef.field.getType();\r
+ if (clazz.equals(targetType)) {\r
+ fieldCount++;\r
+ }\r
+ }\r
+ \r
+ if (fieldCount > 1) {\r
+ throw new IciqlException(\r
+ "Can not explicitly reference {0} because there are {1} {0} fields in your model class!", clazz.getSimpleName(), fieldCount);\r
}\r
}\r
\r
package com.iciql.test;\r
\r
import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
\r
import java.util.List;\r
\r
import org.junit.Test;\r
\r
import com.iciql.Db;\r
+import com.iciql.IciqlException;\r
import com.iciql.test.models.EnumModels;\r
import com.iciql.test.models.EnumModels.EnumIdModel;\r
import com.iciql.test.models.EnumModels.EnumOrdinalModel;\r
list = db.from(e).where(e.tree()).between(Tree.MAPLE).and(Tree.PINE).select();\r
assertEquals(3, list.size());\r
}\r
+ \r
+ @Test\r
+ public void testMultipleEnumInstances() {\r
+ BadEnums b = new BadEnums();\r
+ try {\r
+ db.from(b).where(b.tree1).is(Tree.BIRCH).and (b.tree2).is(Tree.MAPLE).getSQL();\r
+ assertTrue("Failed to detect multiple Tree fields?!", false);\r
+ } catch (IciqlException e) {\r
+ assertTrue(e.getMessage(), e.getMessage().startsWith("Can not explicitly reference Tree"));\r
+ }\r
+ }\r
+ \r
+ public static class BadEnums {\r
+ Tree tree1 = Tree.BIRCH;\r
+ Tree tree2 = Tree.MAPLE;\r
+ }\r
}\r