Author: tfischer
Date: Sat Apr 14 15:09:23 2012
New Revision: 1326125
URL: http://svn.apache.org/viewvc?rev=1326125&view=rev
Log:
TORQUE-186: Fix behaviour for Booleanint and Booleanchar object columns with
null values
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/dbObjectFieldGetter.vm
db/torque/torque4/trunk/torque-test/src/main/schema/types-schema.xml
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BooleanIntCharTest.java
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm?rev=1326125&r1=1326124&r2=1326125&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
Sat Apr 14 15:09:23 2012
@@ -136,16 +136,40 @@
${peerClassName}.$peerColumnName,
new JdbcTypedValue($columnFieldName, Types.TIMESTAMP));
#elseif ($columnType == "BOOLEANCHAR" &&
$columnFieldType.equalsIgnoreCase("boolean"))
+ #if ($primitive == "true")
String $columnFieldName = Boolean.TRUE.equals(${field}.${getter}())
? "Y"
: "N";
+ #else
+ String $columnFieldName = null;
+ if (Boolean.TRUE.equals(${field}.${getter}()))
+ {
+ $columnFieldName = "Y";
+ }
+ else if (Boolean.FALSE.equals(${field}.${getter}()))
+ {
+ $columnFieldName = "N";
+ }
+ #end
columnValues.put(
${peerClassName}.$peerColumnName,
new JdbcTypedValue($columnFieldName, Types.CHAR));
#elseif ($columnType == "BOOLEANINT" &&
$columnFieldType.equalsIgnoreCase("boolean"))
+ #if ($primitive == "true")
Integer $columnFieldName = Boolean.TRUE.equals(${field}.${getter}())
- ? new Integer(1)
- : new Integer(0);
+ ? Integer.valueOf(1)
+ : Integer.valueOf(0);
+ #else
+ Integer $columnFieldName = null;
+ if (Boolean.TRUE.equals(${field}.${getter}()))
+ {
+ $columnFieldName = Integer.valueOf(1);
+ }
+ else if (Boolean.FALSE.equals(${field}.${getter}()))
+ {
+ $columnFieldName = Integer.valueOf(0);
+ }
+ #end
columnValues.put(
${peerClassName}.$peerColumnName,
new JdbcTypedValue($columnFieldName, Types.INTEGER));
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/dbObjectFieldGetter.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/dbObjectFieldGetter.vm?rev=1326125&r1=1326124&r2=1326125&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/dbObjectFieldGetter.vm
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/dbObjectFieldGetter.vm
Sat Apr 14 15:09:23 2012
@@ -56,6 +56,12 @@
{
return true;
}
+ #if ($primitive != "true")
+ else if (null == stringValue)
+ {
+ return null;
+ }
+ #end
else
{
return false;
@@ -66,6 +72,12 @@
{
return true;
}
+ #if ($primitive != "true")
+ else if (0 == intValue && resultSet.wasNull())
+ {
+ return null;
+ }
+ #end
else
{
return false;
Modified: db/torque/torque4/trunk/torque-test/src/main/schema/types-schema.xml
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/types-schema.xml?rev=1326125&r1=1326124&r2=1326125&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/types-schema.xml
(original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/types-schema.xml Sat
Apr 14 15:09:23 2012
@@ -42,9 +42,11 @@
</table>
<table name="bint_bchar_value" idMethod="none">
- <column name="id" required="true" primaryKey="true" type="VARCHAR"
size="2" />
+ <column name="id" required="true" primaryKey="true" type="VARCHAR"
size="20" />
<column name="bint_value" required="true" type="BOOLEANINT" />
<column name="bchar_value" required="true" type="BOOLEANCHAR" />
+ <column name="bint_object_value" type="BOOLEANINT" javaType="object"/>
+ <column name="bchar_object_value" type="BOOLEANCHAR" javaType="object"/>
</table>
</database>
Modified:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BooleanIntCharTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BooleanIntCharTest.java?rev=1326125&r1=1326124&r2=1326125&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BooleanIntCharTest.java
(original)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/datatypes/BooleanIntCharTest.java
Sat Apr 14 15:09:23 2012
@@ -38,27 +38,53 @@ import org.apache.torque.util.BasePeer;
public class BooleanIntCharTest extends BaseDatabaseTestCase
{
/**
- * Test inserting and reading boolean values.
+ * Checks whether we can read boolean true values.
*
* @throws Exception if the test fails
*/
- public void testReadBooleanIntCharValues() throws Exception
+ public void testReadBooleanIntCharTrueValue() throws Exception
{
fillTables();
BintBcharValue bc
= BintBcharValuePeer.retrieveByPK(new StringKey("t1"));
- assertTrue("BOOLEANINT should be true but is: "
- + bc.getBintValue(), bc.getBintValue());
- assertTrue("BOOLEANCHAR should be true but is: "
- + bc.getBcharValue(), bc.getBcharValue());
- bc = BintBcharValuePeer.retrieveByPK(new StringKey("f1"));
- assertFalse("BOOLEANINT should be false but is: "
- + bc.getBintValue(), bc.getBintValue());
- assertFalse("BOOLEANCHAR should be false but is: "
- + bc.getBcharValue(), bc.getBcharValue());
+ assertEquals(Boolean.TRUE, (Boolean) bc.getBintValue());
+ assertEquals(Boolean.TRUE, (Boolean) bc.getBcharValue());
+ assertEquals(Boolean.TRUE, bc.getBintObjectValue());
+ assertEquals(Boolean.TRUE, bc.getBcharObjectValue());
}
+ /**
+ * Checks whether we can read boolean false values.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testReadBooleanIntCharFalseValue() throws Exception
+ {
+ fillTables();
+
+ BintBcharValue bc
+ = BintBcharValuePeer.retrieveByPK(new StringKey("f1"));
+ assertEquals(Boolean.FALSE, (Boolean) bc.getBintValue());
+ assertEquals(Boolean.FALSE, (Boolean) bc.getBcharValue());
+ assertEquals(Boolean.FALSE, bc.getBintObjectValue());
+ assertEquals(Boolean.FALSE, bc.getBcharObjectValue());
+ }
+
+ /**
+ * Checks whether we can read Boolean null values.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testReadBooleanIntCharNullValue() throws Exception
+ {
+ fillTables();
+
+ BintBcharValue bc
+ = BintBcharValuePeer.retrieveByPK(new StringKey("null"));
+ assertEquals(null, bc.getBintObjectValue());
+ assertEquals(null, bc.getBcharObjectValue());
+ }
/**
* Check whether we can impose the condition Boolean True to
@@ -68,14 +94,16 @@ public class BooleanIntCharTest extends
*/
public void testBooleanTrueSelect() throws Exception
{
+ fillTables();
+
Criteria criteria = new Criteria()
.where(BintBcharValuePeer.BCHAR_VALUE, new Boolean(true))
- .and(BintBcharValuePeer.BINT_VALUE, new Boolean(true));
+ .and(BintBcharValuePeer.BINT_VALUE, new Boolean(true))
+ .and(BintBcharValuePeer.BCHAR_OBJECT_VALUE, new Boolean(true))
+ .and(BintBcharValuePeer.BINT_OBJECT_VALUE, new Boolean(true));
List<BintBcharValue> selectedList
= BintBcharValuePeer.doSelect(criteria);
- assertTrue("Should have read 1 dataset with both values true "
- + "but read " + selectedList.size(),
- selectedList.size() == 1);
+ assertEquals(1, selectedList.size());
BintBcharValue bintBcharValue = selectedList.get(0);
assertTrue("Primary key of data set should be t1 but is "
+ bintBcharValue.getId(),
@@ -90,13 +118,16 @@ public class BooleanIntCharTest extends
*/
public void testBooleanFalseSelect() throws Exception
{
+ fillTables();
+
Criteria criteria = new Criteria()
.where(BintBcharValuePeer.BCHAR_VALUE, new Boolean(false))
- .and(BintBcharValuePeer.BINT_VALUE, new Boolean(false));
- List<BintBcharValue> selectedList =
BintBcharValuePeer.doSelect(criteria);
- assertTrue("Should have read 1 dataset with both values false "
- + "but read " + selectedList.size(),
- selectedList.size() == 1);
+ .and(BintBcharValuePeer.BINT_VALUE, new Boolean(false))
+ .and(BintBcharValuePeer.BCHAR_OBJECT_VALUE, new Boolean(false))
+ .and(BintBcharValuePeer.BINT_OBJECT_VALUE, new Boolean(false));
+ List<BintBcharValue> selectedList
+ = BintBcharValuePeer.doSelect(criteria);
+ assertEquals(1, selectedList.size());
BintBcharValue bintBcharValue = selectedList.get(0);
assertTrue("Primary key of data set should be f1 but is "
+ bintBcharValue.getId(),
@@ -104,6 +135,49 @@ public class BooleanIntCharTest extends
}
/**
+ * Check whether we can impose the condition Boolean Null to
+ * booleanint/booleanchar columns and get objects where the columns
+ * are null.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBooleanObjectNullSelect() throws Exception
+ {
+ fillTables();
+
+ Criteria criteria = new Criteria()
+ .where(BintBcharValuePeer.BCHAR_OBJECT_VALUE, null)
+ .and(BintBcharValuePeer.BINT_OBJECT_VALUE, null);
+ List<BintBcharValue> selectedList
+ = BintBcharValuePeer.doSelect(criteria);
+ assertEquals(1, selectedList.size());
+ BintBcharValue bintBcharValue = selectedList.get(0);
+ assertTrue("Primary key of data set should be null but is "
+ + bintBcharValue.getId(),
+ "null".equals(bintBcharValue.getId()));
+ }
+
+ /**
+ * Check whether we can impose the condition Boolean Null to
+ * booleanint/booleanchar primitive columns and get no hit.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testPrimitiveNullSelect() throws Exception
+ {
+ fillTables();
+
+ Criteria criteria = new Criteria()
+ .and(BintBcharValuePeer.BCHAR_VALUE, null)
+ .and(BintBcharValuePeer.BINT_VALUE, null);
+ List<BintBcharValue> selectedList
+ = BintBcharValuePeer.doSelect(criteria);
+ assertTrue("Should have read 0 dataset with both values false "
+ + "but read " + selectedList.size(),
+ selectedList.size() == 0);
+ }
+
+ /**
* Check whether we can impose a Boolean condition to
booleanint/booleanchar
* columns via joins.
*
@@ -111,13 +185,17 @@ public class BooleanIntCharTest extends
*/
public void testBooleanSelectViaJoins() throws Exception
{
+ fillTables();
+
Criteria criteria = new Criteria();
criteria.addAlias("bc", BintBcharValuePeer.TABLE_NAME);
criteria.addJoin(
BintBcharValuePeer.ID,
new ColumnImpl("bc.id"));
- criteria.where("bc.bint_value", new Boolean(false));
- criteria.and("bc.bchar_value", new Boolean(false));
+ criteria.where("bc.bint_value", new Boolean(false))
+ .and("bc.bchar_value", new Boolean(false))
+ .and("bc.bint_object_value", new Boolean(false))
+ .and("bc.bchar_object_value", new Boolean(false));
List<BintBcharValue> selectedList
= BintBcharValuePeer.doSelect(criteria);
assertTrue("Should have read 1 dataset with both values false "
@@ -137,6 +215,8 @@ public class BooleanIntCharTest extends
*/
public void testBooleanSelectInChainedCriterionsNoHits() throws Exception
{
+ fillTables();
+
// check whether complex criteria are overwritten by
// replaceBooleans
Criteria criteria = new Criteria();
@@ -167,6 +247,8 @@ public class BooleanIntCharTest extends
*/
public void testBooleanSelectInChainedCriterionsUsingOr() throws Exception
{
+ fillTables();
+
Criteria criteria = new Criteria();
Criterion criterion1 = new Criterion(
BintBcharValuePeer.BCHAR_VALUE,
@@ -199,21 +281,21 @@ public class BooleanIntCharTest extends
{
// check whether booleans are replaced with unqualified columns
Criteria criteria = new Criteria()
- .where("BooleanCheck.bint_value", true)
- .and("BooleanCheck.bchar_value", true);
+ .where("bint_value", true)
+ .and("bchar_value", true);
BintBcharValuePeer.correctBooleans(criteria);
Criterion criterionInt
= criteria.getTopLevelCriterion().getParts().get(0);
- Object intValue = criterionInt.getValue();
+ Object intValue = criterionInt.getRValue();
assertTrue("The boolean value should be an instance of Integer",
intValue instanceof Integer);
Criterion criterionChar
= criteria.getTopLevelCriterion().getParts().get(1);
- Object charValue = criterionChar.getValue();
+ Object charValue = criterionChar.getRValue();
assertTrue("The boolean value should be an instance of String",
charValue instanceof String);
@@ -234,14 +316,14 @@ public class BooleanIntCharTest extends
Criterion criterionBool1
= criteria.getTopLevelCriterion().getParts().get(0);
- Object boolValue1 = criterionBool1.getValue();
+ Object boolValue1 = criterionBool1.getRValue();
assertTrue("The boolean value should be an instance of Boolean",
boolValue1 instanceof Boolean);
Criterion criterionBool2
= criteria.getTopLevelCriterion().getParts().get(1);
- Object boolValue2 = criterionBool2.getValue();
+ Object boolValue2 = criterionBool2.getRValue();
assertTrue("The boolean value should be an instance of Boolean",
boolValue2 instanceof Boolean);
@@ -260,11 +342,22 @@ public class BooleanIntCharTest extends
bc.setId("t1");
bc.setBintValue(true);
bc.setBcharValue(true);
+ bc.setBintObjectValue(Boolean.TRUE);
+ bc.setBcharObjectValue(Boolean.TRUE);
bc.save();
bc = new BintBcharValue();
bc.setId("f1");
bc.setBintValue(false);
bc.setBcharValue(false);
+ bc.setBintObjectValue(Boolean.FALSE);
+ bc.setBcharObjectValue(Boolean.FALSE);
+ bc.save();
+ bc = new BintBcharValue();
+ bc.setId("null");
+ bc.setBintValue(false);
+ bc.setBcharValue(true);
+ bc.setBintObjectValue(null);
+ bc.setBcharObjectValue(null);
bc.save();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]