db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1410897 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/om/mapper/ torque-runtime/src/main/java/org/apache/torque/util/ torque-runtime/src/test/java/org/apache/torque/om/mapper/ torque-site/src/site/xdoc/docum...
Date Sun, 18 Nov 2012 15:30:03 GMT
Author: tfischer
Date: Sun Nov 18 15:29:55 2012
New Revision: 1410897

URL: http://svn.apache.org/viewvc?rev=1410897&view=rev
Log:
TORQUE-242 RecordMapper should use selected columns from Criteria
TORQUE-245 API Change for Record mapper interface
TORQUE-246 Remove unused method resultSet2Objects 

Removed:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/resultSet2Objects.vm
Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/BigDecimalMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/CompositeMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/IntegerMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/LongMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/ObjectListMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/RecordMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/StringMapper.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/BigDecimalMapperTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/CompositeMapperTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/DateMapperTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/IntegerMapperTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/LongMapperTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/ObjectListMapperTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/StringMapperTest.java
    db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/BigDecimalMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/BigDecimalMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/BigDecimalMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/BigDecimalMapper.java Sun Nov 18 15:29:55 2012
@@ -24,6 +24,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps a database record to a BigDecimal.
@@ -56,9 +57,21 @@ public class BigDecimalMapper implements
         this.internalOffset = offset;
     }
 
+    /**
+     * Maps the current row in the result to a BigDecimal.
+     *
+     * @param resultSet the result set to map, not null.
+     * @param rowOffset a possible offset in the columns to be considered
+     *        (if previous columns contain other objects), or 0 for no offset.
+     * @param criteria The criteria which created the result set, or null
+     *        if not known. This parameter is not used by this record mapper.
+      *
+     * @return the BigDecimal retrieved from the result set.
+     */
     public BigDecimal processRow(
                 ResultSet resultSet,
-                int rowOffset)
+                int rowOffset,
+                CriteriaInterface<?> criteria)
             throws TorqueException
     {
         try

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/CompositeMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/CompositeMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/CompositeMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/CompositeMapper.java Sun Nov 18 15:29:55 2012
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Uses a list of mappers to map a database record to a list of objects.
@@ -59,12 +60,18 @@ public class CompositeMapper implements 
      * and putting the result of each mapper in the result list.
      *
      * @param resultSet the result set to map, not null.
-     * @param offset the total offset of this mapper within the result set.
+     * @param offset the total column offset of this mapper
+     *        within the result set.
+     * @param criteria The criteria which created the result set, or null
+     *        if not known. This parameter is not used by this record mapper.
      *
      * @return a list of mapped objects in the same order as the mappers
      *         were ordered, not null.
      */
-    public List<Object> processRow(ResultSet resultSet, int offset)
+    public List<Object> processRow(
+            ResultSet resultSet,
+            int offset,
+            CriteriaInterface<?> criteria)
         throws TorqueException
     {
         List<Object> result = new ArrayList<Object>(mapperList.size());
@@ -72,7 +79,7 @@ public class CompositeMapper implements 
         {
             int totalOffset = offset +  mapperWithOffset.getOffset();
             RecordMapper<?> mapper = mapperWithOffset.getMapper();
-            result.add(mapper.processRow(resultSet, totalOffset));
+            result.add(mapper.processRow(resultSet, totalOffset, criteria));
         }
         return result;
     }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/DateMapper.java Sun Nov 18 15:29:55 2012
@@ -24,6 +24,7 @@ import java.sql.SQLException;
 import java.util.Date;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps a database record to a java.util.Date.
@@ -35,47 +36,54 @@ public class DateMapper implements Recor
     /** Serial Version UID. */
     private static final long serialVersionUID = 1L;
 
-  /** The internal offset for the mapper. */
-  private final int internalOffset;
+    /** The internal offset for the mapper. */
+    private final int internalOffset;
 
-  /**
-   * Constructs a DateMapper with an offset of 0.
-   */
-  public DateMapper()
-  {
-    this.internalOffset = 0;
-  }
-
-  /**
-   * Constructs a DateMapper with the given offset.
-   *
-   * @param offset the additional offset (0 based).
-   */
-  public DateMapper(int offset)
-  {
-    this.internalOffset = offset;
-  }
-
-  /**
-   * Maps a ResultSet column to a java.uti.Date.
-   *
-   * @param resultSet the result set to read
-   * @param offset the column offset for the column.
-   *
-   * @return the column as a Date.
-   */
-  public Date processRow(ResultSet resultSet, int offset)
-      throws TorqueException
-  {
-    try
+    /**
+     * Constructs a DateMapper with an offset of 0.
+     */
+    public DateMapper()
     {
-        java.util.Date value = resultSet.getTimestamp(
-            offset + internalOffset + 1);
-        return value;
+        this.internalOffset = 0;
     }
-    catch (SQLException e)
+
+    /**
+     * Constructs a DateMapper with the given offset.
+     *
+     * @param offset
+     *            the additional offset (0 based).
+     */
+    public DateMapper(int offset)
+    {
+        this.internalOffset = offset;
+    }
+
+    /**
+     * Maps the current row in the result set to a java.util.Date.
+     *
+     * @param resultSet the result set to map, not null.
+     * @param rowOffset a possible offset in the columns to be considered
+     *        (if previous columns contain other objects), or 0 for no offset.
+     * @param criteria The criteria which created the result set,
+     *        or null if not known. This parameter is not used
+     *        by this record mapper.
+     *
+     * @return the date retrieved from the result set.
+     */
+    public Date processRow(
+                ResultSet resultSet,
+                int rowOffset,
+                CriteriaInterface<?> criteria)
+            throws TorqueException
     {
-        throw new TorqueException("Result could not be mapped to a Date", e);
+        try
+        {
+            java.util.Date value = resultSet.getTimestamp(
+                    rowOffset + internalOffset + 1);
+            return value;
+        } catch (SQLException e)
+        {
+            throw new TorqueException("Result could not be mapped to a Date", e);
+        }
     }
-  }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/IntegerMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/IntegerMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/IntegerMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/IntegerMapper.java Sun Nov 18 15:29:55 2012
@@ -23,6 +23,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps a database record to a Integer.
@@ -55,9 +56,21 @@ public class IntegerMapper implements Re
         this.internalOffset = offset;
     }
 
