cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r722016 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/ main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/access/util/ main/java/org/...
Date Mon, 01 Dec 2008 09:55:43 GMT
Author: aadamchik
Date: Mon Dec  1 01:55:29 2008
New Revision: 722016

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

added entity name to DataRow;
injecting entity name into the DataRow on creation;
added row reading strategy to the JDBCResultIterator with inheritance support

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/FullRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/IdRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/InheritanceAwareRowReader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/RowReader.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/TransactionResultIteratorDecorator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/util/DistinctResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java Mon Dec  1 01:55:29 2008
@@ -48,6 +48,11 @@
     protected long version = currentVersion++;
     protected long replacesVersion = DataObject.DEFAULT_VERSION;
 
+    /**
+     * @since 3.0
+     */
+    protected String entityName;
+
     public DataRow(Map<String, ?> map) {
         super(map);
     }
@@ -88,9 +93,9 @@
     /**
      * Creates a DataRow that contains only the keys that have values that differ between
      * this object and <code>row</code> parameter. Diff values are taken from the
-     * <code>row</code> parameter. It is assumed that key sets are compatible in both
-     * rows (e.g. they represent snapshots for the same entity). Returns null if no
-     * differences are found.
+     * <code>row</code> parameter. It is assumed that key sets are compatible in both rows
+     * (e.g. they represent snapshots for the same entity). Returns null if no differences
+     * are found.
      */
     public DataRow createDiff(DataRow row) {
 
@@ -216,4 +221,18 @@
                 " version",
                 version).append(" replaces", replacesVersion).toString();
     }
+
+    /**
+     * @since 3.0
+     */
+    public String getEntityName() {
+        return entityName;
+    }
+
+    /**
+     * @since 3.0
+     */
+    public void setEntityName(String entityName) {
+        this.entityName = entityName;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/IncrementalFaultList.java Mon Dec  1 01:55:29 2008
@@ -34,7 +34,6 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.QueryMetadata;
@@ -233,9 +232,8 @@
                 }
 
                 // continue reading ids
