db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r410605 - in /db/ojb/branches/OJB_1_0_RELEASE/src: java/org/apache/ojb/broker/accesslayer/RowReader.java java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java
Date Wed, 31 May 2006 17:15:56 GMT
Author: arminw
Date: Wed May 31 10:15:55 2006
New Revision: 410605

URL: http://svn.apache.org/viewvc?rev=410605&view=rev
Log:
add new method, javadoc update

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReader.java?rev=410605&r1=410604&r2=410605&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
Wed May 31 10:15:55 2006
@@ -19,48 +19,71 @@
 import java.util.Map;
 
 import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
 
 /**
+ * This class is responsible to map a query result set row to the specified
+ * {@link java.util.Map}. 
+ *
  * @version $Id$
  */
 public interface RowReader extends Serializable
 {
-	static final long serialVersionUID = -1283322922537162249L;    /**
-     * materialize a single object from the values of the Map row.
-     * the implementor of this class must not care for materializing
-     * references or collection attributes, this is done later! 
+    static final long serialVersionUID = -1283322922537162249L;
+
+    /**
+     * Materialize a single object from the values of the Map row.
+     * The implementor of this class must not care for materializing
+     * references or collection attributes, this is done later!
+     *
      * @param row the Map containing the new values
      * @return a properly created instance.
      */
     public Object readObjectFrom(Map row);
 
     /**
-     * refresh an existing instance from the values of the Map row.
+     * Refresh an existing instance from the values of the Map row.
+     *
      * @param instance the instance to refresh
      * @param row the Map containing the new values
      */
     public void refreshObject(Object instance, Map row);
 
 
-	/**
-	 * Read all fields from the current ResultRow into the Object[] row.#
-	 * ConversionStrategies are applied here!
-	 */
-	public void readObjectArrayFrom(ResultSetAndStatement rs, Map row);
-
-	/**
-	 * Read primary key fields from the current ResultRow into the Object[] row.#
-	 * ConversionStrategies are applied here!
-	 */
-	public void readPkValuesFrom(ResultSetAndStatement rs, Map row);
+    /**
+     * Read all fields from the current ResultRow into the Object[] row.#
+     * ConversionStrategies are applied here!
+     *
+     * @param rs Current result set.
+     * @param row The target map.
+     */
+    public void readObjectArrayFrom(ResultSetAndStatement rs, Map row);
+
+    /**
+     * Read primary key fields from the current ResultRow into the Object[] row.#
+     * ConversionStrategies are applied here!
+     *
+     * @param rs Current result set.
+     * @param row The target map.
+     */
+    public void readPkValuesFrom(ResultSetAndStatement rs, Map row);
 
     /**
      * Set the descriptor this <i>RowReader</i> worked with.
+     *
+     * @param cld The {@link org.apache.ojb.broker.metadata.ClassDescriptor}.
      */
     public void setClassDescriptor(ClassDescriptor cld);
 
+    /** Returns the associated {@link org.apache.ojb.broker.metadata.ClassDescriptor} */
+    public ClassDescriptor getClassDescriptor();
+
     /**
-     * Returns the associated {@link org.apache.ojb.broker.metadata.ClassDescriptor}
+     * Read the specified field into the row map.
+     *
+     * @param rs Current result set.
+     * @param row The target map.
+     * @param fields The fields to read from result set.
      */
-    public ClassDescriptor getClassDescriptor();
+    public void readValuesFrom(ResultSetAndStatement rs, Map row, FieldDescriptor[] fields);
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java?rev=410605&r1=410604&r2=410605&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
Wed May 31 10:15:55 2006
@@ -37,6 +37,7 @@
      * Used as key in result set row map.
      */
     private static final String OJB_CONCRETE_CLASS_KEY = "ojbTemporaryNoneColumnKey";
+
     /**
      * represents a zero sized parameter array
      */
@@ -135,7 +136,8 @@
                 }
                 catch (Exception ex)
                 {
-                    throw new PersistenceBrokerException("Unable to invoke initialization
method:" + initializationMethod.getName() + " for class:" + m_cld.getClassOfObject(), ex);
+                    throw new PersistenceBrokerException("Unable to invoke initialization
method:"
+                            + initializationMethod.getName() + " for class:" + m_cld.getClassOfObject(),
ex);
                 }
             }
         }