+    /**
+     * Maps the current row in the result set to a Integer.
+     *
+     * @param resultSet the result set to map, not null.
+     * @param rowOffset a possible offset in the columns to be considered
+     *        (if previous columns contain other objects), or 0 for no offset.
+     * @param criteria The criteria which created the result set, or null
+     *        if not known. This parameter is not used by this record mapper.
+     *
+     * @return the Integer retrieved from the result set.
+     */
     public Integer processRow(
                 ResultSet resultSet,
-                int rowOffset)
+                int rowOffset,
+                CriteriaInterface<?> criteria)
             throws TorqueException
     {
         try

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/LongMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/LongMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/LongMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/LongMapper.java Sun Nov 18 15:29:55 2012
@@ -23,6 +23,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps a database record to a Long.
@@ -55,9 +56,21 @@ public class LongMapper implements Recor
         this.internalOffset = offset;
     }
 
+    /**
+     * Maps the current row in the result set to a Long.
+     *
+     * @param resultSet the result set to map, not null.
+     * @param rowOffset a possible offset in the columns to be considered
+     *        (if previous columns contain other objects), or 0 for no offset.
+     * @param criteria The criteria which created the result set, or null
+     *        if not known. This parameter is not used by this record mapper.
+     *
+     * @return the Long retrieved from the result set.
+     */
     public Long processRow(
                 ResultSet resultSet,
-                int rowOffset)
+                int rowOffset,
+                CriteriaInterface<?> criteria)
             throws TorqueException
     {
         try

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/ObjectListMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/ObjectListMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/ObjectListMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/ObjectListMapper.java Sun Nov 18 15:29:55 2012
@@ -36,6 +36,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps a record to a list of objects.
@@ -124,6 +125,8 @@ public class ObjectListMapper implements
      *
      * @param resultSet the result set to map, not null.
      * @param offset the offset of this mapper within the result set.
+     * @param criteria The criteria which created the result set, or null
+     *        if not known. This parameter is not used by this record mapper.
      *
      * @return a list of mapped objects in the same order as the mappers
      *         were ordered, not null.
@@ -132,8 +135,11 @@ public class ObjectListMapper implements
      *         fails or if the number of available columns cannot be determined
      *         from the result set.
      */
-    public List<Object> processRow(ResultSet resultSet, int offset)
-        throws TorqueException
+    public List<Object> processRow(
+                ResultSet resultSet,
+                int offset,
+                CriteriaInterface<?> criteria)
+            throws TorqueException
     {
         try
         {

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/RecordMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/RecordMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/RecordMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/RecordMapper.java Sun Nov 18 15:29:55 2012
@@ -23,6 +23,7 @@ import java.io.Serializable;
 import java.sql.ResultSet;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps an object to a database record and back.
@@ -44,12 +45,20 @@ public interface RecordMapper<T> extends
      *
      * @param resultSet the resultSet to operate on, already pointing
      *        to the correct row. Not null.
-     * @param rowOffset a possible offset in the rows to be considered
-     *        (if previous rows contain other objects).
+     * @param rowOffset a possible offset in the columns to be considered
+     *        (if previous columns contain other objects), or 0 for no offset.
+     * @param criteria the Criteria which contains the query to process,
+     *        or null if not known or the query was not produced by a Criteria.
+     *        Can be used by the RecordMapper to determine the columns
+     *        contained in the result set.
      *
      * @return the mapped object, not null.
      *
      * @throws TorqueException when the mapping fails.
      */
-    T processRow(ResultSet resultSet, int rowOffset) throws TorqueException;
+    T processRow(
+                ResultSet resultSet,
+                int rowOffset,
+                CriteriaInterface<?> criteria)
+            throws TorqueException;
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/StringMapper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/StringMapper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/StringMapper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/mapper/StringMapper.java Sun Nov 18 15:29:55 2012
@@ -23,6 +23,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 
 /**
  * Maps a database record to a String.
@@ -55,9 +56,21 @@ public class StringMapper implements Rec
         this.internalOffset = offset;
     }
 
+    /**
+     * Maps the current row in the result set to a String.
+     *
+     * @param resultSet the result set to map, not null.
+     * @param rowOffset a possible offset in the columns to be considered
+     *        (if previous columns contain other objects), or 0 for no offset.
+     * @param criteria The criteria which created the result set, or null
+     *        if not known. This parameter is not used by this record mapper.
+     *
+     * @return the String retrieved from the result set.
+     */
     public String processRow(
                 ResultSet resultSet,
-                int rowOffset)
+                int rowOffset,
+                CriteriaInterface<?> criteria)
             throws TorqueException
     {
         try

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Sun Nov 18 15:29:55 2012
@@ -191,36 +191,6 @@ public class BasePeerImpl<T> implements 
     }
 
     /**
-     * Get the list of objects from a ResultSet.
-     * Please not that the ResultSet MUST return columns in the right order.
-     * You can use getFieldNames() in BaseObject to get the correct sequence.
-     *
-     * @param resultSet the ResultSet to extract the objects from.
-     *
-     * @return the list of objects read from the ResultSet.
-     *
-     * @throws TorqueException If the mapping fails.
-     */
-    public List<T> resultSet2Objects(java.sql.ResultSet resultSet)
-        throws TorqueException
-    {
-        try
-        {
-            List<T> result = new ArrayList<T>();
-            RecordMapper<T> mapper = getRecordMapper();
-            while (resultSet.next())
-            {
-                result.add(mapper.processRow(resultSet, 0));
-            }
-            return result;
-        }
-        catch (SQLException e)
-        {
-            throw ExceptionMapper.getInstance().toTorqueException(e);
-        }
-    }
-
-    /**
      * Convenience method to create a String array of criteria keys.
      *
      * @param tableName Name of table.
@@ -1320,7 +1290,7 @@ public class BasePeerImpl<T> implements 
 
             while (resultSet.next())
             {
-                TT rowResult = mapper.processRow(resultSet, 0);
+                TT rowResult = mapper.processRow(resultSet, 0, null);
                 result.add(rowResult);
             }
             long mappingEndTime = System.currentTimeMillis();
@@ -1464,7 +1434,7 @@ public class BasePeerImpl<T> implements 
                     break;
                 }
 
-                TT rowResult = mapper.processRow(resultSet, 0);
+                TT rowResult = mapper.processRow(resultSet, 0, criteria);
                 result.add(rowResult);
 
                 rowNumber++;
@@ -1616,7 +1586,7 @@ public class BasePeerImpl<T> implements 
                     break;
                 }
 
-                TT rowResult = mapper.processRow(resultSet, 0);
+                TT rowResult = mapper.processRow(resultSet, 0, criteria);
                 result.add(rowResult);
 
                 rowNumber++;

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java Sun Nov 18 15:29:55 2012
@@ -306,6 +306,7 @@ public class SummaryHelper
             throws TorqueException
     {
         Criteria c = buildCriteria(crit);
+        // TODO use BasePeerImpl.doSelect instead of parsing the result manually
         String query = SqlBuilder.buildQuery(c).toString();
         RecordMapper<List<Object>> mapper = new ObjectListMapper(resultTypes);
 
@@ -325,7 +326,7 @@ public class SummaryHelper
 
             while (resultSet.next())
             {
-                List<Object> rowResult = mapper.processRow(resultSet, 0);
+                List<Object> rowResult = mapper.processRow(resultSet, 0, null);
                 rows.add(rowResult);
             }
             long mappingEndTime = System.currentTimeMillis();
@@ -414,6 +415,7 @@ public class SummaryHelper
             throws TorqueException
     {
         org.apache.torque.criteria.Criteria c = buildCriteria(crit);
+        // TODO use BasePeerImpl.doSelect instead of parsing the result manually
         String query = SqlBuilder.buildQuery(c).toString();
         RecordMapper<List<Object>> mapper = new ObjectListMapper(resultTypes);
 
@@ -433,7 +435,7 @@ public class SummaryHelper
 
             while (resultSet.next())
             {
-                List<Object> rowResult = mapper.processRow(resultSet, 0);
+                List<Object> rowResult = mapper.processRow(resultSet, 0, null);
                 rows.add(rowResult);
             }
             long mappingEndTime = System.currentTimeMillis();

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/BigDecimalMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/BigDecimalMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/BigDecimalMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/BigDecimalMapperTest.java Sun Nov 18 15:29:55 2012
@@ -29,6 +29,7 @@ import java.sql.SQLException;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -61,8 +62,8 @@ public class BigDecimalMapperTest extend
         BigDecimalMapper mapper = new BigDecimalMapper();
 
         // execute
-        BigDecimal result1 = mapper.processRow(resultSet, 0);
-        BigDecimal result2 = mapper.processRow(resultSet, 1);
+        BigDecimal result1 = mapper.processRow(resultSet, 0, null);
+        BigDecimal result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(null, result1);
@@ -83,8 +84,8 @@ public class BigDecimalMapperTest extend
         BigDecimalMapper mapper = new BigDecimalMapper(1);
 
         // execute
-        BigDecimal result1 = mapper.processRow(resultSet, 0);
-        BigDecimal result2 = mapper.processRow(resultSet, 1);
+        BigDecimal result1 = mapper.processRow(resultSet, 0, new Criteria());
+        BigDecimal result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(new BigDecimal(0), result1);
@@ -107,7 +108,7 @@ public class BigDecimalMapperTest extend
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/CompositeMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/CompositeMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/CompositeMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/CompositeMapperTest.java Sun Nov 18 15:29:55 2012
@@ -28,6 +28,7 @@ import java.util.List;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -42,26 +43,29 @@ public class CompositeMapperTest extends
 
     /** Mock delegate RecordMapper. */
     @Mock
-    private RecordMapper recordMapper1;
+    private RecordMapper<?> recordMapper1;
 
     /** Mock delegate RecordMapper. */
     @Mock
-    private RecordMapper recordMapper2;
+    private RecordMapper<Integer> recordMapper2;
 
     /** Mock delegate RecordMapper. */
     @Mock
-    private RecordMapper recordMapper3;
+    private RecordMapper<Long> recordMapper3;
+
+    /** The fake criteria which produced the query .*/
+    private Criteria criteria = new Criteria();
 
     @Override
     public void setUp() throws Exception
     {
         super.setUp();
         MockitoAnnotations.initMocks(this);
-        when(recordMapper1.processRow(resultSet, 3))
+        when(recordMapper1.processRow(resultSet,3, criteria))
             .thenReturn(null);
-        when(recordMapper2.processRow(resultSet, 4))
+        when(recordMapper2.processRow(resultSet, 4, criteria))
             .thenReturn(new Integer(1));
-        when(recordMapper3.processRow(resultSet, 5))
+        when(recordMapper3.processRow(resultSet, 5, criteria))
             .thenReturn(new Long(2));
 
         mapper = new CompositeMapper();
@@ -78,16 +82,16 @@ public class CompositeMapperTest extends
     public void testProcessRow() throws Exception
     {
         // execute
-        List<Object> result = mapper.processRow(resultSet, 2);
+        List<Object> result = mapper.processRow(resultSet, 2, criteria);
 
         // verify
         assertEquals(3, result.size());
         assertEquals(null, result.get(0));
         assertEquals(new Integer(1), result.get(1));
         assertEquals(new Long(2), result.get(2));
-        verify(recordMapper1).processRow(resultSet, 3);
-        verify(recordMapper2).processRow(resultSet, 4);
-        verify(recordMapper3).processRow(resultSet, 5);
+        verify(recordMapper1).processRow(resultSet, 3, criteria);
+        verify(recordMapper2).processRow(resultSet, 4, criteria);
+        verify(recordMapper3).processRow(resultSet, 5, criteria);
         verifyNoMoreInteractions(resultSet);
     }
 
@@ -99,13 +103,13 @@ public class CompositeMapperTest extends
     public void testProcessRowSqlException() throws Exception
     {
         // prepare
-        when(recordMapper1.processRow(resultSet, 1))
+        when(recordMapper1.processRow(resultSet, 1, criteria))
             .thenThrow(new TorqueException("thrown by mock"));
 
         // execute
         try
         {
-            mapper.processRow(resultSet, 0);
+            mapper.processRow(resultSet, 0, criteria);
             // verify 1
             fail("Exception expected");
         }
@@ -113,7 +117,7 @@ public class CompositeMapperTest extends
         {
             // verify 2
             assertEquals("thrown by mock", e.getMessage());
-            verify(recordMapper1).processRow(resultSet, 1);
+            verify(recordMapper1).processRow(resultSet, 1, criteria);
             verifyNoMoreInteractions(resultSet);
         }
     }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/DateMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/DateMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/DateMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/DateMapperTest.java Sun Nov 18 15:29:55 2012
@@ -29,6 +29,7 @@ import java.util.Date;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -63,8 +64,8 @@ public class DateMapperTest extends Base
         DateMapper mapper = new DateMapper();
 
         // execute
-        Date result1 = mapper.processRow(resultSet, 0);
-        Date result2 = mapper.processRow(resultSet, 1);
+        Date result1 = mapper.processRow(resultSet, 0, null);
+        Date result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(null, result1);
@@ -85,8 +86,8 @@ public class DateMapperTest extends Base
         DateMapper mapper = new DateMapper(1);
 
         // execute
-        Date result1 = mapper.processRow(resultSet, 0);
-        Date result2 = mapper.processRow(resultSet, 1);
+        Date result1 = mapper.processRow(resultSet, 0, new Criteria());
+        Date result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(new Date(0), result1);
@@ -109,7 +110,7 @@ public class DateMapperTest extends Base
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/IntegerMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/IntegerMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/IntegerMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/IntegerMapperTest.java Sun Nov 18 15:29:55 2012
@@ -28,6 +28,7 @@ import java.sql.SQLException;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -61,8 +62,8 @@ public class IntegerMapperTest extends B
         IntegerMapper mapper = new IntegerMapper();
 
         // execute
-        Integer result1 = mapper.processRow(resultSet, 0);
-        Integer result2 = mapper.processRow(resultSet, 1);
+        Integer result1 = mapper.processRow(resultSet, 0, new Criteria());
+        Integer result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(null, result1);
@@ -85,8 +86,8 @@ public class IntegerMapperTest extends B
         IntegerMapper mapper = new IntegerMapper(1);
 
         // execute
-        Integer result1 = mapper.processRow(resultSet, 0);
-        Integer result2 = mapper.processRow(resultSet, 1);
+        Integer result1 = mapper.processRow(resultSet, 0, null);
+        Integer result2 = mapper.processRow(resultSet, 1, new Criteria());
 
         // verify
         assertEquals(Integer.valueOf(-273343444), result1);
@@ -109,7 +110,7 @@ public class IntegerMapperTest extends B
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/LongMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/LongMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/LongMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/LongMapperTest.java Sun Nov 18 15:29:55 2012
@@ -28,6 +28,7 @@ import java.sql.SQLException;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -61,8 +62,8 @@ public class LongMapperTest extends Base
         LongMapper mapper = new LongMapper();
 
         // execute
-        Long result1 = mapper.processRow(resultSet, 0);
-        Long result2 = mapper.processRow(resultSet, 1);
+        Long result1 = mapper.processRow(resultSet, 0, new Criteria());
+        Long result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(null, result1);
@@ -85,8 +86,8 @@ public class LongMapperTest extends Base
         LongMapper mapper = new LongMapper(1);
 
         // execute
-        Long result1 = mapper.processRow(resultSet, 0);
-        Long result2 = mapper.processRow(resultSet, 1);
+        Long result1 = mapper.processRow(resultSet, 0, null);
+        Long result2 = mapper.processRow(resultSet, 1, new Criteria());
 
         // verify
         assertEquals(Long.valueOf(-2733434442345777L), result1);
@@ -109,7 +110,7 @@ public class LongMapperTest extends Base
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/ObjectListMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/ObjectListMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/ObjectListMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/ObjectListMapperTest.java Sun Nov 18 15:29:55 2012
@@ -43,6 +43,7 @@ import java.util.List;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -132,7 +133,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper();
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(3, result.size());
@@ -160,7 +161,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper();
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 1);
+        List<Object> result = mapper.processRow(resultSet, 1, new Criteria());
 
         // verify
         assertEquals(2, result.size());
@@ -184,7 +185,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(2);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 1);
+        List<Object> result = mapper.processRow(resultSet, 1, new Criteria());
 
         // verify
         assertEquals(2, result.size());
@@ -229,7 +230,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, null);
 
         // verify
         assertEquals(22, result.size());
