diff options
author | James Moger <james.moger@gmail.com> | 2011-08-04 22:22:24 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-04 22:22:24 -0400 |
commit | a1ab11053107c8995b3f3e850fa14a2374c2013a (patch) | |
tree | 750b96cfd386187d2086760d9e1b716e77f785db /tests/com/iciql/test | |
parent | b055a2a49335c78fdc754e38a7e8ab863b2a5515 (diff) | |
download | iciql-a1ab11053107c8995b3f3e850fa14a2374c2013a.tar.gz iciql-a1ab11053107c8995b3f3e850fa14a2374c2013a.zip |
Customizable enumId() mapping (issue 2)
Diffstat (limited to 'tests/com/iciql/test')
-rw-r--r-- | tests/com/iciql/test/ModelsTest.java | 2 | ||||
-rw-r--r-- | tests/com/iciql/test/models/SupportedTypes.java | 27 |
2 files changed, 24 insertions, 5 deletions
diff --git a/tests/com/iciql/test/ModelsTest.java b/tests/com/iciql/test/ModelsTest.java index bafc3e0..716b1bc 100644 --- a/tests/com/iciql/test/ModelsTest.java +++ b/tests/com/iciql/test/ModelsTest.java @@ -115,7 +115,7 @@ public class ModelsTest { true); assertEquals(1, models.size()); // a poor test, but a start - assertEquals(1838, models.get(0).length()); + assertEquals(1904, models.get(0).length()); } @Test diff --git a/tests/com/iciql/test/models/SupportedTypes.java b/tests/com/iciql/test/models/SupportedTypes.java index bb5ecc6..97a8675 100644 --- a/tests/com/iciql/test/models/SupportedTypes.java +++ b/tests/com/iciql/test/models/SupportedTypes.java @@ -21,6 +21,7 @@ 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; @@ -51,8 +52,8 @@ public class SupportedTypes { } /** - * Test of @IQEnum annotated enumeration. - * This strategy is the default strategy for all fields of the Tree enum. + * 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. @@ -60,8 +61,19 @@ public class SupportedTypes { * Here ORDINAL specifies that this enum will be mapped to an INT column. */ @IQEnum(EnumType.ORDINAL) - public enum Tree { - PINE, OAK, BIRCH, WALNUT, MAPLE; + 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) @@ -121,6 +133,11 @@ public class SupportedTypes { // @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() { List<SupportedTypes> list = Utils.newArrayList(); @@ -150,6 +167,7 @@ public class SupportedTypes { s.myFavoriteFlower = Flower.MUM; s.myOtherFavoriteFlower = Flower.MARIGOLD; s.myFavoriteTree = Tree.BIRCH; + s.myOtherFavoriteTree = Tree.WALNUT; return s; } @@ -172,6 +190,7 @@ public class SupportedTypes { same &= myFavoriteFlower.equals(s.myFavoriteFlower); same &= myOtherFavoriteFlower.equals(s.myOtherFavoriteFlower); same &= myFavoriteTree.equals(s.myFavoriteTree); + same &= myOtherFavoriteTree.equals(s.myOtherFavoriteTree); return same; } |