db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r414934 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/
Date Fri, 16 Jun 2006 21:41:10 GMT
Author: arminw
Date: Fri Jun 16 14:41:09 2006
New Revision: 414934

URL: http://svn.apache.org/viewvc?rev=414934&view=rev
Log:
adapt classes to support the improved handling of advanced jdbc data types (like JAVA_OBJECT)

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessFactory.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.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/java/org/apache/ojb/broker/accesslayer/RsIterator.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessFactory.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessFactory.java?rev=414934&r1=414933&r2=414934&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessFactory.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessFactory.java
Fri Jun 16 14:41:09 2006
@@ -16,11 +16,12 @@
  */
 
 import org.apache.ojb.broker.PersistenceBroker;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.util.factory.ConfigurableFactory;
 
 /**
+ * Factory to create {@link JdbcAccess} instances.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class JdbcAccessFactory extends ConfigurableFactory
@@ -43,6 +44,6 @@
 
     public JdbcAccess createJdbcAccess(PersistenceBroker broker)
     {
-        return (JdbcAccess) createNewInstance(PersistenceBroker.class, broker);
+        return (JdbcAccess) createNewInstance(PersistenceBrokerInternal.class, broker);
     }
 }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java?rev=414934&r1=414933&r2=414934&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
Fri Jun 16 14:41:09 2006
@@ -25,12 +25,12 @@
 
 import org.apache.ojb.broker.Identity;
 import org.apache.ojb.broker.OptimisticLockException;
-import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.PersistenceBrokerSQLException;
-import org.apache.ojb.broker.lob.LobHandle;
 import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
 import org.apache.ojb.broker.core.ValueContainer;
+import org.apache.ojb.broker.lob.LobHandle;
 import org.apache.ojb.broker.metadata.ArgumentDescriptor;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
@@ -45,11 +45,10 @@
 import org.apache.ojb.broker.util.sequence.SequenceManagerException;
 
 /**
- * JdbcAccess is responsible for establishing performing
- * SQL Queries against remote Databases.
- * It hides all knowledge about JDBC from the BrokerImpl
+ * JdbcAccess is responsible for establishing performing SQL Queries against remote
+ * Databases. It hides all knowledge about JDBC from the associated
+ * {@link org.apache.ojb.broker.PersistenceBroker}.
  *
- * @author <a href="mailto:thma@apache.org">Thomas Mahler</a>
  * @version $Id$
  */
 public class JdbcAccessImpl implements JdbcAccess
@@ -62,13 +61,13 @@
     /**
      * The broker in use.
      */
-    protected PersistenceBroker broker;
+    protected PersistenceBrokerInternal broker;
 
     /**
      * constructor is private, use getInstance to get
      * the singleton instance of this class
      */
-    public JdbcAccessImpl(PersistenceBroker broker)
+    public JdbcAccessImpl(PersistenceBrokerInternal broker)
     {
         this.broker = broker;
         logger = LoggerFactory.getLogger(this.getClass());
@@ -294,7 +293,7 @@
                 rs = stmt.executeQuery();
             }
 