@@ -295,7 +296,7 @@ public class ObjectListMapperTest extend
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }
@@ -325,7 +326,7 @@ public class ObjectListMapperTest extend
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }
@@ -350,7 +351,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(1, result.size());
@@ -371,7 +372,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(1, result.size());
@@ -391,7 +392,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(1, result.size());
@@ -411,7 +412,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(1, result.size());
@@ -431,7 +432,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(1, result.size());
@@ -451,7 +452,7 @@ public class ObjectListMapperTest extend
         ObjectListMapper mapper = new ObjectListMapper(classList);
 
         // execute
-        List<Object> result = mapper.processRow(resultSet, 0);
+        List<Object> result = mapper.processRow(resultSet, 0, new Criteria());
 
         // verify
         assertEquals(1, result.size());

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/StringMapperTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/StringMapperTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/StringMapperTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/om/mapper/StringMapperTest.java Sun Nov 18 15:29:55 2012
@@ -28,6 +28,7 @@ import java.sql.SQLException;
 
 import org.apache.torque.BaseTestCase;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -60,8 +61,8 @@ public class StringMapperTest extends Ba
         StringMapper mapper = new StringMapper();
 
         // execute
-        String result1 = mapper.processRow(resultSet, 0);
-        String result2 = mapper.processRow(resultSet, 1);
+        String result1 = mapper.processRow(resultSet, 0, new Criteria());
+        String result2 = mapper.processRow(resultSet, 1, null);
 
         // verify
         assertEquals(null, result1);
