cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r722516 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/
Date Tue, 02 Dec 2008 16:33:25 GMT
Author: aadamchik
Date: Tue Dec  2 08:33:24 2008
New Revision: 722516

URL: http://svn.apache.org/viewvc?rev=722516&view=rev
Log:
CAY-1142 (Single table) Inheritance and Paginated lists

implementing a more lax check for object types added to incremental fault list.
This should address inheritance related failures, and make things just a bit faster for paginated
queries

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritanceTest.java
Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    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/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=722516&r1=722515&r2=722516&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Tue Dec  2 08:33:24 2008
@@ -15,6 +15,7 @@
 Changes/New Features Since M5:
 
 CAY-1140 Store ObjEntity name in the DataRow
+CAY-1142 (Single table) Inheritance and Paginated lists 
 
 ----------------------------------
 Release: 3.0M5

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=722516&r1=722515&r2=722516&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
Tue Dec  2 08:33:24 2008
@@ -323,7 +323,7 @@
             List<Object> ids = new ArrayList<Object>(pageSize);
             for (int i = fromIndex; i < toIndex; i++) {
                 Object object = elements.get(i);
-                if (helper.incorrectObjectType(object)) {
+                if (helper.unresolvedSuspect(object)) {
                     quals.add(buildIdQualifier(object));
                     ids.add(object);
                 }
@@ -601,7 +601,7 @@
         synchronized (elements) {
             Object o = elements.get(index);
 
-            if (helper.incorrectObjectType(o)) {
+            if (helper.unresolvedSuspect(o)) {
                 // read this page
                 int pageStart = pageIndex(index) * pageSize;
                 resolveInterval(pageStart, pageStart + pageSize);
@@ -710,7 +710,7 @@
     abstract class IncrementalListHelper {
 
         int indexOfObject(Object object) {
-            if (incorrectObjectType(object)) {
+            if (unresolvedSuspect(object)) {
                 return -1;
             }
 
@@ -725,7 +725,7 @@
         }
 
         int lastIndexOfObject(Object object) {
-            if (incorrectObjectType(object)) {
+            if (unresolvedSuspect(object)) {
                 return -1;
             }
 
@@ -759,7 +759,15 @@
             }
         }
 
-        abstract boolean incorrectObjectType(Object object);
+        /**
+         * Returns true if an object is not the type of object expected in the list. This
+         * method is not expected to perform thorough checking of the object type. What's
+         * important is the guarantee that an unresolved object representation will always
+         * return true for this method, and resolved will return false. Other types of
+         * objects that users may choose to add to the list will not be analyzed in
+         * detail.
+         */
+        abstract boolean unresolvedSuspect(Object object);
 
         abstract boolean objectsAreEqual(Object object, Object objectInTheList);
 
@@ -769,21 +777,16 @@
     class PersistentListHelper extends IncrementalListHelper {
 
         @Override
-        boolean incorrectObjectType(Object object) {
+        boolean unresolvedSuspect(Object object) {
             if (!(object instanceof Persistent)) {
                 return true;
             }
 
-            Persistent persistent = (Persistent) object;
-            // NULL ObjectContext can be a result of a delete/commit operation
-            if (persistent.getObjectContext() != null
-                    && persistent.getObjectContext() != dataContext) {
-                return true;
-            }
-
-            if (!persistent.getObjectId().getEntityName().equals(rootEntity.getName())) {
-                return true;
-            }
+            // don't do a full check for object type matching the type of objects in the
+            // list... what's important is a quick "false" return if the object is of type
+            // representing unresolved objects.. furthermore, if inheritance is involved,
+            // we'll need an even more extensive check (see CAY-1142 on inheritance
+            // issues).
 
             return false;
         }
@@ -815,13 +818,12 @@
     class DataRowListHelper extends IncrementalListHelper {
 
         @Override
-        boolean incorrectObjectType(Object object) {
+        boolean unresolvedSuspect(Object object) {
             if (!(object instanceof Map)) {
                 return true;
             }
 
-            Map<?, ?> map = (Map<?, ?>) object;
-            return map.size() != rowWidth;
+            return false;
         }
 
         @Override
@@ -834,6 +836,10 @@
 
                 Map<?, ?> id = (Map<?, ?>) objectInTheList;
                 Map<?, ?> map = (Map<?, ?>) object;
+                
+                if(id.size() != map.size()) {
+                    return false;
+                }
 
                 // id must be a subset of this map
                 for (Map.Entry<?, ?> entry : id.entrySet()) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsTest.java?rev=722516&r1=722515&r2=722516&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SimpleIdIncrementalFaultListDataRowsTest.java
Tue Dec  2 08:33:24 2008
@@ -24,6 +24,7 @@
 import java.util.Map;
 
 import org.apache.art.Artist;
+import org.apache.cayenne.DataRow;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.query.Ordering;
@@ -83,8 +84,11 @@
 
         Map row = (Map) artists.get(0);
         assertEquals(19, list.indexOf(row));
+        
+        DataRow clone = new DataRow(row);
+        assertEquals(19, list.indexOf(clone));
 
-        row.remove("ARTIST_NAME");
+        row.remove("ARTIST_ID");
         assertEquals(-1, list.indexOf(row));
     }
 
@@ -135,7 +139,7 @@
         Map row = (Map) artists.get(0);
         assertEquals(19, list.lastIndexOf(row));
 
-        row.remove("ARTIST_NAME");
+        row.remove("ARTIST_ID");
         assertEquals(-1, list.lastIndexOf(row));
     }
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritanceTest.java?rev=722516&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritanceTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/SingleTableInheritanceTest.java
Tue Dec  2 08:33:24 2008
@@ -0,0 +1,79 @@
+/*****************************************************************
+ *   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;
+
+import java.util.List;
+
+import org.apache.cayenne.query.QueryChain;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.inherit.AbstractPerson;
+import org.apache.cayenne.testdo.inherit.Employee;
+import org.apache.cayenne.testdo.inherit.Manager;
+import org.apache.cayenne.unit.PeopleCase;
+
+public class SingleTableInheritanceTest extends PeopleCase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        deleteTestData();
+    }
+
+    public void testPaginatedQueries() {
+
+        QueryChain insert = new QueryChain();
+        insert
+                .addQuery(new SQLTemplate(
+                        AbstractPerson.class,
+                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (1, 'E1',
'EE')"));
+        insert
+                .addQuery(new SQLTemplate(
+                        AbstractPerson.class,
+                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (2, 'E2',
'EM')"));
+        insert
+                .addQuery(new SQLTemplate(
+                        AbstractPerson.class,
+                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (3, 'E3',
'EE')"));
+        insert
+                .addQuery(new SQLTemplate(
+                        AbstractPerson.class,
+                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (4, 'E4',
'EM')"));
+        insert
+                .addQuery(new SQLTemplate(
+                        AbstractPerson.class,
+                        "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (5, 'E5',
'EE')"));
+        createDataContext().performGenericQuery(insert);
+
+        SelectQuery select = new SelectQuery(AbstractPerson.class);
+        select.addOrdering("db:" + AbstractPerson.PERSON_ID_PK_COLUMN, true);
+        select.setPageSize(3);
+
+        List<AbstractPerson> results = createDataContext().performQuery(select);
+        assertEquals(5, results.size());
+
+        assertTrue(results.get(0) instanceof Employee);
+
+        // this is where things would blow up per CAY-1142
+        assertTrue(results.get(1) instanceof Manager);
+
+        assertTrue(results.get(3) instanceof Manager);
+        assertTrue(results.get(4) instanceof Employee);
+    }
+}



Mime
View raw message