]> source.dussan.org Git - iciql.git/commitdiff
Finished enum query support (issue 4)
authorJames Moger <james.moger@gmail.com>
Sun, 7 Aug 2011 19:53:18 +0000 (15:53 -0400)
committerJames Moger <james.moger@gmail.com>
Sun, 7 Aug 2011 19:53:18 +0000 (15:53 -0400)
15 files changed:
src/com/iciql/Condition.java
src/com/iciql/Function.java
src/com/iciql/OrderExpression.java
src/com/iciql/Query.java
src/com/iciql/QueryCondition.java
src/com/iciql/SQLStatement.java
src/com/iciql/TableDefinition.java
src/com/iciql/TestCondition.java
src/com/iciql/UpdateColumnIncrement.java
src/com/iciql/UpdateColumnSet.java
src/com/iciql/bytecode/Variable.java
src/com/iciql/util/Utils.java
tests/com/iciql/test/ModelsTest.java
tests/com/iciql/test/models/EnumModels.java [new file with mode: 0644]
tests/com/iciql/test/models/SupportedTypes.java

index df6b033fa13b241d07a73872860c69c0d5f4736c..df9762a6f858c5277334e995eee214ad99cede04 100644 (file)
@@ -35,12 +35,12 @@ class Condition<A> implements Token {
        }\r
 \r
        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
-               query.appendSQL(stat, x);\r
+               query.appendSQL(stat, null, x);\r
                stat.appendSQL(" ");\r
                stat.appendSQL(compareType.getString());\r
                if (compareType.hasRightExpression()) {\r
                        stat.appendSQL(" ");\r
-                       query.appendSQL(stat, y);\r
+                       query.appendSQL(stat, x, y);\r
                }\r
        }\r
 }\r
index f2c9e3093ba7c39112909bbc79676061a8b62d17..f07a5eae1fd3fd0a8e23608d3644ac4e62397638 100644 (file)
@@ -42,7 +42,7 @@ public class Function implements Token {
                        if (i++ > 0) {\r
                                stat.appendSQL(",");\r
                        }\r
-                       query.appendSQL(stat, o);\r
+                       query.appendSQL(stat, null, o);\r
                }\r
                stat.appendSQL(")");\r
        }\r
@@ -67,7 +67,7 @@ public class Function implements Token {
        public static Boolean isNull(Object x) {\r
                return Db.registerToken(Utils.newObject(Boolean.class), new Function("", x) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" IS NULL");\r
                        }\r
                });\r
@@ -76,7 +76,7 @@ public class Function implements Token {
        public static Boolean isNotNull(Object x) {\r
                return Db.registerToken(Utils.newObject(Boolean.class), new Function("", x) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" IS NOT NULL");\r
                        }\r
                });\r
@@ -86,7 +86,7 @@ public class Function implements Token {
                return Db.registerToken(Utils.newObject(Boolean.class), new Function("", x) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("NOT ");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                        }\r
                });\r
        }\r
@@ -99,7 +99,7 @@ public class Function implements Token {
                                        if (i++ > 0) {\r
                                                stat.appendSQL(" OR ");\r
                                        }\r
-                                       query.appendSQL(stat, o);\r
+                                       query.appendSQL(stat, null, o);\r
                                }\r
                        }\r
                });\r
@@ -113,7 +113,7 @@ public class Function implements Token {
                                        if (i++ > 0) {\r
                                                stat.appendSQL(" AND ");\r
                                        }\r
-                                       query.appendSQL(stat, o);\r
+                                       query.appendSQL(stat, null, o);\r
                                }\r
                        }\r
                });\r
