Author: tfischer
Date: Sat Aug 5 07:49:17 2006
New Revision: 429004
URL: http://svn.apache.org/viewvc?rev=429004&view=rev
Log:
Made correctBooleans work for aliased tables and joined tables. Still does not
work for chained criterions, though.
Modified:
db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java
db/torque/site/trunk/xdocs/changes.xml
db/torque/templates/trunk/src/templates/om/Peer.vm
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?rev=429004&r1=429003&r2=429004&view=diff
==============================================================================
--- 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 Sat
Aug 5 07:49:17 2006
@@ -1520,6 +1520,99 @@
}
/**
+ * Checks all columns in the criteria to see whether
+ * booleanchar and booleanint columns are queried with a boolean.
+ * If yes, the query values are mapped onto values the database
+ * 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
+ * not given in a column.
+ * @throws TorqueException if the database map for the criteria cannot be
+ * retrieved.
+ */
+ public static void correctBooleans(
+ Criteria criteria,
+ TableMap defaultTableMap)
+ throws TorqueException
+ {
+ Iterator keyIt = criteria.keySet().iterator();
+ while (keyIt.hasNext())
+ {
+ String key = (String) keyIt.next();
+ String columnName;
+ TableMap tableMap = null;
+ int dotPosition = key.lastIndexOf(".");
+ if (dotPosition == -1)
+ {
+ columnName = key;
+ tableMap = defaultTableMap;
+ }
+ else
+ {
+ columnName = key.substring(dotPosition + 1);
+ String tableName = key.substring(0, dotPosition);
+ String databaseName = criteria.getDbName();
+ if (databaseName == null)
+ {
+ databaseName = Torque.getDefaultDB();
+ }
+ DatabaseMap databaseMap = Torque.getDatabaseMap(databaseName);
+ if (databaseMap != null)
+ {
+ tableMap = databaseMap.getTable(tableName);
+ }
+ if (tableMap == null)
+ {
+ // try aliases
+ if (criteria.getAliases().get(tableName) != null)
+ {
+ tableName = (String)
+ criteria.getAliases().get(tableName);
+ tableMap = databaseMap.getTable(tableName);
+ }
+ }
+ if (tableMap == null)
+ {
+ // no description of table available, do not modify
anything
+ break;
+ }
+ }
+ ColumnMap columnMap = tableMap.getColumn(columnName);
+ if (columnMap != null)
+ {
+ 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);
+ }
+ }
+ 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");
+ }
+ }
+ }
+ }
+ }
+
+ /**
* Process the result of a Table list generation.
* This runs the statements onto the list of tables and
* provides a callback hook to add functionality.
Modified: db/torque/site/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?rev=429004&r1=429003&r2=429004&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Sat Aug 5 07:49:17 2006
@@ -30,6 +30,10 @@
<release version="3.2.1-dev" date="in SVN">
<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.
+ </action>
+ <action type="fix" dev="tfischer" issue="TORQUE-44" due-to="Thoralf
Rickert">
Preserved case when generating the constants for column names
in the Peers and the database maps. For example, for a table named book
and a column namend author_id, the constant BaseBookPeer.AUTHOR_ID
Modified: db/torque/templates/trunk/src/templates/om/Peer.vm
URL:
http://svn.apache.org/viewvc/db/torque/templates/trunk/src/templates/om/Peer.vm?rev=429004&r1=429003&r2=429004&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/Peer.vm (original)
+++ db/torque/templates/trunk/src/templates/om/Peer.vm Sat Aug 5 07:49:17 2006
@@ -303,33 +303,12 @@
* This enables the user to create criteria using Boolean values
* for booleanchar or booleanint columns
* @param criteria the criteria in which the boolean values should be
corrected
+ * @throws TorqueException if the database map for the criteria cannot be
+ obtained.
*/
- public static void correctBooleans(Criteria criteria)
+ public static void correctBooleans(Criteria criteria) throws
TorqueException
{
- #foreach ($col in $table.Columns)
- #set ( $cup=$col.Name.toUpperCase() )
- #if($col.isBooleanInt())
- // check for conversion from boolean to int
- if (criteria.containsKey($cup))
- {
- Object possibleBoolean = criteria.get($cup);
- if (possibleBoolean instanceof Boolean)
- {
- criteria.add($cup, ((Boolean) possibleBoolean).booleanValue()
? 1 : 0);
- }
- }
- #elseif ($col.isBooleanChar())
- // check for conversion from boolean to Y/N
- if (criteria.containsKey($cup))
- {
- Object possibleBoolean = criteria.get($cup);
- if (possibleBoolean instanceof Boolean)
- {
- criteria.add($cup, ((Boolean) possibleBoolean).booleanValue()
? "Y" : "N");
- }
- }
- #end
- #end
+ correctBooleans(criteria, getTableMap());
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]