-            return new ResultSetAndStatement(sm, stmt, rs, sql);
+            return new ResultSetAndStatement(broker, stmt, rs, sql);
         }
         catch (PersistenceBrokerException e)
         {
@@ -358,7 +357,7 @@
 
             // as we return the resultset for further operations, we cannot release the statement
yet.
             // that has to be done by the JdbcAccess-clients (i.e. RsIterator, ProxyRsIterator
and PkEnumeration.)
-            return new ResultSetAndStatement(sm, stmt, rs, new SelectStatement()
+            return new ResultSetAndStatement(broker, stmt, rs, new SelectStatement()
             {
                 public Query getQueryInstance()
                 {
@@ -592,16 +591,12 @@
             sm.bindSelect(stmt, oid, cld, false);
             rs = stmt.executeQuery();
             // data available read object, else return null
-            ResultSetAndStatement rs_stmt = new ResultSetAndStatement(broker.serviceStatementManager(),
stmt, rs, sql);
+            ResultSetAndStatement rs_stmt = new ResultSetAndStatement(broker, stmt, rs, sql);
             if (rs.next())
             {
                 Map row = new HashMap();
                 cld.getRowReader().readObjectArrayFrom(rs_stmt, row);
                 result = cld.getRowReader().readObjectFrom(row);
-
-                // TODO: Wrap LOB-fields in RowReader in next major version
-                // wrap LOB fields
-                broker.serviceLobHelper().wrapLobFields(cld, result);
             }
             // close resources
             rs_stmt.close();
@@ -723,11 +718,9 @@
             {
                 // Get the value and convert it to it's appropriate
                 // java type.
-                Object value = fmd.getJdbcType().getObjectFromColumn(callable, index);
-
+                Object value = fmd.readValue(broker, callable, index, true);
                 // Set the value of the persistent field.
-                fmd.getPersistentField().set(obj, fmd.getFieldConversion().sqlToJava(value));
-
+                fmd.getPersistentField().set(obj, value);
             }
         }
         catch (SQLException e)

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java?rev=414934&r1=414933&r2=414934&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java
Fri Jun 16 14:41:09 2006
@@ -34,7 +34,9 @@
  * this class can be used to create enumerations of PrimaryKey objects.
  * This is interesting for EJB finder methods
  * in BMP entity beans which must return such enumerations.
+ *
  * @author Thomas Mahler
+ * @deprecated will be removed in next version.
  * @version $Id$
  */
 public class PkEnumeration implements Enumeration
@@ -110,7 +112,7 @@
             for (int i = 0; i < pkfields.length; i++)
             {
                 fld = pkfields[i];
-                colValue = fld.getJdbcType().getObjectFromColumn(resultSetAndStatment.m_rs,
fld.getColumnName());
+                colValue = fld.readValue(resultSetAndStatment, true);
                 fld.getPersistentField().set(obj, colValue);
             }
             // 3. return the representing identity object

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java?rev=414934&r1=414933&r2=414934&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ReportQueryRsIterator.java
Fri Jun 16 14:41:09 2006
@@ -21,8 +21,8 @@
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.core.PersistenceBrokerImpl;
 import org.apache.ojb.broker.metadata.FieldDescriptor;
-import org.apache.ojb.broker.metadata.JdbcTypesHelper;
 import org.apache.ojb.broker.metadata.JdbcType;
+import org.apache.ojb.broker.metadata.JdbcTypesHelper;
 import org.apache.ojb.broker.query.ReportQuery;
 
 /**
@@ -58,7 +58,6 @@
     {
         Object[] result = new Object[m_attributeCount];
         ReportQuery q =(ReportQuery) getQueryObject().getQuery();
-
         for (int i = 0; i < m_attributeCount; i++)
         {
             try
@@ -68,15 +67,15 @@
                 Object val;
                 if(fld != null)
                 {
-                    val = fld.getJdbcType().getObjectFromColumn(getRsAndStmt().m_rs, i +
1);
-                    val = fld.getFieldConversion().sqlToJava(val);
+                    val = fld.readValue(getRsAndStmt(), i+1, true);
                 }
                 else
                 {
+                    // if we don't know the associated FieldDescriptor we have to use
+                    // basic methods to read in the value
                     int jdbcType = extractJdbcType(i);
                     JdbcType type = JdbcTypesHelper.getJdbcTypeByTypesIndex(new Integer(jdbcType));
                     val = type.getObjectFromColumn(getRsAndStmt().m_rs, i + 1);
-                    //val =JdbcTypesHelper.getObjectFromColumn(getRsAndStmt().m_rs, new Integer(jdbcType),
i + 1);
                 }
                 result[i] = val;
             }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java?rev=414934&r1=414933&r2=414934&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/ResultSetAndStatement.java
Fri Jun 16 14:41:09 2006
@@ -18,18 +18,18 @@
 import java.sql.ResultSet;
 import java.sql.Statement;
 
+import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.accesslayer.sql.SelectStatement;
+import org.apache.ojb.broker.platforms.Platform;
 
 /**
  * Intern used wrapper for {@link Statement} and {@link ResultSet} instances.
+ * Make sure that after use of this class method {@link #close()} was called.
  *
  * @version $Id$
  */
-public class ResultSetAndStatement
+public final class ResultSetAndStatement
 {
-	// private static Logger log = LoggerFactory.getLogger(ResultSetAndStatement.class);
-
-	private final StatementManagerIF manager;
     private boolean isClosed;
     /*
     arminw: declare final to avoid stmt/rs leaking in use
@@ -38,10 +38,13 @@
     public final ResultSet m_rs;
     public final Statement m_stmt;
     public final SelectStatement m_sql;
+    public final PersistenceBrokerInternal m_broker;
+    public final Platform m_platform;
 
-	public ResultSetAndStatement(StatementManagerIF manager, Statement stmt, ResultSet rs, SelectStatement
sql)
+    public ResultSetAndStatement(PersistenceBrokerInternal broker, Statement stmt, ResultSet
rs, SelectStatement sql)
     {
-		this.manager = manager;
+        this.m_broker = broker;
+        this.m_platform = broker.serviceConnectionManager().getSupportedPlatform();
         m_stmt = stmt;
         m_rs = rs;
         m_sql = sql;
@@ -49,7 +52,7 @@
     }
 
     /**
-     * do a platform specific resource release.
+     * Do a platform specific resource release.
      * <br/>
      * Note: This method must be called after usage
      * of this class.
@@ -58,7 +61,7 @@
     {
         if(!isClosed)
         {
-            manager.closeResources(m_stmt, m_rs);
+            m_broker.serviceStatementManager().closeResources(m_stmt, m_rs);
             isClosed = true;
         }
     }

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=414934&r1=414933&r2=414934&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
Fri Jun 16 14:41:09 2006
@@ -33,7 +33,7 @@
  */
 public class RowReaderDefaultImpl implements RowReader
 {
-    /** 
+    /**
      * Used as key in result set row map.
      */
     private static final String OJB_CONCRETE_CLASS_KEY = "ojbTemporaryNoneColumnKey";
@@ -203,8 +203,8 @@
                 else
                 {
                     fields = m_cld.getFieldDescriptor(true);
-                }           
-            }         
+                }
+            }
         }
         readValuesFrom(rs_stmt, row, fields);
     }