@@ -82,8 +83,8 @@ public class StringMapperTest extends Ba
         StringMapper mapper = new StringMapper(1);
 
         // execute
-        String result1 = mapper.processRow(resultSet, 0);
-        String result2 = mapper.processRow(resultSet, 1);
+        String result1 = mapper.processRow(resultSet, 0, null);
+        String result2 = mapper.processRow(resultSet, 1, new Criteria());
 
         // verify
         assertEquals("", result1);
@@ -106,7 +107,7 @@ public class StringMapperTest extends Ba
         // execute
         try
         {
-            mapper.processRow(resultSet, -1);
+            mapper.processRow(resultSet, -1, new Criteria());
             // verify 1
             fail("Exception expected");
         }

Modified: db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml (original)
+++ db/torque/torque4/trunk/torque-site/src/site/xdoc/documentation/orm-reference/read-from-db.xml Sun Nov 18 15:29:55 2012
@@ -876,6 +876,48 @@ List<String> authorNames = BasePeer.doSe
 </source>
   </section>
 
+  <section name="Partal selects">
+
+    <p>
+      In a partial select, only a part of the attributes of an object
+      is filled. This is often done for performance reasons, especially
+      if one of the columns is a BLOB or CLOB column.
+      A partial select is constructed by using the addSelectColumn method
+      in the Criteria object. For example, to read all books but fill only
+      the bookId and title attributes, use the following Criteria:
+   </p>
+
+<source>
+Criteria criteria = new Criteria()
+    .addSelectColumn(BookPeer.BOOK_ID)
+    .addSelectColumn(BookPeer.TITLE);
+</source>
+
+    <p>
+      whic corresponds to the expected SQL query
+   </p>
+   
+<source>
+SELECT BOOK.BOOK_ID, BOOK.TITLE FROM BOOK;
+</source>
+
+    <p>
+      Two final notes:
+   </p>
+   
+   <ul>
+     <li>
+       The primary key of the objects should always be filled,
+       otherwise the equals and hashCode methods will not work properly.
+     </li>
+     <li>
+       Beware when saving partially filled objects to the database.
+       You might empty the columns you have not read in the database.
+     </li>
+   </ul>
+    
+  </section>
+
   <section name="Using a Column twice in a Criteria">
 
     <p>

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/basePeer.xml Sun Nov 18 15:29:55 2012
@@ -68,9 +68,6 @@
     <mergepoint name="inheritanceClasskeyConstants">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.inheritanceClasskeyConstants"/>
     </mergepoint>
