db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r371251 - in /db/ojb/trunk/src/java/org/apache/ojb/broker: accesslayer/ accesslayer/sql/ util/
Date Sun, 22 Jan 2006 09:28:04 GMT
Author: brj
Date: Sun Jan 22 01:27:57 2006
New Revision: 371251

URL: http://svn.apache.org/viewcvs?rev=371251&view=rev
Log:
applied armins fix for OJB-91

Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java Sun Jan 22
01:27:57 2006
@@ -620,6 +620,11 @@
                 {
                     return sql;
                 }
+
+                public boolean isUseOjbClassColumn()
+                {
+                    return false;
+                }
             });
         }
         catch(PersistenceBrokerException e)

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java Sun
Jan 22 01:27:57 2006
@@ -282,7 +282,7 @@
             }
             else
             {
-                String ojbClass = SqlHelper.getOjbClassName(rs_stmt.m_rs);
+                String ojbClass = SqlHelper.getOjbClassName(rs_stmt);
                 if (ojbClass != null)
                 {
                     ClassDescriptor cld = classDescriptor.getRepository().getDescriptorFor(ojbClass);
@@ -304,7 +304,7 @@
      */
     public void readPkValuesFrom(ResultSetAndStatement rs_stmt, Map row)
     {       
-        String ojbClass = SqlHelper.getOjbClassName(rs_stmt.m_rs);
+        String ojbClass = SqlHelper.getOjbClassName(rs_stmt);
         ClassDescriptor cld;
         
         if (ojbClass != null)

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatement.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatement.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatement.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SelectStatement.java Sun Jan
22 01:27:57 2006
@@ -15,11 +15,8 @@
  * limitations under the License.
  */
 
-import java.lang.Object;
-import java.sql.ResultSet;
-
-import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.query.Query;
 
 /**
  * This class
@@ -46,4 +43,12 @@
      * column index is not supported.
      */
     public int getColumnIndex(FieldDescriptor fld);
+    
+    /**
+     * If "table-per-subclass"-inheritance is used for the class specified in
+     * the {@link org.apache.ojb.broker.query.Query} the name of the "real" class to
+     * instantiate for each row of the result set was hold by a pseudo column - In this
+     * case this method returns <em>true</em>.
+     */
+    public boolean isUseOjbClassColumn();
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java
(original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureFKStatement.java
Sun Jan 22 01:27:57 2006
@@ -40,7 +40,6 @@
  */
 public class SqlProcedureFKStatement implements SelectStatement
 {
-
     /**
      * The descriptor that defines the procedure to invoke.
      */
@@ -81,9 +80,11 @@
     {
         // Collect criteria name/values
         HashMap values = new HashMap();
-        for (Enumeration e = query.getCriteria().getElements(); e.hasMoreElements();) {
+        for (Enumeration e = query.getCriteria().getElements(); e.hasMoreElements();)
+        {
             SelectionCriteria c = (SelectionCriteria) e.nextElement();
-            if (c.getValue() != null) {
+            if (c.getValue() != null)
+            {
                 values.put(c.getAttribute(), c.getValue());
             }
         }
@@ -106,9 +107,12 @@
         {
             ArgumentDescriptor argument = (ArgumentDescriptor) i.next();
             Object value = values.get(argument.getFieldRefName());
-            if (value == null) {
+            if (value == null)
+            {
                 sb.append("NULL");
-            } else {
+            } 
+            else
+            {
                 sb.append("?");
             }
 
@@ -128,5 +132,13 @@
     public int getColumnIndex(FieldDescriptor fld)
     {
         return JdbcType.MIN_INT;
+    }
+
+    /**
+     * @see org.apache.ojb.broker.accesslayer.sql.SelectStatement#isUseOjbClassColumn()
+     */
+    public boolean isUseOjbClassColumn()
+    {
+        return false;
     }
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java
(original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlProcedureStatement.java
Sun Jan 22 01:27:57 2006
@@ -32,7 +32,6 @@
 
 public class SqlProcedureStatement implements SelectStatement
 {
-
     /**
      * The descriptor that defines the procedure to invoke.
      */
@@ -100,5 +99,13 @@
     public int getColumnIndex(FieldDescriptor fld)
     {
         return JdbcType.MIN_INT;
+    }
+
+    /**
+     * @see org.apache.ojb.broker.accesslayer.sql.SelectStatement#isUseOjbClassColumn()
+     */
+    public boolean isUseOjbClassColumn()
+    {
+        return false;
     }
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java Sun
Jan 22 01:27:57 2006
@@ -45,6 +45,7 @@
 public class SqlSelectStatement extends SqlQueryStatement implements SelectStatement
 {
     private WeakReference fieldsForSelect;
+    private boolean useOjbClassColumn;
 
     /**
      * Constructor for SqlSelectStatement.
@@ -165,6 +166,9 @@
         }
         buf.append(" ELSE '").append(cld.getClassNameOfObject()).append("'");
         buf.append(" END AS " + SqlHelper.OJB_CLASS_COLUMN);
+
+        // signal the use of the ojbClassColumn
+        setUseOjbClassColumn(true);
     }
 
     /**
@@ -447,5 +451,18 @@
             }
         }
         return index;
+    }
+    
+    /**
+     * @see org.apache.ojb.broker.accesslayer.sql.SelectStatement#isUseOjbClassColumn()
+     */
+    public boolean isUseOjbClassColumn()
+    {
+        return useOjbClassColumn;
+    }
+
+    protected void setUseOjbClassColumn(boolean useOjbClassColumn)
+    {
+        this.useOjbClassColumn = useOjbClassColumn;
     }
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java?rev=371251&r1=371250&r2=371251&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/SqlHelper.java Sun Jan 22 01:27:57 2006
@@ -4,6 +4,9 @@
 import java.sql.SQLException;
 import java.util.StringTokenizer;
 
+import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
+
 /* Copyright 2002-2004 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -137,15 +140,20 @@
      * @param rs the Resultset
      * @return null if the column is not available
      */
-    public static String getOjbClassName(ResultSet rs)
+    public static String getOjbClassName(ResultSetAndStatement rsAndStmt)
     {
-        try
-        {
-            return rs.getString(OJB_CLASS_COLUMN);
-        }
-        catch (SQLException e)
+        String result = null;
+        if (rsAndStmt.m_sql != null && rsAndStmt.m_sql.isUseOjbClassColumn())
         {
-            return null;
+            try
+            {
+                result = rsAndStmt.m_rs.getString(OJB_CLASS_COLUMN);
+            }
+            catch (SQLException e)
+            {
+                throw new PersistenceBrokerException("Cannot access " + OJB_CLASS_COLUMN,
e);
+            }
         }
+        return result;
     }
 }



---------------------------------------------------------------------
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