cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r409068 - /incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/jdbc/JDBCResultIterator.java
Date Wed, 24 May 2006 04:23:18 GMT
Author: aadamchik
Date: Tue May 23 21:23:18 2006
New Revision: 409068

URL: http://svn.apache.org/viewvc?rev=409068&view=rev
Log:
CAY-525 - saving a few CPU cycles on big result processing by caching the column labels and
JDBC types.

Modified:
    incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/jdbc/JDBCResultIterator.java

Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/jdbc/JDBCResultIterator.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/jdbc/JDBCResultIterator.java?rev=409068&r1=409067&r2=409068&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/jdbc/JDBCResultIterator.java
(original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/jdbc/JDBCResultIterator.java
Tue May 23 21:23:18 2006
@@ -105,6 +105,9 @@
     protected boolean nextRow;
     protected int fetchedSoFar;
     protected int fetchLimit;
+    
+    private String[] labels;
+    private int[] types;
 
     /**
      * Creates new JDBCResultIterator that reads from provided ResultSet.
@@ -122,6 +125,19 @@
         this.mapCapacity = (int) Math.ceil((descriptor.getWidth()) / 0.75);
 
         checkNextRow();
+        
+        if(nextRow) {
+            // extract column parameters to speed up processing...
+            ColumnDescriptor[] columns = descriptor.getColumns();
+            int width = columns.length;
+            labels = new String[width];
+            types = new int[width];
+            
+            for(int i = 0; i < width; i++) {
+                labels[i] = columns[i].getLabel();
+                types[i] = columns[i].getJdbcType();
+            }
+        }
     }
 
     /**
@@ -302,18 +318,17 @@
         try {
             DataRow dataRow = new DataRow(mapCapacity);
             ExtendedType[] converters = rowDescriptor.getConverters();
-            ColumnDescriptor[] columns = rowDescriptor.getColumns();
-            int resultWidth = rowDescriptor.getWidth();
+
+            int resultWidth = labels.length;
 
             // process result row columns,
             for (int i = 0; i < resultWidth; i++) {
                 // note: jdbc column indexes start from 1, not 0 unlike everywhere else
-                Object val = converters[i].materializeObject(resultSet, i + 1, columns[i]
-                        .getJdbcType());
-                dataRow.put(columns[i].getLabel(), val);
+                Object val = converters[i].materializeObject(resultSet, i + 1, types[i]);
+                dataRow.put(labels[i], val);
             }
-            
-            if(postProcessor != null) {
+
+            if (postProcessor != null) {
                 postProcessor.postprocessRow(resultSet, dataRow);
             }
 
@@ -337,7 +352,6 @@
         try {
             DataRow idRow = new DataRow(2);
             ExtendedType[] converters = rowDescriptor.getConverters();
-            ColumnDescriptor[] columns = rowDescriptor.getColumns();
             int len = pkIndices.length;
 
             for (int i = 0; i < len; i++) {
@@ -349,11 +363,11 @@
                 Object val = converters[index].materializeObject(
                         resultSet,
                         index + 1,
-                        columns[index].getJdbcType());
-                idRow.put(columns[index].getLabel(), val);
+                        types[index]);
+                idRow.put(labels[index], val);
             }
-            
-            if(postProcessor != null) {
+
+            if (postProcessor != null) {
                 postProcessor.postprocessRow(resultSet, idRow);
             }
 



Mime
View raw message