-    <mergepoint name="resultSet2Objects">
-      <action xsi:type="applyAction" outlet="torque.om.peer.base.resultSet2Objects"/>
-    </mergepoint>
     <mergepoint name="doInsert">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.doInsert"/>
     </mergepoint>
@@ -190,9 +187,6 @@
     <mergepoint name="inheritanceClasskeyConstants">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.inheritanceClasskeyConstants"/>
     </mergepoint>
-    <mergepoint name="resultSet2Objects">
-      <action xsi:type="applyAction" outlet="torque.om.peer.base.resultSet2Objects"/>
-    </mergepoint>
     <mergepoint name="addSelectColumns">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.addSelectColumns"/>
     </mergepoint>
@@ -329,11 +323,6 @@
       path="peer/base/inheritanceClasskeyConstants.vm">
   </outlet>
 
-  <outlet name="torque.om.peer.base.resultSet2Objects"
-      xsi:type="velocityOutlet"
-      path="peer/base/resultSet2Objects.vm">
-  </outlet>
-
   <outlet name="torque.om.peer.base.doInsert"
       xsi:type="velocityOutlet"
       path="peer/base/doInsert.vm">

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeer.vm Sun Nov 18 15:29:55 2012
@@ -51,7 +51,6 @@ $torqueGen.mergepoint("staticInit")
 $torqueGen.mergepoint("peerImplCreator")
 $torqueGen.mergepoint("peerImplGetter")
 $torqueGen.mergepoint("peerImplSetter")