@@ -229,7 +231,7 @@
         readValuesFrom(rs_stmt, row, pkFields);
     }
 
-    protected void readValuesFrom(ResultSetAndStatement rs_stmt, Map row, FieldDescriptor[]
fields)
+    public void readValuesFrom(ResultSetAndStatement rs_stmt, Map row, FieldDescriptor[]
fields)
     {
         int size = fields.length;
         Object val;
@@ -258,38 +260,41 @@
 
     protected String extractOjbConcreteClass(ClassDescriptor cld, ResultSet rs, Map row)
     {
+        String result = null;
         FieldDescriptor fld = m_cld.getOjbConcreteClassField();
-        if (fld == null)
+        if (fld != null)
         {
-            return null;
-        }
-        try
-        {
-            Object tmp = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
-            // allow field-conversion for discriminator column too
-            String result = (String) fld.getFieldConversion().sqlToJava(tmp);
-            result = result != null ? result.trim() : null;
-            if (result == null || result.length() == 0)
+            // First check for already existing entry to avoid multiple result set lookup
+            result = (String) row.get(fld.getColumnName());
+            if(result == null)
             {
-                throw new PersistenceBrokerException(
-                        "ojbConcreteClass field for class " + cld.getClassNameOfObject()
-                        + " returned null or 0-length string");
-            }
-            else
-            {
-                /*
-                arminw: Make sure that we don't read discriminator field twice from the ResultSet.
-                */
-                row.put(fld.getColumnName(), result);
-                return result;
+                try
+                {
+                        Object tmp = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
+                        // allow field-conversion for discriminator column too
+                        result = (String) fld.getFieldConversion().sqlToJava(tmp);
+                        result = result != null ? result.trim() : null;
+                        if (result == null || result.length() == 0)
+                        {
+                            throw new PersistenceBrokerException(
+                                    "ojbConcreteClass field for class " + cld.getClassNameOfObject()
+                                    + " returned 'null' or 0-length string");
+                        }
+                        else
+                        {
+                            // Make sure that we don't read discriminator field twice from
the ResultSet
+                            row.put(fld.getColumnName(), result);
+                        }
+                }
+                catch(SQLException e)
+                {
+                    throw new PersistenceBrokerException("Unexpected error while try to read
'ojbConcretClass'" +
+                            " field from result set using column name " + fld.getColumnName()
+ " main class" +
+                            " was " + m_cld.getClassNameOfObject(), e);
+                }
             }
         }
-        catch(SQLException e)
-        {
-            throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'"
+
-                    " field from result set using column name " + fld.getColumnName() + "
main class" +
-                    " was " + m_cld.getClassNameOfObject(), e);
-        }
+        return result;
     }
 
     /**
@@ -302,12 +307,6 @@
         if(ojbConcreteClass != null)
         {
             result = m_cld.getRepository().getDescriptorFor(ojbConcreteClass);
-            // if we can't find class-descriptor for concrete class, something wrong with
mapping
-            if (result == null)
-            {
-                throw new PersistenceBrokerException("Can't find class-descriptor for ojbConcreteClass
'"
-                        + ojbConcreteClass + "', the main class was " + m_cld.getClassNameOfObject());
-            }
         }
         return result;
     }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java?rev=410605&r1=410604&r2=410605&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/xdoclet/test/xdoclet/modules/ojb/tests/TestRowReader.java
Wed May 31 10:15:55 2006
@@ -21,6 +21,7 @@
 import org.apache.ojb.broker.accesslayer.RowReader;
 import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
 
 /**
  * Row reader class used in some of the unit tests.
@@ -51,5 +52,9 @@
     public ClassDescriptor getClassDescriptor()
     {
         return null;
+    }
+
+    public void readValuesFrom(ResultSetAndStatement rs, Map row, FieldDescriptor[] fields)
+    {
     }
 }



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


Mime
View raw message