aboutsummaryrefslogtreecommitdiffstats
path: root/tests/com/iciql/test/models
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2011-08-04 17:58:22 -0400
committerJames Moger <james.moger@gmail.com>2011-08-04 17:58:22 -0400
commitb055a2a49335c78fdc754e38a7e8ab863b2a5515 (patch)
tree50c1e4bec870701e81e3bbcdde7c90d9a9119f52 /tests/com/iciql/test/models
parent3d1e36c31e2a8354e03cdfe12565503190c2e957 (diff)
downloadiciql-b055a2a49335c78fdc754e38a7e8ab863b2a5515.tar.gz
iciql-b055a2a49335c78fdc754e38a7e8ab863b2a5515.zip
BLOB support (issue 1) and Enum support (issue 2). Documentation.
Diffstat (limited to 'tests/com/iciql/test/models')
-rw-r--r--tests/com/iciql/test/models/ProductAnnotationOnly.java3
-rw-r--r--tests/com/iciql/test/models/SupportedTypes.java64
2 files changed, 65 insertions, 2 deletions
diff --git a/tests/com/iciql/test/models/ProductAnnotationOnly.java b/tests/com/iciql/test/models/ProductAnnotationOnly.java
index 6b8d420..caf07c7 100644
--- a/tests/com/iciql/test/models/ProductAnnotationOnly.java
+++ b/tests/com/iciql/test/models/ProductAnnotationOnly.java
@@ -31,8 +31,7 @@ import com.iciql.Iciql.IndexType;
*/
@IQTable(name = "AnnotatedProduct", primaryKey = "id")
-@IQIndexes({ @IQIndex({ "name", "cat" }),
- @IQIndex(name = "nameidx", type = IndexType.HASH, value = "name") })
+@IQIndexes({ @IQIndex({ "name", "cat" }), @IQIndex(name = "nameidx", type = IndexType.HASH, value = "name") })
public class ProductAnnotationOnly {
@IQColumn(autoIncrement = true)
diff --git a/tests/com/iciql/test/models/SupportedTypes.java b/tests/com/iciql/test/models/SupportedTypes.java
index 66c25d4..bb5ecc6 100644
--- a/tests/com/iciql/test/models/SupportedTypes.java
+++ b/tests/com/iciql/test/models/SupportedTypes.java
@@ -21,7 +21,9 @@ import java.math.BigDecimal;
import java.util.List;
import java.util.Random;
+import com.iciql.Iciql.EnumType;
import com.iciql.Iciql.IQColumn;
+import com.iciql.Iciql.IQEnum;
import com.iciql.Iciql.IQIndex;
import com.iciql.Iciql.IQIndexes;
import com.iciql.Iciql.IQTable;
@@ -39,6 +41,29 @@ public class SupportedTypes {
public static final SupportedTypes SAMPLE = new SupportedTypes();
+ /**
+ * Test of plain enumeration.
+ *
+ * Each field declaraton of this enum must specify a mapping strategy.
+ */
+ public enum Flower {
+ 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 {
+ PINE, OAK, BIRCH, WALNUT, MAPLE;
+ }
+
@IQColumn(primaryKey = true, autoIncrement = true)
public Integer id;
@@ -81,6 +106,22 @@ public class SupportedTypes {
@IQColumn
private java.sql.Timestamp mySqlTimestamp;
+ @IQColumn
+ private byte[] myBlob;
+
+ @IQEnum(EnumType.STRING)
+ @IQColumn(trimString = true, maxLength = 25)
+ private Flower myFavoriteFlower;
+
+ @IQEnum(EnumType.ORDINAL)
+ @IQColumn
+ private Flower myOtherFavoriteFlower;
+
+ @IQColumn(maxLength = 25)
+ // @IQEnum is set on the enumeration definition and is shared
+ // by all uses of Tree as an @IQColumn
+ private Tree myFavoriteTree;
+
public static List<SupportedTypes> createList() {
List<SupportedTypes> list = Utils.newArrayList();
for (int i = 0; i < 10; i++) {
@@ -105,6 +146,10 @@ public class SupportedTypes {
s.mySqlDate = new java.sql.Date(rand.nextLong());
s.mySqlTime = new java.sql.Time(rand.nextLong());
s.mySqlTimestamp = new java.sql.Timestamp(rand.nextLong());
+ s.myBlob = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ s.myFavoriteFlower = Flower.MUM;
+ s.myOtherFavoriteFlower = Flower.MARIGOLD;
+ s.myFavoriteTree = Tree.BIRCH;
return s;
}
@@ -123,9 +168,28 @@ public class SupportedTypes {
same &= mySqlDate.toString().equals(s.mySqlDate.toString());
same &= mySqlTime.toString().equals(s.mySqlTime.toString());
same &= myString.equals(s.myString);
+ same &= compare(myBlob, s.myBlob);
+ same &= myFavoriteFlower.equals(s.myFavoriteFlower);
+ same &= myOtherFavoriteFlower.equals(s.myOtherFavoriteFlower);
+ same &= myFavoriteTree.equals(s.myFavoriteTree);
return same;
}
+ private boolean compare(byte[] a, byte[] b) {
+ if (b == null) {
+ return false;
+ }
+ if (a.length != b.length) {
+ return false;
+ }
+ for (int i = 0; i < a.length; i++) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* This class demonstrates the table upgrade.
*/