-$torqueGen.mergepoint("resultSet2Objects")
 $torqueGen.mergepoint("addSelectColumns")
 $torqueGen.mergepoint("correctBooleans")
 $torqueGen.mergepoint("doSelect")

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/basePeerForView.vm Sun Nov 18 15:29:55 2012
@@ -53,7 +53,6 @@ $torqueGen.mergepoint("staticInit")
 $torqueGen.mergepoint("peerImplCreator")
 $torqueGen.mergepoint("peerImplGetter")
 $torqueGen.mergepoint("peerImplSetter")
-$torqueGen.mergepoint("resultSet2Objects")
 $torqueGen.mergepoint("addSelectColumns")
 $torqueGen.mergepoint("correctBooleans")
 $torqueGen.mergepoint("doSelect")

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/recordmapper/base/recordMapperBase.vm Sun Nov 18 15:29:55 2012
@@ -31,8 +31,13 @@ package ${baseRecordMapperPackage};
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.List;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.Column;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
 import org.apache.torque.om.mapper.RecordMapper;
 
 #if (${baseRecordMapperPackage} != $dbObjectPackage)
@@ -41,6 +46,10 @@ import ${dbObjectPackage}.${dbObjectClas
 #if (${baseRecordMapperPackage} != $peerPackage)
 import ${peerPackage}.${peerClassName};
 #end
+#if (${baseRecordMapperPackage} != $basePeerPackage)
+import ${basePeerPackage}.${basePeerClassName};
+#end
+
 #set ( $inheritanceBaseColumnElements = $torqueGen.getChildren("inheritance-column"))
 ## there should at most be one inheritance-column in each table
 #foreach ($inheritanceBaseColumnElement in $inheritanceBaseColumnElements)
@@ -55,7 +64,6 @@ import ${dbObjectPackage}.${inheritanceC
     #end
   #end
 #end
-    
 /**
  * Maps ResultSet rows into ${dbObjectClassName} objects.
  *
@@ -68,19 +76,36 @@ import ${dbObjectPackage}.${inheritanceC
  */
 public class ${baseRecordMapperClassName} implements RecordMapper<${dbObjectClassName}>
 {
+
+    /** The class log. */
+    private static Log log
+            = LogFactory.getLog(${baseRecordMapperClassName}.class);
+
     /**
      * Constructs the object from the current row in the resultSet.
      *
      * @param resultSet the resultSet to operate on, already pointing
      *        to the correct row. Not null.
-     * @param a possible offset in the rows to be considered
-     *        (if previous rows contain other objects).
+     * @param a possible offset in the columns to be considered
+     *        (if previous columns contain other objects),
+     *        or 0 for no offset.
+     * @param criteria The criteria which created the result set.
+     *        If set, the attributes to set in the data object
+     *        are determined from the select columns in the criteria;
+     *        if no matching column can be found, null is returned.
+     *        If not set, all of the table's columns are read from the
+     *        result set in the order defined in the table definition.
      *
      * @return the mapped object, not null.
      *
-     * @throws TorqueException when reading fields from the RecordSet fails.
+     * @throws TorqueException when reading fields from the RecordSet fails
+     *         or if a Criteria is passed which contains select columns other
+     *         than the columns in the ${name} table.
      */
-    public $dbObjectClassName processRow(ResultSet resultSet, int offset)
+    public $dbObjectClassName processRow(
+                ResultSet resultSet,
+                int offset,
+                CriteriaInterface<?> criteria)
             throws TorqueException
     {
 #set ( $inheritanceBaseColumnElement = $torqueGen.getChild("inheritance-column") )
@@ -94,14 +119,52 @@ $torqueGen.mergepoint("createDbObjectIns
         {
             ${field}.setLoading(true);
 #end
+            if (criteria == null)
+            {
 #set ( $n = 1 )
 #foreach ($columnElement in $torqueGen.getChildren("column"))
   #set ( $setter = $columnElement.getAttribute("setter") )
   #set ( $getter = $columnElement.getAttribute("getter") )
-            ${field}.${setter}(
-                    ${getter}(resultSet, offset + $n));
+                ${field}.${setter}(
+                        ${getter}(resultSet, offset + $n));
   #set ( $n = $n + 1 )
 #end
+            }
+            else
+            {
+                // try to get columns to be mapped
+                // from criteria's select columns
+                boolean columnMapped = false;
+                int totalOffset = offset + 1;
+                List<Column> selectColumns = criteria.getSelectColumns();
+                List<Column> columnsWithoutOffset = selectColumns.subList(
+                        offset, 
+                        selectColumns.size());
+                for (Column column : columnsWithoutOffset)
+                {
+#set ( $else = "" )
+#foreach ($columnElement in $torqueGen.getChildren("column"))
+  #set ( $setter = $columnElement.getAttribute("setter") )
+  #set ( $getter = $columnElement.getAttribute("getter") )
+  #set ( $peerColumnName = $columnElement.getAttribute("peerColumnName") )
+                    ${else}if (${basePeerClassName}.${peerColumnName}.getSqlExpression().equals(
+                            column.getSqlExpression()))
+                    {
+                        ${field}.${setter}(
+                            ${getter}(resultSet, totalOffset));
+                        columnMapped = true;
+                    }
+  #set ( $else = "else ")
+#end
+                    totalOffset++;
+                }
+                if (!columnMapped)
+                {
+                    log.debug("no columns to map found in criteria, "
+                        + "returning null");
+                    return null;
+                }
+            }
             ${field}.setNew(false);
             ${field}.setModified(false);
 #if ($trackLoading == "true")

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Sun Nov 18 15:29:55 2012
@@ -35,6 +35,7 @@ import org.apache.torque.adapter.DerbyAd
 import org.apache.torque.adapter.MssqlAdapter;
 import org.apache.torque.adapter.MysqlAdapter;
 import org.apache.torque.criteria.Criteria;
+import org.apache.torque.criteria.CriteriaInterface;
 import org.apache.torque.criteria.Criterion;
 import org.apache.torque.om.mapper.CompositeMapper;
 import org.apache.torque.om.mapper.IntegerMapper;
@@ -1562,7 +1563,10 @@ public class DataTest extends BaseDataba
     static class DoNothingMapper implements RecordMapper<Object>
     {
 
-        public Object processRow(ResultSet resultSet, int rowOffset)
+        public Object processRow(
+                    ResultSet resultSet,
+                    int rowOffset,
+                    CriteriaInterface<?> criteria)
                 throws TorqueException
         {
             return null;

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java?rev=1410897&r1=1410896&r2=1410897&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java Sun Nov 18 15:29:55 2012
@@ -26,10 +26,13 @@ import org.apache.torque.BaseDatabaseTes
 import org.apache.torque.TooManyRowsException;
 import org.apache.torque.Torque;
 import org.apache.torque.criteria.Criteria;
+import org.apache.torque.om.mapper.CompositeMapper;
 import org.apache.torque.test.dbobject.Author;
 import org.apache.torque.test.dbobject.Book;
 import org.apache.torque.test.peer.AuthorPeer;
 import org.apache.torque.test.peer.BookPeer;
+import org.apache.torque.test.recordmapper.AuthorRecordMapper;
+import org.apache.torque.test.recordmapper.BookRecordMapper;
 
 /**
  * Tests simple selects.
@@ -249,4 +252,99 @@ public class SelectTest extends BaseData
         List<Book> books = BookPeer.doSelect(criteria);
         assertEquals(90, books.size());
     }
+
+    /**
+     * Tests a partial select where only a part of the object's attributes
+     * are filled and no other columns are read.
+     *
+     * @throws Exception if the test fails.
+     */
+    public void testPartialSelectOnlyOwnColumns() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        Book bookToSelect = authorList.get(0).getBooks().get(0);
+        criteria.where(BookPeer.BOOK_ID, bookToSelect.getBookId());
+        criteria.addSelectColumn(BookPeer.BOOK_ID);
+        criteria.addSelectColumn(BookPeer.TITLE);
+
+        List<Book> books = BookPeer.doSelect(criteria);
+        assertEquals(1, books.size());
+        Book selectedBook = books.get(0);
+        assertEquals(bookToSelect.getBookId(), selectedBook.getBookId());
+        assertEquals(bookToSelect.getTitle(), selectedBook.getTitle());
+        assertEquals(null, selectedBook.getIsbn());
+        assertEquals(0, selectedBook.getAuthorId());
+    }
+
+    /**
+     * Tests a partial select where only a part of the object's attributes
+     * are filled and an offset is used.
+     *
+     * @throws Exception if the test fails.
+     */
+    public void testPartialSelectOffset() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        Book bookToSelect = authorList.get(0).getBooks().get(0);
+        criteria.where(BookPeer.BOOK_ID, bookToSelect.getBookId());
+        criteria.addSelectColumn(BookPeer.BOOK_ID);
+        criteria.addSelectColumn(BookPeer.TITLE);
+        // use CompositeMapper to enforce offset
+        CompositeMapper recordMapper = new CompositeMapper();
+        recordMapper.addMapper(new BookRecordMapper(), 1);
+
+        List<List<Object>> books = BookPeer.doSelect(criteria, recordMapper);
+        assertEquals(1, books.size());
+        Book selectedBook = (Book) books.get(0).get(0);
+        assertEquals(0, selectedBook.getBookId());
+        assertEquals(bookToSelect.getTitle(), selectedBook.getTitle());
+        assertEquals(null, selectedBook.getIsbn());
+        assertEquals(0, selectedBook.getAuthorId());
+    }
+
+    /**
+     * Tests a partial select where only a part of the object's attributes
+     * are filled and foreign columns are also read.
+     *
+     * @throws Exception if the test fails.
+     */
+    public void testPartialSelectForeignColumns() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        Book bookToSelect = authorList.get(0).getBooks().get(0);
+        criteria.where(BookPeer.BOOK_ID, bookToSelect.getBookId());
+        criteria.addSelectColumn(AuthorPeer.AUTHOR_ID);
+        criteria.addSelectColumn(BookPeer.BOOK_ID);
+        criteria.addSelectColumn(AuthorPeer.NAME);
+        criteria.addSelectColumn(BookPeer.TITLE);
+        criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
+
+        List<Book> books = BookPeer.doSelect(criteria);
+        assertEquals(1, books.size());
+        Book selectedBook = books.get(0);
+        assertEquals(bookToSelect.getBookId(), selectedBook.getBookId());
+        assertEquals(bookToSelect.getTitle(), selectedBook.getTitle());
+        assertEquals(null, selectedBook.getIsbn());
+        assertEquals(0, selectedBook.getAuthorId());
+    }
+
+    /**
+     * Tests a partial select where only a part of the object's attributes
+     * are filled and no other columns are read. It is expected that the
+     * record mapper returns null.
+     *
+     * @throws Exception if the test fails.
+     */
+    public void testPartialSelectNoOwnColumns() throws Exception
+    {
+        Book bookToSelect = authorList.get(0).getBooks().get(0);
+        Criteria criteria = new Criteria()
+                .where(BookPeer.BOOK_ID, bookToSelect.getBookId())
+                .addSelectColumn(BookPeer.BOOK_ID);
+
+        List<Author> authors = BookPeer.doSelect(
+                criteria, new AuthorRecordMapper());
+        assertEquals(1, authors.size());
+        assertEquals(null, authors.get(0));
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message