Author: tfischer
Date: Sun Oct 29 04:06:48 2006
New Revision: 468882
URL: http://svn.apache.org/viewvc?view=rev&rev=468882
Log:
Booleanchar and Booleanint now work for chained (andes, ored) Criterions in
selects.
For this ,it was necessary to add a setValue() method to Criteria.Criterion.
Thanks to Thoralf Rickert for insisting on a solution for this behaviour.
Modified:
db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java
db/torque/runtime/trunk/src/java/org/apache/torque/util/Criteria.java
db/torque/site/trunk/xdocs/changes.xml
db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Modified: db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java
URL:
http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java?view=diff&rev=468882&r1=468881&r2=468882
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java
(original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java Sun
Oct 29 04:06:48 2006
@@ -1526,9 +1526,6 @@
* does understand, i.e. 0 and 1 for booleanints and N and Y for
* booleanchar columns.
*
- * Limitations: The method does not yet check for criterions which contain
- * other criterions.
- *
* @param criteria The criteria to be checked for booleanint and
booleanchar
* columns.
* @param defaultTableMap the table map to be used if the table name is
@@ -1589,28 +1586,54 @@
{
if ("BOOLEANINT".equals(columnMap.getTorqueType()))
{
- Object criterionValue = criteria.get(key);
- if (criterionValue instanceof Boolean)
- {
- Boolean booleanValue = (Boolean) criterionValue;
- criteria.add(
- key,
- Boolean.TRUE.equals(booleanValue) ? 1 : 0);
- }
+ Criteria.Criterion criterion = criteria.getCriterion(key);
+ replaceBooleanValues(
+ criterion,
+ new Integer(1),
+ new Integer(0));
}
else if ("BOOLEANCHAR".equals(columnMap.getTorqueType()))
{
- Object criterionValue = criteria.get(key);
- if (criterionValue instanceof Boolean)
- {
- Boolean booleanValue = (Boolean) criterionValue;
- criteria.add(
- key,
- Boolean.TRUE.equals(booleanValue) ? "Y" : "N");
- }
- }
+ Criteria.Criterion criterion = criteria.getCriterion(key);
+ replaceBooleanValues(criterion, "Y", "N");
+ }
+ }
+ }
+ }
+
+ /**
+ * Replaces any Boolean value in the criterion and its attached Criterions
+ * by trueValue if the Boolean equals <code>Boolean.TRUE</code>
+ * and falseValue if the Boolean equals <code>Boolean.FALSE</code>.
+ *
+ * @param criterion the criterion to replace Boolean values in.
+ * @param trueValue the value by which Boolean.TRUE should be replaced.
+ * @param falseValue the value by which Boolean.FALSE should be replaced.
+ */
+ private static void replaceBooleanValues(
+ Criteria.Criterion criterion,
+ Object trueValue,
+ Object falseValue)
+ {
+ // attachedCriterions also contains the criterion itself,
+ // so no additional treatment is needed for the criterion itself.
+ Criteria.Criterion[] attachedCriterions
+ = criterion.getAttachedCriterion();
+ for (int i = 0; i < attachedCriterions.length; ++i)
+ {
+ Object criterionValue
+ = attachedCriterions[i].getValue();
+ if (criterionValue instanceof Boolean)
+ {
+ Boolean booleanValue = (Boolean) criterionValue;
+ attachedCriterions[i].setValue(
+ Boolean.TRUE.equals(booleanValue)
+ ? trueValue
+ : falseValue);
}
+
}
+
}
/**
Modified: db/torque/runtime/trunk/src/java/org/apache/torque/util/Criteria.java
URL:
http://svn.apache.org/viewvc/db/torque/runtime/trunk/src/java/org/apache/torque/util/Criteria.java?view=diff&rev=468882&r1=468881&r2=468882
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/Criteria.java
(original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/Criteria.java Sun
Oct 29 04:06:48 2006
@@ -3283,6 +3283,16 @@
}
/**
+ * Set the value of the criterion.
+ *
+ * @param value the new value.
+ */
+ public void setValue(Object value)
+ {
+ this.value = value;
+ }
+
+ /**
* Get the value of db.
* The DB adaptor which might be used to get db specific
* variations of sql.
Modified: db/torque/site/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?view=diff&rev=468882&r1=468881&r2=468882
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Sun Oct 29 04:06:48 2006
@@ -28,7 +28,10 @@
<body>
<release version="3.2.1-dev" date="in SVN">
-
+ <action type="fix" dev="tfischer" issue="TORQUE-59">
+ Booleanchar and Booleanint now work for chained (and'ed, or'ed)
+ Criterions.
+ </action>
<action type="add" dev="tfischer" issue="TORQUE-27" due-to="Greg Monroe">
Added support for option tags for most elements in the database.xml
for usage with custom templates.
@@ -64,7 +67,7 @@
</action>
<action type="fix" dev="tfischer" issue="TORQUE-44" due-to="Thoralf
Rickert">
Selects for BOOLEANCHAR and BOOLEANINT now works for aliased tablenames
- and joined tables. It still does not work for chained Criterions.
+ and joined tables.
</action>
<action type="fix" dev="tfischer" issue="TORQUE-44" due-to="Thoralf
Rickert">
Preserved case when generating the constants for column names
Modified:
db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
URL:
http://svn.apache.org/viewvc/db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java?view=diff&rev=468882&r1=468881&r2=468882
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
(original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Sun Oct 29 04:06:48 2006
@@ -495,6 +495,50 @@
assertTrue("Primary key of data set should be f1 but is "
+ booleanCheck.getTestKey().trim(),
"f1".equals(booleanCheck.getTestKey().trim()));
+
+ // check whether complex criteria are overwritten by
+ // replaceBooleans
+ criteria.clear();
+ Criteria.Criterion criterion1 = criteria.getNewCriterion(
+ BooleanCheckPeer.BCHAR_VALUE,
+ Boolean.FALSE,
+ Criteria.EQUAL);
+ Criteria.Criterion criterion2 = criteria.getNewCriterion(
+ BooleanCheckPeer.BCHAR_VALUE,
+ null,
+ Criteria.ISNULL);
+ criteria.add(criterion1.and(criterion2));
+ booleanCheckList = BooleanCheckPeer.doSelect(criteria);
+ // List should be empty, because and creates unfulfillable condition
+ // If BasePeer.correctBooleans() replaces Criterion wrongly,
+ // then we get entries in the list.
+ assertTrue("List should be empty but contains "
+ + booleanCheckList.size() + " datasets",
+ booleanCheckList.isEmpty());
+
+ // check whether complex criteria are overwritten by
+ // replaceBooleans
+ criteria.clear();
+ criterion1 = criteria.getNewCriterion(
+ BooleanCheckPeer.BCHAR_VALUE,
+ null,
+ Criteria.ISNULL);
+ criterion2 = criteria.getNewCriterion(
+ BooleanCheckPeer.BCHAR_VALUE,
+ Boolean.FALSE,
+ Criteria.EQUAL);
+ criteria.add(criterion1.or(criterion2));
+ booleanCheckList = BooleanCheckPeer.doSelect(criteria);
+ assertTrue("Should have read 1 dataset complex Criteria "
+ + "but read " + booleanCheckList.size(),
+ booleanCheckList.size() == 1);
+ booleanCheck = (BooleanCheck) booleanCheckList.get(0);
+ // use trim() for testkey because some databases will return the
+ // testkey filled up with blanks, as it is defined as char(10)
+ assertTrue("Primary key of data set should be f1 but is "
+ + booleanCheck.getTestKey().trim(),
+ "f1".equals(booleanCheck.getTestKey().trim()));
+
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]