@@ -217,7 +217,7 @@
 
         String ojbClass = SqlHelper.getOjbClassName(rs_stmt);
         ClassDescriptor cld;
-        
+
         if (ojbClass != null)
         {
             cld = m_cld.getRepository().getDescriptorFor(ojbClass);
@@ -234,18 +234,19 @@
     public void readValuesFrom(ResultSetAndStatement rs_stmt, Map row, FieldDescriptor[]
fields)
     {
         int size = fields.length;
-        Object val;
         FieldDescriptor fld = null;
         try
         {
+            Object value;
             for (int j = 0; j < size; j++)
             {
                 fld = fields[j];
                 if(!row.containsKey(fld.getColumnName()))
                 {
-                    int idx = rs_stmt.m_sql.getColumnIndex(fld);
-                    val = fld.getJdbcType().getObjectFromColumn(rs_stmt.m_rs, null, fld.getColumnName(),
idx);
-                    row.put(fld.getColumnName(), fld.getFieldConversion().sqlToJava(val));
+                    // Get the value and convert it to it's appropriate
+                    // java type.
+                    value = fld.readValue(rs_stmt, true);
+                    row.put(fld.getColumnName(), value);
                 }
             }
         }

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java?rev=414934&r1=414933&r2=414934&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
Fri Jun 16 14:41:09 2006
@@ -33,6 +33,8 @@
 import org.apache.ojb.broker.PersistenceBrokerException;
 import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.PersistenceBrokerSQLException;
+import org.apache.ojb.broker.lob.LobHandle;
+import org.apache.ojb.broker.platforms.Platform;
 import org.apache.ojb.broker.cache.MaterializationCache;
 import org.apache.ojb.broker.cache.ObjectCacheInternal;
 import org.apache.ojb.broker.core.PersistenceBrokerImpl;
@@ -484,10 +486,6 @@
                             // fill reference and collection attributes
                             ClassDescriptor cld = pb.getClassDescriptor(result.getClass());
 
-                            // TODO: Wrap LOB-fields in RowReader in next major version
-                            // wrap LOB fields
-                            pb.serviceLobHelper().wrapLobFields(cld, result);
-
                             // don't force loading of reference
                             pb.getReferenceBroker().retrieveReferences(result, cld, false);
                             pb.getReferenceBroker().retrieveCollections(result, cld, false);
@@ -515,19 +513,25 @@
                     // map all field values from the current result set
                     rowReader.readObjectArrayFrom(getRsAndStmt(), row);
                     rowReader.refreshObject(result, row);
-
-                    // TODO: Wrap LOB-fields in RowReader in next major version
-                    // wrap LOB fields
-                    pb.serviceLobHelper().wrapLobFields(cld, result);
                 }
                 else if(cld.hasLobField() && pb.serviceLobHelper().isLobAutoRefresh())
                 {
                     /*
-                    TODO: Improve! Find better solution
+                    If the object has LOB content we have to re-read the locator
+                    object of cached objects
                     */
                     FieldDescriptor[] flds = cld.getLobFields();
-                    writeFields(getRsAndStmt(), rowReader, row, flds, result);
-                    pb.serviceLobHelper().wrapLobFields(cld, result);
+                    for(int i = 0; i < flds.length; i++)
+                    {
+                        FieldDescriptor fld = flds[i];
+                        LobHandle lob = (LobHandle) fld.getPersistentField().get(result);
+                        // if LOB content isn't active, we have to re-read content
+                        if(!lob.isActive())
+                        {
+                            rowReader.readValuesFrom(getRsAndStmt(), row, new FieldDescriptor[]{fld});
+                            fld.getPersistentField().set(result, row.get(fld.getColumnName()));
+                        }
+                    }
                 }
                 pb.checkRefreshRelationships(result, oid, cld);
             }
