From 978bf81acba6443bf705d62ccb460ece88f206a2 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 19 Jun 2010 17:48:51 +0000 Subject: [PATCH] Added support for boxed booleans. I have to admit that adding it to the test case, seeing it fail, then adding the code to handle it was rather satisfying. I'm not jumping on the TDD bandwagon or anything, but libraries like Depot are clear cases where vigorous unit testing is a big win. --- src/java/com/samskivert/depot/impl/FieldMarshaller.java | 6 ++++++ src/java/com/samskivert/depot/tests/AllTypesRecord.java | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/java/com/samskivert/depot/impl/FieldMarshaller.java b/src/java/com/samskivert/depot/impl/FieldMarshaller.java index 80ecf28..ad7499f 100644 --- a/src/java/com/samskivert/depot/impl/FieldMarshaller.java +++ b/src/java/com/samskivert/depot/impl/FieldMarshaller.java @@ -252,6 +252,12 @@ public abstract class FieldMarshaller return new DoubleMarshaller(); // boxed primitive types + } else if (ftype.equals(Boolean.class)) { + return new ObjectMarshaller() { + @Override public String getColumnType (ColumnTyper typer, int length) { + return typer.getBooleanType(length); + } + }; } else if (ftype.equals(Byte.class)) { return new ObjectMarshaller() { @Override public String getColumnType (ColumnTyper typer, int length) { diff --git a/src/java/com/samskivert/depot/tests/AllTypesRecord.java b/src/java/com/samskivert/depot/tests/AllTypesRecord.java index b07b665..126c305 100644 --- a/src/java/com/samskivert/depot/tests/AllTypesRecord.java +++ b/src/java/com/samskivert/depot/tests/AllTypesRecord.java @@ -84,6 +84,7 @@ public class AllTypesRecord extends PersistentRecord public float floatValue; public double doubleValue; + public Boolean boxedBoolean; public Byte boxedByte; public Short boxedShort; public Integer boxedInt; @@ -101,6 +102,7 @@ public class AllTypesRecord extends PersistentRecord // public Blob blob; // tested by byte[] // public Clob clob; // not clear how to test this + @Column(nullable=true) public Boolean nullBoxedBoolean; @Column(nullable=true) public Byte nullBoxedByte; @Column(nullable=true) public Short nullBoxedShort; @Column(nullable=true) public Integer nullBoxedInt; @@ -126,6 +128,7 @@ public class AllTypesRecord extends PersistentRecord (longValue == orec.longValue) && (floatValue == orec.floatValue) && (doubleValue == orec.doubleValue) && + boxedBoolean.equals(orec.boxedBoolean) && boxedByte.equals(orec.boxedByte) && boxedShort.equals(orec.boxedShort) && boxedInt.equals(orec.boxedInt) && @@ -138,6 +141,7 @@ public class AllTypesRecord extends PersistentRecord date.equals(orec.date) && time.equals(orec.time) && timestamp.equals(orec.timestamp) && + (nullBoxedBoolean == orec.nullBoxedBoolean) && (nullBoxedByte == orec.nullBoxedByte) && (nullBoxedShort == orec.nullBoxedShort) && (nullBoxedInt == orec.nullBoxedInt) && @@ -163,6 +167,7 @@ public class AllTypesRecord extends PersistentRecord rec.longValue = 4; rec.floatValue = 5.5f; rec.doubleValue = 6.6; + rec.boxedBoolean = true; rec.boxedByte = 7; rec.boxedShort = 8; rec.boxedInt = 9;