-                DbEntity entity = rootEntity.getDbEntity();
                 while (it.hasNextRow()) {
-                    elementsList.add(it.nextId(entity));
+                    elementsList.add(it.nextId());
                 }
 
                 QueryLogger.logSelectCount(elementsList.size(), System

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java Mon Dec  1 01:55:29 2008
@@ -49,8 +49,8 @@
     ClassDescriptor descriptor;
     Collection<DbAttribute> primaryKey;
 
-    EntityInheritanceTree inheritanceTree;
     DataRowStore cache;
+    DescriptorResolutionStrategy descriptorResolutionStrategy;
 
     ObjectResolver(DataContext context, ClassDescriptor descriptor) {
         init(context, descriptor);
@@ -77,8 +77,13 @@
         this.context = context;
         this.cache = context.getObjectStore().getDataRowCache();
         this.descriptor = descriptor;
-        this.inheritanceTree = context.getEntityResolver().lookupInheritanceTree(
-                descriptor.getEntity());
+
+        EntityInheritanceTree inheritanceTree = context
+                .getEntityResolver()
+                .lookupInheritanceTree(descriptor.getEntity());
+        this.descriptorResolutionStrategy = inheritanceTree != null
+                ? new InheritanceStrategy()
+                : new NoInheritanceStrategy();
     }
 
     /**
@@ -194,19 +199,8 @@
     Persistent objectFromDataRow(DataRow row) {
 
         // determine entity to use
-        ClassDescriptor classDescriptor;
-
-        if (inheritanceTree != null) {
-            ObjEntity objectEntity = inheritanceTree.entityMatchingRow(row);
-
-            // null probably means that inheritance qualifiers are messed up
-            classDescriptor = (objectEntity != null) ? context
-                    .getEntityResolver()
-                    .getClassDescriptor(objectEntity.getName()) : descriptor;
-        }
-        else {
-            classDescriptor = descriptor;
-        }
+        ClassDescriptor classDescriptor = descriptorResolutionStrategy
+                .descriptorForRow(row);
 
         // not using DataRow.createObjectId for performance reasons - ObjectResolver has
         // all needed metadata already cached.
@@ -312,4 +306,26 @@
 
         return new ObjectId(objEntity.getName(), idMap);
     }
+
+    interface DescriptorResolutionStrategy {
+        ClassDescriptor descriptorForRow(DataRow row);
+    }
+
+    class NoInheritanceStrategy implements DescriptorResolutionStrategy {
+
+        public final ClassDescriptor descriptorForRow(DataRow row) {
+            return descriptor;
+        }
+    }
+
+    class InheritanceStrategy implements DescriptorResolutionStrategy {
+
+        public final ClassDescriptor descriptorForRow(DataRow row) {
+            String entityName = row.getEntityName();
+
+            // null probably means that inheritance qualifiers are messed up
+            return (entityName != null) ? context.getEntityResolver().getClassDescriptor(
+                    entityName) : descriptor;
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ResultIterator.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ResultIterator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ResultIterator.java Mon Dec  1 01:55:29 2008
@@ -31,7 +31,6 @@
  * execution. Usually a ResultIterator is supported by an open java.sql.ResultSet,
  * therefore most of the methods would throw checked exceptions. ResultIterators must be
  * explicitly closed when the user is done working with them.
- * 
  */
 public interface ResultIterator {
 
@@ -62,14 +61,14 @@
     Map<String, Object> nextObjectId(DbEntity entity) throws CayenneException;
 
     /**
-     * Reads and returns an id column or columns for the DbEntity. If an entity has a
-     * single column id, the return value is an Object matching the column type (e.g.
-     * java.lang.Long). If an entity has a compound PK, the return value is a DataRow
-     * (i.e. equivalent to {@link #nextObjectId(DbEntity)}).
+     * Reads and returns an id column or columns for the current row DbEntity. If an
+     * entity has a single column id, the return value is an Object matching the column
+     * type (e.g. java.lang.Long). If an entity has a compound PK, the return value is a
+     * DataRow.
      * 
      * @since 3.0
      */
-    Object nextId(DbEntity entity) throws CayenneException;
+    Object nextId() throws CayenneException;
 
     /**
      * Skips current data row instead of reading it.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/TransactionResultIteratorDecorator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/TransactionResultIteratorDecorator.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/TransactionResultIteratorDecorator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/TransactionResultIteratorDecorator.java Mon Dec  1 01:55:29 2008
@@ -105,8 +105,8 @@
     /**
      * @since 3.0
      */
-    public Object nextId(DbEntity entity) throws CayenneException {
-        return result.nextId(entity);
+    public Object nextId() throws CayenneException {
+        return result.nextId();
     }
 
     public void skipDataRow() throws CayenneException {

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseRowReader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseRowReader.java?rev=722016&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseRowReader.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseRowReader.java Mon Dec  1 01:55:29 2008
@@ -0,0 +1,64 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access.jdbc;
+
+import java.sql.ResultSet;
+
+import org.apache.cayenne.CayenneException;
+import org.apache.cayenne.access.types.ExtendedType;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.QueryMetadata;
+
+/**
+ * @since 3.0
+ */
+abstract class BaseRowReader<T> implements RowReader<T> {
+
+    ExtendedType[] converters;
+    String[] labels;
+    int[] types;
+    DataRowPostProcessor postProcessor;
+    String entityName;
+
+    BaseRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata) {
+        ObjEntity rootObjEntity = queryMetadata.getObjEntity();
+        if (rootObjEntity != null) {
+            this.entityName = rootObjEntity.getName();
+        }
+
+        this.converters = descriptor.getConverters();
+
+        ColumnDescriptor[] columns = descriptor.getColumns();
+        int width = columns.length;
+        this.labels = new String[width];
+        this.types = new int[width];
+
+        for (int i = 0; i < width; i++) {
+            labels[i] = columns[i].getLabel();
+            types[i] = columns[i].getJdbcType();
+        }
+    }
+
+    public abstract T readRow(ResultSet resultSet) throws CayenneException;
+
+    public void setPostProcessor(DataRowPostProcessor postProcessor) {
+        this.postProcessor = postProcessor;
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java Mon Dec  1 01:55:29 2008
@@ -68,15 +68,18 @@
         long t1 = System.currentTimeMillis();
 
         QueryMetadata metadata = query.getMetaData(getEntityResolver());
-       
 
         JDBCResultIterator resultReader = new JDBCResultIterator(
                 null,
                 null,
                 resultSet,
-                descriptor);
-        
-        LimitResultIterator it = new LimitResultIterator(resultReader, getInMemoryOffset(metadata.getFetchOffset()), metadata.getFetchLimit());
+                descriptor,
+                metadata);
+
+        LimitResultIterator it = new LimitResultIterator(
+                resultReader,
+                getInMemoryOffset(metadata.getFetchOffset()),
+                metadata.getFetchLimit());
 
         if (!delegate.isIteratedResult()) {
             List<DataRow> resultRows = it.dataRows(false);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java Mon Dec  1 01:55:29 2008
@@ -297,7 +297,8 @@
                 null,
                 null,
                 keysRS,
-                keyRowDescriptor);
+                keyRowDescriptor,
+                query.getMetaData(getEntityResolver()));
 
         observer.nextGeneratedDataRows(query, iterator);
     }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/FullRowReader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/FullRowReader.java?rev=722016&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/FullRowReader.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/FullRowReader.java Mon Dec  1 01:55:29 2008
@@ -0,0 +1,75 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access.jdbc;
+
+import java.sql.ResultSet;
+
+import org.apache.cayenne.CayenneException;
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.util.Util;
+
+/**
+ * @since 3.0
+ */
+class FullRowReader extends BaseRowReader<DataRow> {
+
+    int mapCapacity;
+
+    FullRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata) {
+        super(descriptor, queryMetadata);
+        this.mapCapacity = (int) Math.ceil((descriptor.getWidth()) / 0.75);
+    }
+
+    @Override
+    public DataRow readRow(ResultSet resultSet) throws CayenneException {
+        try {
+            DataRow dataRow = new DataRow(mapCapacity);
+
+            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, types[i]);
+                dataRow.put(labels[i], val);
+            }
+
+            postprocessRow(resultSet, dataRow);
+
+            return dataRow;
+        }
+        catch (CayenneException cex) {
+            // rethrow unmodified
+            throw cex;
+        }
+        catch (Exception otherex) {
+            throw new CayenneException("Exception materializing column.", Util
+                    .unwindException(otherex));
+        }
+    }
+
+    void postprocessRow(ResultSet resultSet, DataRow dataRow) throws Exception {
+        if (postProcessor != null) {
+            postProcessor.postprocessRow(resultSet, dataRow);
+        }
+
+        dataRow.setEntityName(entityName);
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/IdRowReader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/IdRowReader.java?rev=722016&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/IdRowReader.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/IdRowReader.java Mon Dec  1 01:55:29 2008
@@ -0,0 +1,127 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access.jdbc;
+
+import java.sql.ResultSet;
+
+import org.apache.cayenne.CayenneException;
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.util.Util;
+
+/**
+ * @since 3.0
+ */
+class IdRowReader extends BaseRowReader<Object> {
+
+    protected int[] pkIndices;
+
+    public IdRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata) {
+        super(descriptor, queryMetadata);
+
+        DbEntity dbEntity = queryMetadata.getDbEntity();
+        if (dbEntity == null) {
+            throw new CayenneRuntimeException("Null root DbEntity, can't index PK");
+        }
+
+        int len = dbEntity.getPrimaryKeys().size();
+
+        // sanity check
+        if (len == 0) {
+            throw new CayenneRuntimeException("Root DBEntity has no PK defined: "
+                    + dbEntity);
+        }
+
+        int[] pk = new int[len];
+        ColumnDescriptor[] columns = descriptor.getColumns();
+        for (int i = 0, j = 0; i < columns.length; i++) {
+            DbAttribute a = (DbAttribute) dbEntity.getAttribute(columns[i].getName());
+            if (a != null && a.isPrimaryKey()) {
+                pk[j++] = i;
+            }
+        }
+
+        this.pkIndices = pk;
+    }
+
+    @Override
+    public Object readRow(ResultSet resultSet) throws CayenneException {
+        try {
+            if (pkIndices.length == 1) {
+                return readSingleId(resultSet);
+            }
+            else {
+                return readIdMap(resultSet);
+            }
+        }
+        catch (CayenneException cex) {
+            // rethrow unmodified
+            throw cex;
+        }
+        catch (Exception otherex) {
+            throw new CayenneException("Exception materializing id column.", Util
+                    .unwindException(otherex));
+        }
+    }
+
+    private Object readSingleId(ResultSet resultSet) throws Exception {
+
+        // dereference column index
+        int index = pkIndices[0];
+
+        // note: jdbc column indexes start from 1, not 0 as in arrays
+        Object val = converters[index].materializeObject(
+                resultSet,
+                index + 1,
+                types[index]);
+
+        // note that postProcessor overrides are not applied. ID mapping must be the
+        // same across inheritance hierarchy, so overrides do not make sense.
+        return val;
+    }
+
+    private Object readIdMap(ResultSet resultSet) throws Exception {
+
+        DataRow idRow = new DataRow(2);
+        idRow.setEntityName(entityName);
+        int len = pkIndices.length;
+
+        for (int i = 0; i < len; i++) {
+
+            // dereference column index
+            int index = pkIndices[i];
+
+            // note: jdbc column indexes start from 1, not 0 as in arrays
+            Object val = converters[index].materializeObject(
+                    resultSet,
+                    index + 1,
+                    types[index]);
+            idRow.put(labels[index], val);
+        }
+
+        if (postProcessor != null) {
+            postProcessor.postprocessRow(resultSet, idRow);
+        }
+
+        return idRow;
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/InheritanceAwareRowReader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/InheritanceAwareRowReader.java?rev=722016&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/InheritanceAwareRowReader.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/InheritanceAwareRowReader.java Mon Dec  1 01:55:29 2008
@@ -0,0 +1,51 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access.jdbc;
+
+import java.sql.ResultSet;
+
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.map.EntityInheritanceTree;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.QueryMetadata;
+
+/**
+ * @since 3.0
+ */
+class InheritanceAwareRowReader extends FullRowReader {
+
+    private EntityInheritanceTree entityInheritanceTree;
+
+    InheritanceAwareRowReader(RowDescriptor descriptor, QueryMetadata queryMetadata) {
+        super(descriptor, queryMetadata);
+        this.entityInheritanceTree = queryMetadata
+                .getClassDescriptor()
+                .getEntityInheritanceTree();
+    }
+
+    @Override
+    void postprocessRow(ResultSet resultSet, DataRow dataRow) throws Exception {
+        if (postProcessor != null) {
+            postProcessor.postprocessRow(resultSet, dataRow);
+        }
+
+        ObjEntity entity = entityInheritanceTree.entityMatchingRow(dataRow);
+        dataRow.setEntityName(entity != null ? entity.getName() : entityName);
+    }
+}

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=722016&r1=722015&r2=722016&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 01:55:29 2008
@@ -28,20 +28,16 @@
 import java.util.Map;
 
 import org.apache.cayenne.CayenneException;
-import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.ResultIterator;
-import org.apache.cayenne.access.types.ExtendedType;
-import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.util.Util;
+import org.apache.cayenne.query.QueryMetadata;
 
 /**
  * A ResultIterator over the underlying JDBC ResultSet.
  * 
  * @since 1.2
  */
-// Replaces DefaultResultIterator
 public class JDBCResultIterator implements ResultIterator {
 
     // Connection information
@@ -50,51 +46,56 @@
     protected ResultSet resultSet;
 
     protected RowDescriptor rowDescriptor;
-
-    DataRowPostProcessor postProcessor;
+    protected QueryMetadata queryMetadata;
 
     // last indexed PK
-    protected DbEntity rootEntity;
-    protected int[] pkIndices;
-
-    protected int mapCapacity;
 
     protected boolean closingConnection;
     protected boolean closed;
 
     protected boolean nextRow;
 
-    private String[] labels;
-    private int[] types;
+    private DataRowPostProcessor postProcessor;
+    private RowReader<DataRow> rowReader;
+    private RowReader<Object> idRowReader;
 
     /**
      * Creates new JDBCResultIterator that reads from provided ResultSet.
+     * 
+     * @since 3.0
      */
     public JDBCResultIterator(Connection connection, Statement statement,
-            ResultSet resultSet, RowDescriptor descriptor)
+            ResultSet resultSet, RowDescriptor descriptor, QueryMetadata queryMetadata)
             throws CayenneException {
 
         this.connection = connection;
         this.statement = statement;
         this.resultSet = resultSet;
         this.rowDescriptor = descriptor;
-
-        this.mapCapacity = (int) Math.ceil((descriptor.getWidth()) / 0.75);
+        this.queryMetadata = queryMetadata;
 
         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();
-            }
+            this.rowReader = createRowReader(descriptor, queryMetadata);
+        }
+    }
+
+    /**
+     * RowReader factory method.
+     */
+    private RowReader<DataRow> createRowReader(
+            RowDescriptor descriptor,
+            QueryMetadata queryMetadata) {
+        
+        if (queryMetadata.getClassDescriptor() != null
+                && queryMetadata.getClassDescriptor().getEntityInheritanceTree() != null) {
+            return new InheritanceAwareRowReader(descriptor, queryMetadata);
         }
+        else {
+            return new FullRowReader(descriptor, queryMetadata);
+        }
+
     }
 
     /**
@@ -155,9 +156,9 @@
         }
 
         // index id
-        if (rootEntity != entity || pkIndices == null) {
-            this.rootEntity = entity;
-            indexPK();
+        if (idRowReader == null) {
+            this.idRowReader = new IdRowReader(rowDescriptor, queryMetadata);
+            idRowReader.setPostProcessor(postProcessor);
         }
 
         // read ...
@@ -174,19 +175,19 @@
     /**
      * @since 3.0
      */
