cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r722019 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc: EntityRowReader.java JDBCResultIterator.java
Date Mon, 01 Dec 2008 10:00:31 GMT
Author: aadamchik
Date: Mon Dec  1 02:00:29 2008
New Revision: 722019

URL: http://svn.apache.org/viewvc?rev=722019&view=rev
Log:
CAY-1140 Store ObjEntity name in the DataRow

fixing issues resulting from CAY-1136 code merge

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EntityRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EntityRowReader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EntityRowReader.java?rev=722019&r1=722018&r2=722019&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EntityRowReader.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EntityRowReader.java
Mon Dec  1 02:00:29 2008
@@ -23,7 +23,7 @@
 
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.DataRow;
-import org.apache.cayenne.query.EntityResult;
+import org.apache.cayenne.query.EntityResultMetadata;
 import org.apache.cayenne.query.QueryMetadata;
 import org.apache.cayenne.util.Util;
 
@@ -36,10 +36,10 @@
     private int mapCapacity;
 
     EntityRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata,
-            EntityResult entityResult) {
+            EntityResultMetadata entityResult) {
         super(descriptor, queryMetadata);
 
-        Map<String, String> fields = entityResult.getDbFields();
+        Map<String, String> fields = entityResult.getFields();
 
         this.mapCapacity = (int) Math.ceil((fields.size()) / 0.75);
         this.valueIndices = new int[fields.size()];

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java?rev=722019&r1=722018&r2=722019&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
Mon Dec  1 02:00:29 2008
@@ -32,9 +32,8 @@
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.ResultIterator;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.query.EntityResult;
 import org.apache.cayenne.query.QueryMetadata;
-import org.apache.cayenne.query.SQLResultSetMapping;
+import org.apache.cayenne.query.SQLResultSetMetadata;
 
 /**
  * A ResultIterator over the underlying JDBC ResultSet.
@@ -91,28 +90,39 @@
             RowDescriptor descriptor,
             QueryMetadata queryMetadata) {
 
-        SQLResultSetMapping rsMapping = queryMetadata.getResultSetMapping();
+        SQLResultSetMetadata rsMapping = queryMetadata.getResultSetMapping();
         if (rsMapping != null) {
 
-            List<?> resultDescriptors = rsMapping.getResultDescriptors();
-            int resultWidth = resultDescriptors.size();
+            int resultWidth = rsMapping.getSegmentsCount();
+            int[] entitySegments = rsMapping.getEntitySegments();
+            int[] scalarSegments = rsMapping.getScalarSegments();
 
             if (resultWidth == 0) {
                 throw new CayenneRuntimeException("Empty result descriptor");
             }
             else if (resultWidth == 1) {
-                return createSegmentRowReader(
-                        descriptor,
-                        queryMetadata,
-                        resultDescriptors.get(0));
+
+                if (entitySegments.length > 0) {
+                    return new EntityRowReader(descriptor, queryMetadata, rsMapping
+                            .getEntitySegment(entitySegments[0]));
+                }
+                else {
+                    return new ScalarRowReader(descriptor, rsMapping
+                            .getScalarSegment(scalarSegments[0]));
+                }
             }
             else {
                 CompoundRowReader reader = new CompoundRowReader(resultWidth);
-                for (int i = 0; i < resultWidth; i++) {
-                    reader.addRowReader(i, createSegmentRowReader(
+                for (int i : entitySegments) {
+                    reader.addRowReader(i, new EntityRowReader(
                             descriptor,
                             queryMetadata,
-                            resultDescriptors.get(i)));
+                            rsMapping.getEntitySegment(entitySegments[i])));
+                }
+
+                for (int i : scalarSegments) {
+                    reader.addRowReader(i, new ScalarRowReader(descriptor, rsMapping
+                            .getScalarSegment(scalarSegments[i])));
                 }
 
                 return reader;
@@ -123,26 +133,6 @@
         }
     }
 
-    private RowReader<?> createSegmentRowReader(
-            RowDescriptor descriptor,
-            QueryMetadata queryMetadata,
-            Object segmentDescriptor) {
-
-        if (segmentDescriptor instanceof String) {
-            return new ScalarRowReader(descriptor, (String) segmentDescriptor);
-        }
-        else if (segmentDescriptor instanceof EntityResult) {
-            return new EntityRowReader(
-                    descriptor,
-                    queryMetadata,
-                    (EntityResult) segmentDescriptor);
-        }
-        else {
-            throw new IllegalArgumentException(
-                    "Expected either String or Entity Result: " + segmentDescriptor);
-        }
-    }
-
     private RowReader<?> createFullRowReader(
             RowDescriptor descriptor,
             QueryMetadata queryMetadata) {



Mime
View raw message