diff options
author | James Moger <james.moger@gitblit.com> | 2014-10-06 12:12:41 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-10-06 12:12:41 -0400 |
commit | 40ad76e1db008923cd089b0dde80590156fa0596 (patch) | |
tree | a76f96d22a48ada60f6a2b6c0174884a54c2ddf0 /src/test | |
parent | 8eed45f5117065995cbceb7ae2a96c9057a806bd (diff) | |
download | iciql-40ad76e1db008923cd089b0dde80590156fa0596.tar.gz iciql-40ad76e1db008923cd089b0dde80590156fa0596.zip |
Support mapping SQL BOOLEAN -> primitive numeric types
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/com/iciql/test/BooleanModelTest.java | 45 | ||||
-rw-r--r-- | src/test/java/com/iciql/test/models/BooleanModel.java | 27 |
2 files changed, 71 insertions, 1 deletions
diff --git a/src/test/java/com/iciql/test/BooleanModelTest.java b/src/test/java/com/iciql/test/BooleanModelTest.java index 1e1630a..f5cd5e7 100644 --- a/src/test/java/com/iciql/test/BooleanModelTest.java +++ b/src/test/java/com/iciql/test/BooleanModelTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import com.iciql.Db;
import com.iciql.test.models.BooleanModel;
import com.iciql.test.models.BooleanModel.BooleanAsIntModel;
+import com.iciql.test.models.BooleanModel.BooleanAsPrimitiveShortModel;
/**
* Tests interchangeable mapping of INT columns with Booleans and BOOL columns
@@ -33,6 +34,7 @@ import com.iciql.test.models.BooleanModel.BooleanAsIntModel; * <ul>
* <li>mapping a BIT/BOOLEAN column as an Integer
* <li>mapping a INT column as a Boolean.
+ * <li>mapping a BIT/BOOLEAN column as a primitive short
* </ul>
*/
public class BooleanModelTest {
@@ -125,4 +127,47 @@ public class BooleanModelTest { }
db.close();
}
+
+ @Test
+ public void testPrimitiveShortBooleanColumn() {
+ Db db = IciqlSuite.openNewDb();
+ db.insertAll(BooleanModel.getList());
+ BooleanAsPrimitiveShortModel b = new BooleanAsPrimitiveShortModel();
+ List<BooleanAsPrimitiveShortModel> models = db.from(b).select();
+ int count = 0;
+ for (BooleanAsPrimitiveShortModel model : models) {
+ if ((model.id % 2) == 1) {
+ // assert that odd ids are true
+ assertTrue(model.mybool > 0);
+ } else {
+ // assert that even ids are false
+ assertTrue(model.mybool == 0);
+ }
+
+ // count true values
+ if (model.mybool > 0) {
+ count++;
+ }
+ }
+ assertEquals(2, count);
+
+ // invert boolean values and update
+ for (BooleanAsPrimitiveShortModel model : models) {
+ model.mybool = (short) (model.mybool > 0 ? 0 : 1);
+ }
+ db.updateAll(models);
+
+ // check even ids are true
+ models = db.from(b).select();
+ for (BooleanAsPrimitiveShortModel model : models) {
+ if ((model.id % 2) == 1) {
+ // assert that odd ids are false
+ assertTrue(model.mybool == 0);
+ } else {
+ // assert that even ids are true
+ assertTrue(model.mybool > 0);
+ }
+ }
+ db.close();
+ }
}
diff --git a/src/test/java/com/iciql/test/models/BooleanModel.java b/src/test/java/com/iciql/test/models/BooleanModel.java index d22e3c1..4d75ad9 100644 --- a/src/test/java/com/iciql/test/models/BooleanModel.java +++ b/src/test/java/com/iciql/test/models/BooleanModel.java @@ -47,7 +47,7 @@ public class BooleanModel { }
/**
- * Test boolean as int
+ * Test boolean as Integer
*/
@IQTable(name = "BooleanTest")
public static class BooleanAsIntModel {
@@ -70,4 +70,29 @@ public class BooleanModel { new BooleanAsIntModel(3, true), new BooleanAsIntModel(4, false));
}
}
+
+ /**
+ * Test boolean as primitive short
+ */
+ @IQTable(name = "BooleanTest")
+ public static class BooleanAsPrimitiveShortModel {
+ @IQColumn(primaryKey = true)
+ public Integer id;
+
+ @IQColumn
+ public short mybool;
+
+ public BooleanAsPrimitiveShortModel() {
+ }
+
+ BooleanAsPrimitiveShortModel(int id, boolean val) {
+ this.id = id;
+ this.mybool = (short) (val ? 1 : 0);
+ }
+
+ public static List<BooleanAsPrimitiveShortModel> getList() {
+ return Arrays.asList(new BooleanAsPrimitiveShortModel(1, true), new BooleanAsPrimitiveShortModel(2, false),
+ new BooleanAsPrimitiveShortModel(3, true), new BooleanAsPrimitiveShortModel(4, false));
+ }
+ }
}
|