-    public Object nextId(DbEntity entity) throws CayenneException {
+    public Object nextId() throws CayenneException {
         if (!hasNextRow()) {
             throw new CayenneException(
                     "An attempt to read uninitialized row or past the end of the iterator.");
         }
 
         // index id
-        if (rootEntity != entity || pkIndices == null) {
-            this.rootEntity = entity;
-            indexPK();
+        if (idRowReader == null) {
+            this.idRowReader = new IdRowReader(rowDescriptor, queryMetadata);
+            idRowReader.setPostProcessor(postProcessor);
         }
 
-        Object id = readId();
+        Object id = idRowReader.readRow(resultSet);
 
         // rewind
         checkNextRow();
@@ -200,7 +201,7 @@
         }
         checkNextRow();
     }
-    
+
     /**
      * Closes ResultIterator and associated ResultSet. This method must be called
      * explicitly when the user is finished processing the records. Otherwise unused
@@ -279,135 +280,33 @@
      * Reads a row from the internal ResultSet at the current cursor position.
      */
     protected Map<String, Object> readDataRow() throws CayenneException {
-        try {
-            DataRow dataRow = new DataRow(mapCapacity);
-            ExtendedType[] converters = rowDescriptor.getConverters();
-
-            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, types[i]);
-                dataRow.put(labels[i], val);
-            }
-
-            if (postProcessor != null) {
-                postProcessor.postprocessRow(resultSet, dataRow);
-            }
-
-            return dataRow;
-        }
-        catch (CayenneException cex) {
-            // rethrow unmodified
-            throw cex;
-        }
-        catch (Exception otherex) {
-            throw new CayenneException("Exception materializing column.", Util
-                    .unwindException(otherex));
-        }
-    }
-
-    protected Object readId() throws CayenneException {
-
-        int len = pkIndices.length;
-
-        if (len != 1) {
-            return readIdRow();
-        }
-
-        ExtendedType[] converters = rowDescriptor.getConverters();
-
-        try {
-
-            // dereference column index
-            int index = pkIndices[0];
-
-            // note: jdbc column indexes start from 1, not 0 as in arrays
-            Object val = converters[index].materializeObject(
-                    resultSet,
-                    index + 1,
-                    types[index]);
-
-            // note that postProcessor overrides are not applied. ID mapping must be the
-            // same across inheritance hierarchy, so overrides do not make sense.
-            return val;
-        }
-        catch (CayenneException cex) {
-            // rethrow unmodified
-            throw cex;
-        }
-        catch (Exception otherex) {
-            throw new CayenneException("Exception materializing id column.", Util
-                    .unwindException(otherex));
-        }
+        return rowReader.readRow(resultSet);
     }
 
     /**
      * Reads a row from the internal ResultSet at the current cursor position, processing
      * only columns that are part of the ObjectId of a target class.
+     * 
+     * @deprecated since 3.0 as the calling method is deprecated
      */
     protected Map<String, Object> readIdRow() throws CayenneException {
-        try {
-            DataRow idRow = new DataRow(2);
-            ExtendedType[] converters = rowDescriptor.getConverters();
-            int len = pkIndices.length;
-
-            for (int i = 0; i < len; i++) {
-
-                // dereference column index
-                int index = pkIndices[i];
-
-                // note: jdbc column indexes start from 1, not 0 as in arrays
-                Object val = converters[index].materializeObject(
-                        resultSet,
-                        index + 1,
-                        types[index]);
-                idRow.put(labels[index], val);
-            }
-
-            if (postProcessor != null) {
-                postProcessor.postprocessRow(resultSet, idRow);
-            }
-
-            return idRow;
-        }
-        catch (CayenneException cex) {
-            // rethrow unmodified
-            throw cex;
-        }
-        catch (Exception otherex) {
-            throw new CayenneException("Exception materializing id column.", Util
-                    .unwindException(otherex));
-        }
-    }
-
-    /**
-     * Creates an index of PK columns in the RowDescriptor.
-     */
-    protected void indexPK() {
-        if (rootEntity == null) {
-            throw new CayenneRuntimeException("Null root DbEntity, can't index PK");
-        }
+        Object value = idRowReader.readRow(resultSet);
 
-        int len = rootEntity.getPrimaryKeys().size();
-
-        // sanity check
-        if (len == 0) {
-            throw new CayenneRuntimeException("Root DbEntity has no PK defined: "
-                    + rootEntity);
+        if (value instanceof Map) {
+            return (Map<String, Object>) value;
         }
 
-        int[] pk = new int[len];
-        ColumnDescriptor[] columns = rowDescriptor.getColumns();
-        for (int i = 0, j = 0; i < columns.length; i++) {
-            DbAttribute a = (DbAttribute) rootEntity.getAttribute(columns[i].getName());
-            if (a != null && a.isPrimaryKey()) {
-                pk[j++] = i;
-            }
-        }
+        // wrap into a map...
 
-        this.pkIndices = pk;
+        String pkName = queryMetadata
+                .getDbEntity()
+                .getPrimaryKeys()
+                .iterator()
+                .next()
+                .getName();
+        DataRow dataRow = new DataRow(2);
+        dataRow.put(pkName, value);
+        return dataRow;
     }
 
     /**
@@ -430,7 +329,16 @@
         return rowDescriptor;
     }
 
+    // TODO: andrus 11/27/2008 refactor the postprocessor hack into a special row reader.
     void setPostProcessor(DataRowPostProcessor postProcessor) {
         this.postProcessor = postProcessor;
+
+        if (rowReader != null) {
+            rowReader.setPostProcessor(postProcessor);
+        }
+
+        if (idRowReader != null) {
+            idRowReader.setPostProcessor(postProcessor);
+        }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java Mon Dec  1 01:55:29 2008
@@ -74,9 +74,8 @@
 
     }
 
-    protected Map readDataRow() throws CayenneException {
-        Map<String, Object> next = wrappedIterator.nextDataRow();
-        return next;
+    private Map<String, Object> readDataRow() throws CayenneException {
+        return wrappedIterator.nextDataRow();
     }
 
     public void close() throws CayenneException {
@@ -84,19 +83,21 @@
     }
 
     public List dataRows(boolean close) throws CayenneException {
-        List<Map> list = new ArrayList<Map>();
+
+        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
 
         try {
             while (this.hasNextRow()) {
                 list.add(this.nextDataRow());
             }
-            return list;
         }
         finally {
             if (close) {
                 close();
             }
         }
+
+        return list;
     }
 
     public int getDataRowWidth() {
@@ -107,7 +108,7 @@
         return nextRow;
     }
 
-    public Map nextDataRow() throws CayenneException {
+    public Map<String, Object> nextDataRow() throws CayenneException {
         if (!hasNextRow()) {
             throw new CayenneException(
                     "An attempt to read uninitialized row or past the end of the iterator.");
@@ -118,14 +119,14 @@
         return row;
     }
 
-    public Object nextId(DbEntity entity) throws CayenneException {
+    public Object nextId() throws CayenneException {
         if (!hasNextRow()) {
             throw new CayenneException(
                     "An attempt to read uninitialized row or past the end of the iterator.");
         }
 
-        Object id = readId(entity);
-        checkNextId(entity);
+        Object id = readId();
+        checkNextId();
         return id;
 
     }
@@ -148,26 +149,22 @@
         wrappedIterator.skipDataRow();
     }
 
-    void checkNextId(DbEntity entity) throws CayenneException {
-        if (entity == null) {
-            throw new CayenneException("Null DbEntity, can't create id.");
-        }
+    void checkNextId() throws CayenneException {
         nextRow = false;
         if (wrappedIterator.hasNextRow()) {
             nextRow = true;
         }
     }
 
-    public Object readId(DbEntity entity) throws CayenneException {
-
-        Object next = wrappedIterator.nextId(entity);
+    private Object readId() throws CayenneException {
+        Object next = wrappedIterator.nextId();
         return next;
     }
 
+    /**
+     * @deprecated since 3.0
+     */
     void checkNextObjectId(DbEntity entity) throws CayenneException {
-        if (entity == null) {
-            throw new CayenneException("Null DbEntity, can't create id.");
-        }
 
         nextRow = false;
         nextDataObjectIds = null;

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/RowReader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/RowReader.java?rev=722016&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/RowReader.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/RowReader.java Mon Dec  1 01:55:29 2008
@@ -0,0 +1,40 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access.jdbc;
+
+import java.sql.ResultSet;
+
+import org.apache.cayenne.CayenneException;
+
+/**
+ * A strategy class that encapsulates an algorithm for converting a single ResultSet row
+ * into a DataRow.
+ * 
+ * @since 3.0
+ */
+interface RowReader<T> {
+
+    /**
+     * Extracts a DataRow from the ResultSet at its current position.
+     */
+    T readRow(ResultSet resultSet) throws CayenneException;
+
+    // TODO: andrus 11/27/2008 refactor the postprocessor hack into a special row reader.
+    void setPostProcessor(DataRowPostProcessor postProcessor);
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java Mon Dec  1 01:55:29 2008
@@ -41,6 +41,7 @@
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.QueryMetadata;
 import org.apache.cayenne.query.SQLAction;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.util.Util;
@@ -55,7 +56,7 @@
 
     protected DbAdapter adapter;
     protected SQLTemplate query;
-    protected ObjEntity entity;
+    protected QueryMetadata queryMetadata;
 
     /**
      * @deprecated since 3.0 use a
@@ -74,7 +75,7 @@
             EntityResolver entityResolver) {
         this.query = query;
         this.adapter = adapter;
-        this.entity = query.getMetaData(entityResolver).getObjEntity();
+        this.queryMetadata = query.getMetaData(entityResolver);
     }
 
     /**
@@ -215,7 +216,7 @@
             long startTime) throws Exception {
 
         boolean iteratedResult = callback.isIteratedResult();
-        
+
         ExtendedTypeMap types = adapter.getExtendedTypes();
         RowDescriptorBuilder builder = configureRowDescriptorBuilder(compiled, resultSet);
 
@@ -223,10 +224,12 @@
                 connection,
                 statement,
                 resultSet,
-                builder.getDescriptor(types));
-        
-        LimitResultIterator it = new LimitResultIterator(result, getFetchOffset(), query.getFetchLimit());
-        
+                builder.getDescriptor(types),
+                queryMetadata);
+
+        LimitResultIterator it = new LimitResultIterator(result, getFetchOffset(), query
+                .getFetchLimit());
+
         if (!iteratedResult) {
             List<DataRow> resultRows = it.dataRows(false);
             QueryLogger.logSelectCount(resultRows.size(), System.currentTimeMillis()
@@ -262,6 +265,7 @@
         else {
             builder.setResultSet(resultSet);
 
+            ObjEntity entity = queryMetadata.getObjEntity();
             if (entity != null) {
 
                 // TODO: andrus 2008/03/28 support flattened attributes with aliases...
@@ -350,7 +354,7 @@
     public SQLTemplate getQuery() {
         return query;
     }
-    
+
     /**
      * @since 3.0
      */

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java Mon Dec  1 01:55:29 2008
@@ -70,7 +70,7 @@
         SelectTranslator translator = createTranslator(connection);
         PreparedStatement prepStmt = translator.createStatement();
         ResultSet rs = prepStmt.executeQuery();
-
+        QueryMetadata md = query.getMetaData(getEntityResolver());
         RowDescriptor descriptor = new RowDescriptorBuilder().setColumns(
                 translator.getResultColumns()).getDescriptor(
                 getAdapter().getExtendedTypes());
@@ -79,7 +79,8 @@
                 connection,
                 prepStmt,
                 rs,
-                descriptor);
+                descriptor,
+                md);
 
         workerIterator.setPostProcessor(DataRowPostProcessor
                 .createPostProcessor(translator));
@@ -93,7 +94,6 @@
 
             final boolean[] compareFullRows = new boolean[1];
 
-            QueryMetadata md = query.getMetaData(getEntityResolver());
             final PrefetchTreeNode rootPrefetch = md.getPrefetchTree();
 
             if (rootPrefetch != null) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/util/DistinctResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/util/DistinctResultIterator.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/util/DistinctResultIterator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/util/DistinctResultIterator.java Mon Dec  1 01:55:29 2008
@@ -20,7 +20,6 @@
 package org.apache.cayenne.access.util;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -156,11 +155,7 @@
     /**
      * @since 3.0
      */
-    public Object nextId(DbEntity entity) throws CayenneException {
-        Collection<DbAttribute> pk = entity.getPrimaryKeys();
-        if (pk.size() != 1) {
-            return nextObjectId(entity);
-        }
+    public Object nextId() throws CayenneException {
 
         if (!hasNextRow()) {
             throw new CayenneException(
@@ -169,11 +164,11 @@
 
         Map<String, Object> row = nextDataRow;
 
-        checkNextId(entity);
+        checkNextId(defaultEntity);
 
         // TODO: andrus 3/6/2008: not very efficient ... a better algorithm would've
         // relied on wrapped iterator 'nextId' method.
-        return row.get(pk.iterator().next().getName());
+        return row.get(defaultEntity.getPrimaryKeys().iterator().next().getName());
     }
 
     public void skipDataRow() throws CayenneException {
@@ -239,6 +234,9 @@
         }
     }
 
+    /**
+     * @deprecated since 3.0
+     */
     void checkNextId(DbEntity entity) throws CayenneException {
         if (entity == null) {
             throw new CayenneException("Null DbEntity, can't create id.");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java Mon Dec  1 01:55:29 2008
@@ -25,7 +25,7 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.EntityResult;
+import org.apache.cayenne.map.EntityInheritanceTree;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.EntityResultMetadata;
 
@@ -52,6 +52,11 @@
      * @since 3.0
      */
     Collection<DbEntity> getRootDbEntities();
+    
+    /**
+     * @since 3.0
+     */
+    EntityInheritanceTree getEntityInheritanceTree();
 
     /**
      * Returns the EntityResultMetadata that describes the mapping of the ResultSet when

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java Mon Dec  1 01:55:29 2008
@@ -24,6 +24,7 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityInheritanceTree;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.EntityResultMetadata;
 
@@ -82,6 +83,11 @@
         checkDescriptorInitialized();
         return descriptor.getRootDbEntities();
     }
+    
+    public EntityInheritanceTree getEntityInheritanceTree() {
+        checkDescriptorInitialized();
+        return descriptor.getEntityInheritanceTree();
+    }
 
     public EntityResultMetadata getEntityResultMetadata() {
         checkDescriptorInitialized();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java Mon Dec  1 01:55:29 2008
@@ -30,6 +30,7 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityInheritanceTree;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
@@ -59,6 +60,7 @@
     protected ObjEntity entity;
     protected Collection<DbEntity> rootDbEntities;
     protected EntityResultMetadata entityResultMetadata;
+    protected EntityInheritanceTree entityInheritanceTree;
 
     // combines declared and super properties
     protected Collection<Property> idProperties;
@@ -434,4 +436,12 @@
     public void setEntityQualifier(Expression entityQualifier) {
         this.entityQualifier = entityQualifier;
     }
+
+    public EntityInheritanceTree getEntityInheritanceTree() {
+        return entityInheritanceTree;
+    }
+
+    public void setEntityInheritanceTree(EntityInheritanceTree entityInheritanceTree) {
+        this.entityInheritanceTree = entityInheritanceTree;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java Mon Dec  1 01:55:29 2008
@@ -126,6 +126,7 @@
         EntityInheritanceTree inheritanceTree = descriptorMap
                 .getResolver()
                 .lookupInheritanceTree(descriptor.getEntity());
+        descriptor.setEntityInheritanceTree(inheritanceTree);
         indexSubclassDescriptors(descriptor, inheritanceTree);
         indexQualifiers(descriptor, inheritanceTree);
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java Mon Dec  1 01:55:29 2008
@@ -25,8 +25,8 @@
 
 import junit.framework.TestCase;
 
-import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
+import org.apache.cayenne.query.MockQueryMetadata;
 
 import com.mockrunner.mock.jdbc.MockConnection;
 import com.mockrunner.mock.jdbc.MockResultSet;
@@ -67,7 +67,7 @@
                 .setResultSet(rs)
                 .getDescriptor(new ExtendedTypeMap());
 
-        JDBCResultIterator it = new JDBCResultIterator(c, s, rs, descriptor);
+        JDBCResultIterator it = new JDBCResultIterator(c, s, rs, descriptor, new MockQueryMetadata());
 
         assertFalse(rs.isClosed());
         assertFalse(s.isClosed());
@@ -93,7 +93,7 @@
         RowDescriptor descriptor = new RowDescriptorBuilder()
                 .setResultSet(rs)
                 .getDescriptor(new ExtendedTypeMap());
-        return new JDBCResultIterator(c, s, rs, descriptor);
+        return new JDBCResultIterator(c, s, rs, descriptor, new MockQueryMetadata());
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java?rev=722016&r1=722015&r2=722016&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java Mon Dec  1 01:55:29 2008
@@ -26,6 +26,7 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityInheritanceTree;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.EntityResultMetadata;
 
@@ -43,6 +44,10 @@
         return null;
     }
 
+    public EntityInheritanceTree getEntityInheritanceTree() {
+        return null;
+    }
+    
     /**
      * @since 3.0
      */



Mime
View raw message