@@ -138,9 +138,9 @@ public class Function implements Token {
                return Db.registerToken(o, new Function("LIKE", x, pattern) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" LIKE ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
index 36acf160e0845513f9c5264512899f6f9bcacf83..f450bfba033c59d2ba06ad9e27ff8ed95efafd95 100644 (file)
@@ -40,7 +40,7 @@ class OrderExpression<T> {
        }\r
 \r
        void appendSQL(SQLStatement stat) {\r
-               query.appendSQL(stat, expression);\r
+               query.appendSQL(stat, null, expression);\r
                if (desc) {\r
                        stat.appendSQL(" DESC");\r
                }\r
index b6018ea64fba7b018cb27693e3735948cebbd8a0..c44cac793aa6de1947e6a175d8d19649a00746c7 100644 (file)
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.IdentityHashMap;\r
 import java.util.List;\r
 \r
+import com.iciql.Iciql.EnumType;\r
 import com.iciql.bytecode.ClassReader;\r
 import com.iciql.util.JdbcUtils;\r
 import com.iciql.util.StatementLogger;\r
@@ -213,7 +214,7 @@ public class Query<T> {
        @SuppressWarnings("unchecked")\r
        private <X> List<X> selectSimple(X x, boolean distinct) {\r
                SQLStatement stat = getSelectStatement(distinct);\r
-               appendSQL(stat, x);\r
+               appendSQL(stat, null, x);\r
                appendFromWhere(stat);\r
                ResultSet rs = stat.executeQuery();\r
                List<X> result = Utils.newArrayList();\r
@@ -343,26 +344,36 @@ public class Query<T> {
         * \r
         * @param stat\r
         *            the statement\r
-        * @param x\r
-        *            the alias object\r
+        * @param alias\r
+        *            the alias object (can be null)\r
+        * @param value\r
+        *            the value\r
         */\r
-       public void appendSQL(SQLStatement stat, Object x) {\r
-               if (x == Function.count()) {\r
+       public void appendSQL(SQLStatement stat, Object alias, Object value) {\r
+               if (value == Function.count()) {\r
                        stat.appendSQL("COUNT(*)");\r
                        return;\r
                }\r
-               Token token = Db.getToken(x);\r
+               Token token = Db.getToken(value);\r
                if (token != null) {\r
                        token.appendSQL(stat, this);\r
                        return;\r
                }\r
-               SelectColumn<T> col = aliasMap.get(x);\r
+               SelectColumn<T> col = aliasMap.get(value);\r
                if (col != null) {\r
                        col.appendSQL(stat);\r
                        return;\r
                }\r
                stat.appendSQL("?");\r
-               stat.addParameter(x);\r
+               if (alias != null && value.getClass().isEnum()) {\r
+                       col = aliasMap.get(alias);\r
+                       EnumType type = col.getFieldDefinition().enumType;\r
+                       Enum<?> anEnum = (Enum<?>) value;\r
+                       Object y = Utils.convertEnum(anEnum, type);\r
+                       stat.addParameter(y);\r
+               } else {\r
+                       stat.addParameter(value);\r
+               }\r
        }\r
 \r
        void addConditionToken(Token condition) {\r
@@ -397,7 +408,7 @@ public class Query<T> {
                                if (i++ > 0) {\r
                                        stat.appendSQL(", ");\r
                                }\r
-                               appendSQL(stat, obj);\r
+                               appendSQL(stat, null, obj);\r
                                stat.appendSQL(" ");\r
                        }\r
                }\r
index 8e7cd42c409509e95fda6f908ec14d43f6fbb673..9d139956f7981737a1a4bd574741e3e2595a3fc9 100644 (file)
@@ -41,6 +41,11 @@ public class QueryCondition<T, A> {
                return new QueryWhere<T>(query);
        }
 
+       public QueryWhere<T> isNot(A y) {
+               query.addConditionToken(new Condition<A>(x, y, CompareType.NOT_EQUAL));
+               return new QueryWhere<T>(query);
+       }
+
        public QueryWhere<T> exceeds(A y) {
                query.addConditionToken(new Condition<A>(x, y, CompareType.EXCEEDS));
                return new QueryWhere<T>(query);
@@ -60,7 +65,7 @@ public class QueryCondition<T, A> {
                query.addConditionToken(new Condition<A>(x, y, CompareType.AT_MOST));
                return new QueryWhere<T>(query);
        }
-
+       
        public QueryWhere<T> like(A pattern) {
                query.addConditionToken(new Condition<A>(x, pattern, CompareType.LIKE));
                return new QueryWhere<T>(query);
index b6c5e18c8f6e1c20ac449c128a2b22832cf4c157..3a7c901d239f0cd1bcd4e36275c3240bb45b4655 100644 (file)
@@ -63,7 +63,7 @@ public class SQLStatement {
                }\r
                return sql;\r
        }\r
-\r
+       \r
        SQLStatement addParameter(Object o) {\r
                params.add(o);\r
                return this;\r
index 5d9b9c4a0d41d5754075d3cad3b47d60a9818c17..f0ee4fafe7ab1a2477691a51d8d429d02f2d5972 100644 (file)
@@ -705,7 +705,7 @@ class TableDefinition<T> {
                        }\r
                        FieldDefinition def = fields.get(i);\r
                        Object obj = def.getValue(x);\r
-                       query.appendSQL(stat, obj);\r
+                       query.appendSQL(stat, x, obj);\r
                }\r
        }\r
 \r
index b4c1c15e72279aa2c45795c1f44aeadc82a01ab9..010f5a18708aec2ce6bdbc2d8bb8039f556818a5 100644 (file)
@@ -39,61 +39,61 @@ public class TestCondition<A> {
                return Db.registerToken(o, new Function("=", x, y) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" = ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
        }\r
 \r
-       public Boolean bigger(A y) {\r
+       public Boolean exceeds(A y) {\r
                Boolean o = Utils.newObject(Boolean.class);\r
                return Db.registerToken(o, new Function(">", x, y) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" > ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
        }\r
 \r
-       public Boolean biggerEqual(A y) {\r
+       public Boolean atLeast(A y) {\r
                Boolean o = Utils.newObject(Boolean.class);\r
                return Db.registerToken(o, new Function(">=", x, y) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" >= ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
        }\r
 \r
-       public Boolean smaller(A y) {\r
+       public Boolean lessThan(A y) {\r
                Boolean o = Utils.newObject(Boolean.class);\r
                return Db.registerToken(o, new Function("<", x, y) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" < ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
        }\r
 \r
-       public Boolean smallerEqual(A y) {\r
+       public Boolean atMost(A y) {\r
                Boolean o = Utils.newObject(Boolean.class);\r
                return Db.registerToken(o, new Function("<=", x, y) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" <= ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
@@ -104,9 +104,9 @@ public class TestCondition<A> {
                return Db.registerToken(o, new Function("LIKE", x, pattern) {\r
                        public <T> void appendSQL(SQLStatement stat, Query<T> query) {\r
                                stat.appendSQL("(");\r
-                               query.appendSQL(stat, x[0]);\r
+                               query.appendSQL(stat, null, x[0]);\r
                                stat.appendSQL(" LIKE ");\r
-                               query.appendSQL(stat, x[1]);\r
+                               query.appendSQL(stat, x[0], x[1]);\r
                                stat.appendSQL(")");\r
                        }\r
                });\r
index 43ef6d6f7cd8593ac7799015ffc6d44197dfdd22..143ce4840caf70a4e11df6a218292e7318c00f26 100644 (file)
@@ -44,11 +44,11 @@ public class UpdateColumnIncrement<T, A> implements UpdateColumn {
        }
 
        public void appendSQL(SQLStatement stat) {
-               query.appendSQL(stat, x);
+               query.appendSQL(stat, null, x);
                stat.appendSQL("=(");
-               query.appendSQL(stat, x);
+               query.appendSQL(stat, null, x);
                stat.appendSQL("+");
-               query.appendSQL(stat, y);
+               query.appendSQL(stat, x, y);
                stat.appendSQL(")");
        }
 
index 55d3790c365adc4b40b46abcbdf2cffe7d76d5da..f2322e339b178d9f4adae8893546ea5f5fb4f50e 100644 (file)
@@ -17,6 +17,7 @@
 
 package com.iciql;
 
+
 /**
  * This class represents "SET column = value" in an UPDATE statement.
  * 
@@ -44,9 +45,9 @@ public class UpdateColumnSet<T, A> implements UpdateColumn {
        }
 
        public void appendSQL(SQLStatement stat) {
-               query.appendSQL(stat, x);
-               stat.appendSQL("=?");
-               stat.addParameter(y);
+               query.appendSQL(stat, null, x);
+               stat.appendSQL("=");
+               query.appendSQL(stat, x, y);
        }
 
 }
index 34123490b3efa484a49c3ab53bfe3a9ab4e1df4a..f3dbc017cf24a289af0cafb7d68643077a521c75 100644 (file)
@@ -45,7 +45,7 @@ public class Variable implements Token {
        }
 
        public <T> void appendSQL(SQLStatement stat, Query<T> query) {
-               query.appendSQL(stat, obj);
+               query.appendSQL(stat, null, obj);
        }
 
 }
index dac30fcdb643c13c563debf73a3b9c0a3a18efb6..b8e2d600fb60a22d1fea42f06405bbc938763169 100644 (file)
@@ -275,6 +275,25 @@ public class Utils {
                throw new IciqlException("Can not convert the value {0} from {1} to {2}", o, currentType, targetType);\r
        }\r
 \r
+       public static Object convertEnum(Enum<?> o, EnumType type) {\r
+               if (o == null || type == null) {\r
+                       return null;\r
+               }\r
+               switch (type) {\r
+               case ORDINAL:\r
+                       return o.ordinal();\r
+               case ENUMID:\r
+                       if (!EnumId.class.isAssignableFrom(o.getClass())) {\r
+                               throw new IciqlException("Can not convert the enum {0} using ENUMID", o);\r
+                       }\r
+                       EnumId enumid = (EnumId) o;\r
+                       return enumid.enumId();\r
+               case STRING:\r
+               default:\r
+                       return o.name();\r
+               }\r
+       }\r
+\r
        public static Object convertEnum(Object o, Class<?> targetType, EnumType type) {\r
                if (o == null) {\r
                        return null;\r
index 8fbf219403c6e64e13c147c6961de81eeb4addc5..acaf63481c5c960c9a8759a4ae4011c4b7c7e8eb 100644 (file)
@@ -36,11 +36,17 @@ import com.iciql.DbUpgrader;
 import com.iciql.DbVersion;
 import com.iciql.Iciql.IQVersion;
 import com.iciql.ValidationRemark;
+import com.iciql.test.models.EnumModels;
+import com.iciql.test.models.EnumModels.EnumIdModel;
+import com.iciql.test.models.EnumModels.EnumOrdinalModel;
+import com.iciql.test.models.EnumModels.EnumStringModel;
+import com.iciql.test.models.EnumModels.Tree;
 import com.iciql.test.models.Product;
 import com.iciql.test.models.ProductAnnotationOnly;
 import com.iciql.test.models.ProductMixedAnnotation;
 import com.iciql.test.models.SupportedTypes;
 import com.iciql.test.models.SupportedTypes.SupportedTypes2;
+import com.iciql.util.StatementLogger;
 
 /**
  * Test that the mapping between classes and tables is done correctly.
@@ -59,7 +65,7 @@ public class ModelsTest {
        private void log(String text) {
                System.out.println(text);
        }
-       
+
        @Before
        public void setUp() {
                db = Db.open("jdbc:h2:mem:", "sa", "sa");
@@ -106,6 +112,39 @@ public class ModelsTest {
                }
        }
 
+       @Test
+       public void testEnumQueries() {
+               StatementLogger.activateConsoleLogger();
+               testIntEnums(new EnumIdModel(), EnumIdModel.createList());
+               testIntEnums(new EnumOrdinalModel(), EnumOrdinalModel.createList());
+               testStringEnums(new EnumStringModel(), EnumStringModel.createList());
+               StatementLogger.deactivateConsoleLogger();
+       }
+
+       private void testIntEnums(EnumModels e, List<?> models) {
+               db.insertAll(models);
+
+               EnumModels model = db.from(e).where(e.tree()).is(Tree.WALNUT).selectFirst();
+
+               assertEquals(400, model.id.intValue());
+               assertEquals(Tree.WALNUT, model.tree());
+
+               List<EnumModels> list = db.from(e).where(e.tree()).atLeast(Tree.BIRCH).select();
+               assertEquals(3, list.size());
+       }
+       
+       private void testStringEnums(EnumModels e, List<?> models) {
+               db.insertAll(models);
+
+               EnumModels model = db.from(e).where(e.tree()).is(Tree.WALNUT).selectFirst();
+
+               assertEquals(400, model.id.intValue());
+               assertEquals(Tree.WALNUT, model.tree());
+
+               List<EnumModels> list = db.from(e).where(e.tree()).isNot(Tree.BIRCH).select();
+               assertEquals(models.size() - 1, list.size());
+       }
+
        @Test
        public void testModelGeneration() {
                List<SupportedTypes> original = SupportedTypes.createList();
diff --git a/tests/com/iciql/test/models/EnumModels.java b/tests/com/iciql/test/models/EnumModels.java
new file mode 100644 (file)
index 0000000..bd9d88a
--- /dev/null
@@ -0,0 +1,153 @@
+/*\r
+ * Copyright 2011 James Moger.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package com.iciql.test.models;\r
+\r
+import java.util.Arrays;\r
+import java.util.List;\r
+\r
+import com.iciql.Iciql.EnumId;\r
+import com.iciql.Iciql.EnumType;\r
+import com.iciql.Iciql.IQColumn;\r
+import com.iciql.Iciql.IQEnum;\r
+import com.iciql.Iciql.IQTable;\r
+\r
+public abstract class EnumModels {\r
+\r
+       /**\r
+        * Test of @IQEnum annotated enumeration. This strategy is the default\r
+        * strategy for all fields of the Tree enum.\r
+        * \r
+        * Individual Tree field declarations can override this strategy by\r
+        * specifying a different @IQEnum annotation.\r
+        * \r
+        * Here ORDINAL specifies that this enum will be mapped to an INT column.\r
+        */\r
+       @IQEnum(EnumType.ENUMID)\r
+       public enum Tree implements EnumId {\r
+               PINE(10), OAK(20), BIRCH(30), WALNUT(40), MAPLE(50);\r
+\r
+               private int enumid;\r
+\r
+               Tree(int id) {\r
+                       this.enumid = id;\r
+               }\r
+\r
+               @Override\r
+               public int enumId() {\r
+                       return enumid;\r
+               }\r
+       }\r
+\r
+       @IQColumn(primaryKey = true)\r
+       public Integer id;\r
+       \r
+       public abstract Tree tree();\r
+\r
+       /**\r
+        * Test model for enum-as-enumid.\r
+        */\r
+       @IQTable(inheritColumns = true)\r
+       public static class EnumIdModel extends EnumModels {\r
+\r
+               // no need to specify ENUMID type as the enumeration definition\r
+               // specifies it.\r
+               @IQColumn\r
+               private Tree tree;\r
+\r
+               public EnumIdModel() {\r
+               }\r
+\r
+               public EnumIdModel(int id, Tree tree) {\r
+                       this.id = id;\r
+                       this.tree = tree;\r
+               }\r
+\r
+               @Override\r
+               public Tree tree() {\r
+                       return tree;\r
+               }\r
+\r
+               public static List<EnumIdModel> createList() {\r
+                       return Arrays.asList(new EnumIdModel(400, Tree.WALNUT), new EnumIdModel(200, Tree.OAK),\r
+                                       new EnumIdModel(500, Tree.MAPLE), new EnumIdModel(300, Tree.BIRCH), new EnumIdModel(100,\r
+                                                       Tree.PINE));\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Test model for enum-as-ordinal.\r
+        */\r
+       @IQTable(inheritColumns = true)\r
+       public static class EnumOrdinalModel extends EnumModels {\r
+\r
+               // override the enumtype to ordinal\r
+               @IQEnum(EnumType.ORDINAL)\r
+               @IQColumn\r
+               private Tree tree;\r
+\r
+               public EnumOrdinalModel() {\r
+               }\r
+\r
+               public EnumOrdinalModel(int id, Tree tree) {\r
+                       this.id = id;\r
+                       this.tree = tree;\r
+               }\r
+               \r
+               @Override\r
+               public Tree tree() {\r
+                       return tree;\r
+               }\r
+\r
+               public static List<EnumOrdinalModel> createList() {\r
+                       return Arrays.asList(new EnumOrdinalModel(400, Tree.WALNUT), new EnumOrdinalModel(200, Tree.OAK),\r
+                                       new EnumOrdinalModel(500, Tree.MAPLE), new EnumOrdinalModel(300, Tree.BIRCH),\r
+                                       new EnumOrdinalModel(100, Tree.PINE));\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Test model for enum-as-string.\r
+        */\r
+       @IQTable(inheritColumns = true)\r
+       public static class EnumStringModel extends EnumModels {\r
+\r
+               // override the enumtype to string\r
+               // ensure that we specify a length so that the column is VARCHAR\r
+               @IQEnum(EnumType.STRING)\r
+               @IQColumn(length = 25)\r
+               private Tree tree;\r
+\r
+               public EnumStringModel() {\r
+               }\r
+\r
+               public EnumStringModel(int id, Tree tree) {\r
+                       this.id = id;\r
+                       this.tree = tree;\r
+               }\r
+\r
+               @Override\r
+               public Tree tree() {\r
+                       return tree;\r
+               }\r
+               \r
+               public static List<EnumStringModel> createList() {\r
+                       return Arrays.asList(new EnumStringModel(400, Tree.WALNUT), new EnumStringModel(200, Tree.OAK),\r
+                                       new EnumStringModel(500, Tree.MAPLE), new EnumStringModel(300, Tree.BIRCH),\r
+                                       new EnumStringModel(100, Tree.PINE));\r
+               }\r
+       }\r
+}\r
index c8aebcb6d8043d44abd9175b9641120ca1aef06d..b8abf2dcc8fd1819bceed169e624450654af0029 100644 (file)
@@ -21,7 +21,6 @@ import java.math.BigDecimal;
 import java.util.List;
 import java.util.Random;
 
-import com.iciql.Iciql.EnumId;
 import com.iciql.Iciql.EnumType;
 import com.iciql.Iciql.IQColumn;
 import com.iciql.Iciql.IQEnum;
@@ -30,6 +29,7 @@ import com.iciql.Iciql.IQIndexes;
 import com.iciql.Iciql.IQTable;
 import com.iciql.Iciql.IQVersion;
 import com.iciql.Iciql.IndexType;
+import com.iciql.test.models.EnumModels.Tree;
 import com.iciql.util.Utils;
 
 /**
@@ -51,31 +51,6 @@ public class SupportedTypes {
                ROSE, TULIP, MUM, PETUNIA, MARIGOLD, DAFFODIL;
        }
 
-       /**
-        * Test of @IQEnum annotated enumeration. This strategy is the default
-        * strategy for all fields of the Tree enum.
-        * 
-        * Individual Tree field declarations can override this strategy by
-        * specifying a different @IQEnum annotation.
-        * 
-        * Here ORDINAL specifies that this enum will be mapped to an INT column.
-        */
-       @IQEnum(EnumType.ORDINAL)
-       public enum Tree implements EnumId {
-               PINE(10), OAK(20), BIRCH(30), WALNUT(40), MAPLE(50);
-
-               private int enumid;
-
-               Tree(int id) {
-                       this.enumid = id;
-               }
-
-               @Override
-               public int enumId() {
-                       return enumid;
-               }
-       }
-
        @IQColumn(primaryKey = true, autoIncrement = true)
        public Integer id;
 
@@ -129,14 +104,14 @@ public class SupportedTypes {
        @IQColumn
        private Flower myOtherFavoriteFlower;
 
-       @IQColumn(length = 25)
+       @IQEnum(EnumType.ORDINAL)
+       @IQColumn
+       // override the default enum strategy and use the ordinal value
+       private Tree myFavoriteTree;
+
        // @IQEnum is set on the enumeration definition and is shared
        // by all uses of Tree as an @IQColumn
-       private Tree myFavoriteTree;
-       
-       @IQEnum(EnumType.ENUMID)
        @IQColumn
-       // override the default enum strategy and use the custom enumid
        private Tree myOtherFavoriteTree;
 
        public static List<SupportedTypes> createList() {