cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r730166 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/select/ test/java/org/apache/cayenne/access/select/
Date Tue, 30 Dec 2008 16:26:39 GMT
Author: aadamchik
Date: Tue Dec 30 08:26:38 2008
New Revision: 730166

URL: http://svn.apache.org/viewvc?rev=730166&view=rev
Log:
 CAY-1162 SelectDescriptor concept

horizontal inheritance

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderHorizontalTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/EntitySelectColumn.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/ScalarSegment.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/SelectColumn.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/EntitySelectColumn.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/EntitySelectColumn.java?rev=730166&r1=730165&r2=730166&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/EntitySelectColumn.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/EntitySelectColumn.java
Tue Dec 30 08:26:38 2008
@@ -22,6 +22,7 @@
 import java.util.List;
 
 import org.apache.cayenne.access.types.ExtendedType;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 
 /**
@@ -40,7 +41,7 @@
         return jdbcType;
     }
 
-    public String getColumnName(int unionSegmentIndex, String tableAlias) {
+    public String getColumnName(DbEntity unionRoot, String tableAlias) {
         if (tableAlias == null || tableAlias.length() == 0) {
             return columnName;
         }
@@ -52,7 +53,7 @@
         return dataRowKey;
     }
 
-    public List<DbRelationship> getPath(int unionSegmentIndex) {
+    public List<DbRelationship> getPath(DbEntity unionRoot) {
         if (path == null) {
             return Collections.emptyList();
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/ScalarSegment.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/ScalarSegment.java?rev=730166&r1=730165&r2=730166&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/ScalarSegment.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/ScalarSegment.java
Tue Dec 30 08:26:38 2008
@@ -24,6 +24,7 @@
 
 import org.apache.cayenne.access.types.ExtendedType;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 
 /**
@@ -49,7 +50,7 @@
         return rowReader;
     }
 
-    public String getColumnName(int unionSegmentIndex, String tableAlias) {
+    public String getColumnName(DbEntity unionRoot, String tableAlias) {
         if (tableAlias == null || tableAlias.length() == 0) {
             return columnName;
         }
@@ -66,7 +67,7 @@
                 "'dataRowKey' is meaningless for Scalar segments");
     }
 
-    public List<DbRelationship> getPath(int unionSegmentIndex) {
+    public List<DbRelationship> getPath(DbEntity unionRoot) {
         throw new UnsupportedOperationException(
                 "'getPath' is unsupported for Scalar segments");
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/SelectColumn.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/SelectColumn.java?rev=730166&r1=730165&r2=730166&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/SelectColumn.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/select/SelectColumn.java
Tue Dec 30 08:26:38 2008
@@ -20,6 +20,7 @@
 
 import java.util.List;
 
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
 
 /**
@@ -33,7 +34,7 @@
 
     String getDataRowKey();
 
-    String getColumnName(int unionSegmentIndex, String tableAlias);
+    String getColumnName(DbEntity unionRoot, String tableAlias);
 
-    List<DbRelationship> getPath(int unionSegmentIndex);
+    List<DbRelationship> getPath(DbEntity unionRoot);
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderHorizontalTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderHorizontalTest.java?rev=730166&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderHorizontalTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderHorizontalTest.java
Tue Dec 30 08:26:38 2008
@@ -0,0 +1,144 @@
+/*****************************************************************
+ *   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.select;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.cayenne.access.types.ExtendedTypeMap;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.testdo.horizontalinherit.AbstractSuperEntity;
+import org.apache.cayenne.testdo.horizontalinherit.SubEntity1;
+import org.apache.cayenne.unit.InheritanceCase;
+
+public class EntityTreeSegmentBuilderHorizontalTest extends InheritanceCase {
+
+    public void testBuildSegmentColumnsLeafWithDbEntityLessSuper() {
+
+        SelectQuery query = new SelectQuery(SubEntity1.class);
+
+        EntityResolver resolver = getDomain().getEntityResolver();
+        QueryMetadata md = query.getMetaData(resolver);
+        ClassDescriptor descriptor = md.getClassDescriptor();
+        ExtendedTypeMap converters = getDomain()
+                .getDataNodes()
+                .iterator()
+                .next()
+                .getAdapter()
+                .getExtendedTypes();
+
+        SelectDescriptor<Object> select = new EntityTreeSegmentBuilder(
+                md,
+                converters,
+                descriptor).buildSegment();
+
+        List<? extends SelectColumn> columns = select.getColumns();
+
+        DbEntity e0 = resolver.getDbEntity("INHERITANCE_SUB_ENTITY1");
+        Collection<String> columnNames0 = new ArrayList<String>(Arrays.asList(
+                "ID",
+                "SUPER_INT_DB_ATTR",
+                "SUPER_STRING_DB_ATTR",
+                "SUBENTITY_STRING_DB_ATTR"));
+
+        for (SelectColumn column : columns) {
+            columnNames0.remove(column.getColumnName(e0, ""));
+        }
+
+        assertTrue(
+                "Missing columns for 'INHERITANCE_SUB_ENTITY1': " + columnNames0,
+                columnNames0.isEmpty());
+        assertEquals("Unexpected columns present", 4, columns.size());
+    }
+
+    public void testBuildSegmentColumnsSuper() {
+
+        SelectQuery query = new SelectQuery(AbstractSuperEntity.class);
+
+        EntityResolver resolver = getDomain().getEntityResolver();
+        QueryMetadata md = query.getMetaData(resolver);
+        ClassDescriptor descriptor = md.getClassDescriptor();
+        ExtendedTypeMap converters = getDomain()
+                .getDataNodes()
+                .iterator()
+                .next()
+                .getAdapter()
+                .getExtendedTypes();
+
+        SelectDescriptor<Object> select = new EntityTreeSegmentBuilder(
+                md,
+                converters,
+                descriptor).buildSegment();
+
+        List<? extends SelectColumn> columns = select.getColumns();
+
+        DbEntity e0 = resolver.getDbEntity("INHERITANCE_SUB_ENTITY1");
+        Collection<String> columnNames0 = new ArrayList<String>(Arrays.asList(
+                "CAYENNE:ENTITY",
+                "ID",
+                "SUPER_INT_DB_ATTR",
+                "SUPER_STRING_DB_ATTR",
+                "SUBENTITY_STRING_DB_ATTR",
+                "'1'",
+                "1"));
+
+        DbEntity e1 = resolver.getDbEntity("INHERITANCE_SUB_ENTITY2");
+        Collection<String> columnNames1 = new ArrayList<String>(Arrays.asList(
+                "CAYENNE:ENTITY",
+                "ID",
+                "SUPER_INT_DB_ATTR",
+                "OVERRIDDEN_STRING_DB_ATTR",
+                "'1'",
+                "SUBENTITY_INT_DB_ATTR",
+                "1"));
+
+        DbEntity e2 = resolver.getDbEntity("INHERITANCE_SUB_ENTITY3");
+        Collection<String> columnNames2 = new ArrayList<String>(Arrays.asList(
+                "CAYENNE:ENTITY",
+                "ID",
+                "OVERRIDDEN_INT_DB_ATTR",
+                "OVERRIDDEN_STRING_DB_ATTR",
+                "'1'",
+                "1",
+                "SUBENTITY_BOOL_ATTR"));
+
+        for (SelectColumn column : columns) {
+            columnNames0.remove(column.getColumnName(e0, ""));
+            columnNames1.remove(column.getColumnName(e1, ""));
+            columnNames2.remove(column.getColumnName(e2, ""));
+        }
+
+        assertTrue(
+                "Missing columns for 'INHERITANCE_SUB_ENTITY1': " + columnNames0,
+                columnNames0.isEmpty());
+        assertTrue(
+                "Missing columns for 'INHERITANCE_SUB_ENTITY2': " + columnNames1,
+                columnNames1.isEmpty());
+        assertTrue(
+                "Missing columns for 'INHERITANCE_SUB_ENTITY3': " + columnNames2,
+                columnNames2.isEmpty());
+        assertEquals("Unexpected columns present", 7, columns.size());
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderTest.java?rev=730166&r1=730165&r2=730166&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/select/EntityTreeSegmentBuilderTest.java
Tue Dec 30 08:26:38 2008
@@ -75,7 +75,7 @@
         assertEquals("Unexpected columns present", 5, columns.size());
     }
 
-    public void testBuildSegmentRowReaderInheritanceLeaf() throws Exception {
+    public void testBuildSegmentRowReaderLeaf() throws Exception {
 
         SelectQuery query = new SelectQuery(CustomerRepresentative.class);
 
@@ -107,7 +107,7 @@
 
         MockResultSet rs = new MockResultSet("test");
         for (SelectColumn column : columns) {
-            rs.addColumn(column.getColumnName(0, null));
+            rs.addColumn(column.getColumnName(md.getDbEntity(), null));
             crRow.add(crRowMap.get(column.getDataRowKey()));
         }
 
@@ -121,7 +121,7 @@
         assertEquals("Invalid row read: " + crRowRead, crRowMap, crRowRead);
     }
 
-    public void testBuildSegmentColumns() {
+    public void testBuildSegmentColumnsSuper() {
 
         SelectQuery query = new SelectQuery(AbstractPerson.class);
 
@@ -159,7 +159,7 @@
         assertEquals("Unexpected columns present", 7, columns.size());
     }
 
-    public void testBuildSegmentRowReader() throws Exception {
+    public void testBuildSegmentRowReaderSuper() throws Exception {
         SelectQuery query = new SelectQuery(AbstractPerson.class);
 
         EntityResolver resolver = getDomain().getEntityResolver();
@@ -206,7 +206,7 @@
 
         MockResultSet rs = new MockResultSet("test");
         for (SelectColumn column : columns) {
-            rs.addColumn(column.getColumnName(0, null));
+            rs.addColumn(column.getColumnName(md.getDbEntity(), null));
 
             employeeRow.add(employeeRowMap.get(column.getDataRowKey()));
             managerRow.add(managerRowMap.get(column.getDataRowKey()));



Mime
View raw message