@@ -537,20 +541,6 @@
     }
 
     /**
-     * Write the specified fields from result set into the target object.
-     */
-    private void writeFields(ResultSetAndStatement rs_stmt, RowReader rowReader, Map row,
FieldDescriptor[] fields, Object target)
-    {
-        rowReader.readValuesFrom(rs_stmt, row, fields);
-        FieldDescriptor fmd;
-        for (int i = 0; i < fields.length; i++)
-        {
-            fmd = fields[i];
-            fmd.getPersistentField().set(target, row.get(fmd.getColumnName()));
-        }
-    }
-
-    /**
      * Reads primary key information from current RS row and generates a
      *
      * corresponding Identity, and returns a proxy from the Identity.
@@ -642,9 +632,7 @@
         {
             //ignore it
         }
-        if (!supportsAdvancedJDBCCursorControl()
-                || getBroker().serviceConnectionManager().getSupportedPlatform().useCountForResultsetSize()
-                || forwardOnly)
+        if (!supportsAdvancedJDBCCursorControl() || getPlatform().useCountForResultsetSize()
|| forwardOnly)
         {
             /**
              * MBAIRD: doesn't support the .last .getRow method, use the
@@ -932,6 +920,11 @@
     protected JdbcConnectionDescriptor getConnectionDescriptor()
     {
         return getBroker().serviceConnectionManager().getConnectionDescriptor();
+    }
+
+    protected Platform getPlatform()
+    {
+        return getBroker().serviceConnectionManager().getSupportedPlatform();
     }
 
     /**



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