cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r811963 - 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/main/java/org/apache/cayenne/access/trans/ framework/cayen...
Date Mon, 07 Sep 2009 01:24:57 GMT
Author: aadamchik
Date: Mon Sep  7 01:24:56 2009
New Revision: 811963

URL: http://svn.apache.org/viewvc?rev=811963&view=rev
Log:
CAY-1269 Remove SelectQuery custom columns feature

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/FlattenedArcKey.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBasicsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.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=811963&r1=811962&r2=811963&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 Mon Sep  7 01:24:56 2009
@@ -80,6 +80,7 @@
 CAY-1218 Query caching loose ends
 CAY-1221 Exclude JPA from releases
 CAY-1250 Prefetching doesn't work with prefetched subentity
+CAY-1269 Remove SelectQuery custom columns feature
 
 Bug Fixes Since M5:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java?rev=811963&r1=811962&r2=811963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/FlattenedArcKey.java
Mon Sep  7 01:24:56 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cayenne.access;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -29,15 +30,13 @@
 import org.apache.cayenne.access.DataDomainSyncBucket.PropagatedValueFactory;
 import org.apache.cayenne.access.util.DefaultOperationObserver;
 import org.apache.cayenne.dba.PkGenerator;
-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.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SQLTemplate;
 
 /**
  * A holder of flattened relationship modification data.
@@ -135,7 +134,7 @@
     }
 
     /**
-     * Returns pk snapshots for join records for the single-stp flattened relationship.
+     * Returns pk snapshots for join records for the single-step flattened relationship.
      * Multiple joins between the same pair of objects are theoretically possible, so the
      * return value is a list.
      */
@@ -161,24 +160,42 @@
         // TODO: this should be optimized in the future, but now DeleteBatchQuery
         // expects a PK snapshot, so we must provide it.
 
-        SelectQuery query = new SelectQuery(joinEntity, ExpressionFactory.matchAllDbExp(
-                snapshot,
-                Expression.EQUAL_TO));
-        query.setFetchingDataRows(true);
+        StringBuilder sql = new StringBuilder("SELECT ");
+        Collection<DbAttribute> pk = joinEntity.getPrimaryKeys();
 
-        for (DbAttribute dbAttr : joinEntity.getPrimaryKeys()) {
-            query.addCustomDbAttribute(dbAttr.getName());
+        int i = pk.size();
+        for (DbAttribute attribute : joinEntity.getPrimaryKeys()) {
+            sql.append(attribute.getName());
+            if (--i > 0) {
+                sql.append(", ");
+            }
         }
 
-        final List[] result = new List[1];
-
-        node.performQueries(Collections.singleton((Query) query), new DefaultOperationObserver()
{
+        sql.append(" FROM ").append(joinEntity.getFullyQualifiedName()).append(" WHERE ");
+        i = snapshot.size();
+        for (Object key : snapshot.keySet()) {
+            sql.append(key).append(" #bindEqual($").append(key).append(")");
 
-            @Override
-            public void nextRows(Query query, List dataRows) {
-                result[0] = dataRows;
+            if (--i > 0) {
+                sql.append(" AND ");
             }
-        });
+        }
+
+        SQLTemplate query = new SQLTemplate(joinEntity.getDataMap(), sql.toString());
+        query.setParameters(snapshot);
+        query.setFetchingDataRows(true);
+
+        final List[] result = new List[1];
+
+        node.performQueries(
+                Collections.singleton((Query) query),
+                new DefaultOperationObserver() {
+
+                    @Override
+                    public void nextRows(Query query, List dataRows) {
+                        result[0] = dataRows;
+                    }
+                });
 
         return result[0];
     }
@@ -248,7 +265,8 @@
         Map<String, ?> sourceId = this.sourceId.getIdSnapshot();
         Map<String, ?> destinationId = this.destinationId.getIdSnapshot();
 
-        Map<String, Object> snapshot = new HashMap<String, Object>(sourceId.size()
+ destinationId.size(), 1);
+        Map<String, Object> snapshot = new HashMap<String, Object>(sourceId.size()
+                + destinationId.size(), 1);
         for (DbJoin join : firstDbRel.getJoins()) {
             snapshot.put(join.getTargetName(), sourceId.get(join.getSourceName()));
         }
@@ -275,7 +293,8 @@
         List<DbJoin> fromSourceJoins = firstDbRel.getJoins();
         List<DbJoin> toTargetJoins = secondDbRel.getJoins();
 
-        Map<String, Object> snapshot = new HashMap<String, Object>(fromSourceJoins.size()
+ toTargetJoins.size(), 1);
+        Map<String, Object> snapshot = new HashMap<String, Object>(fromSourceJoins.size()
+                + toTargetJoins.size(), 1);
 
         for (int i = 0, numJoins = fromSourceJoins.size(); i < numJoins; i++) {
             DbJoin join = fromSourceJoins.get(i);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java?rev=811963&r1=811962&r2=811963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
Mon Sep  7 01:24:56 2009
@@ -280,9 +280,8 @@
         List<ColumnDescriptor> columns = new ArrayList<ColumnDescriptor>();
         SelectQuery query = getSelectQuery();
 
-        // for query with custom attributes use a different strategy
-        if (query.isFetchingCustomAttributes()) {
-            appendCustomColumns(columns, query);
+        if (query.getRoot() instanceof DbEntity) {
+            appendDbEntityColumns(columns, query);
         }
         else if (getQueryMetadata().getPageSize() > 0) {
             appendIdColumns(columns, query);
@@ -294,6 +293,20 @@
         return columns;
     }
 
+    List<ColumnDescriptor> appendDbEntityColumns(
+            List<ColumnDescriptor> columns,
+            SelectQuery query) {
+
+        final Set<ColumnTracker> attributes = new HashSet<ColumnTracker>();
+
+        DbEntity table = getRootDbEntity();
+        for (DbAttribute dba : table.getAttributes()) {
+            appendColumn(columns, null, dba, attributes, null);
+        }
+
+        return columns;
+    }
+
     /**
      * Appends columns needed for object SelectQuery to the provided columns list.
      */
@@ -519,35 +532,6 @@
         return columns;
     }
 
-    /**
-     * Appends custom columns from SelectQuery to the provided list.
-     * 
-     * @deprecated since 3.0. Will likely be removed after 3.0M6. Can be replaced with
-     *             EJBQL.
-     */
-    @Deprecated
-    List<ColumnDescriptor> appendCustomColumns(
-            List<ColumnDescriptor> columns,
-            SelectQuery query) {
-
-        List<String> customAttributes = query.getCustomDbAttributes();
-        DbEntity table = getRootDbEntity();
-        int len = customAttributes.size();
-
-        for (int i = 0; i < len; i++) {
-            DbAttribute attribute = (DbAttribute) table.getAttribute(customAttributes
-                    .get(i));
-            if (attribute == null) {
-                throw new CayenneRuntimeException("Attribute does not exist: "
-                        + customAttributes.get(i));
-            }
-
-            columns.add(new ColumnDescriptor(attribute, getCurrentAlias()));
-        }
-
-        return columns;
-    }
-
     private void appendColumn(
             List<ColumnDescriptor> columns,
             ObjAttribute objAttribute,

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java?rev=811963&r1=811962&r2=811963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
Mon Sep  7 01:24:56 2009
@@ -20,7 +20,6 @@
 package org.apache.cayenne.query;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -46,7 +45,6 @@
     public static final String DISTINCT_PROPERTY = "cayenne.SelectQuery.distinct";
     public static final boolean DISTINCT_DEFAULT = false;
 
-    protected List<String> customDbAttributes;
     protected List<Ordering> orderings;
     protected boolean distinct;
 
@@ -144,8 +142,8 @@
     public QueryMetadata getMetaData(EntityResolver resolver) {
         metaData.resolve(root, resolver, this);
 
-        // must force DataRows if custom attributes are fetched
-        if (isFetchingCustomAttributes()) {
+        // must force DataRows if DbEntity is fetched
+        if (root instanceof DbEntity) {
             QueryMetadataWrapper wrapper = new QueryMetadataWrapper(metaData);
             wrapper.override(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY, Boolean.TRUE);
             return wrapper;
@@ -311,10 +309,6 @@
             query.addOrderings(orderings);
         }
 
-        if (customDbAttributes != null) {
-            query.addCustomDbAttributes(customDbAttributes);
-        }
-
         // substitute qualifier parameters
         if (qualifier != null) {
             query.setQualifier(qualifier.expWithParameters(parameters, pruneMissing));
@@ -410,64 +404,6 @@
     }
 
     /**
-     * Returns a list of attributes that will be included in the results of this query.
-     * 
-     * @deprecated since 3.0. Will likely be removed after 3.0M6. Can be replaced with
-     *             EJBQL.
-     */
-    @Deprecated
-    public List<String> getCustomDbAttributes() {
-        // if query root is DbEntity, and no custom attributes
-        // are defined, return DbEntity attributes.
-        if ((customDbAttributes == null || customDbAttributes.isEmpty())
-                && (root instanceof DbEntity)) {
-            Collection<String> names = ((DbEntity) root).getAttributeMap().keySet();
-            return new ArrayList<String>(names);
-        }
-        else {
-            return (customDbAttributes != null)
-                    ? customDbAttributes
-                    : Collections.EMPTY_LIST;
-        }
-    }
-
-    /**
-     * Adds a path to the DbAttribute that should be included in the results of this
-     * query. Valid paths would look like <code>ARTIST_NAME</code>,
-     * <code>PAINTING_ARRAY.PAINTING_ID</code>, etc.
-     * 
-     * @deprecated since 3.0. Will likely be removed after 3.0M6. Can be replaced with
-     *             EJBQL.
-     */
-    @Deprecated
-    public void addCustomDbAttribute(String attributePath) {
-        nonNullCustomDbAttributes().add(attributePath);
-    }
-
-    /**
-     * @deprecated since 3.0. Will likely be removed after 3.0M6. Can be replaced with
-     *             EJBQL.
-     */
-    @Deprecated
-    public void addCustomDbAttributes(List<String> attrPaths) {
-        nonNullCustomDbAttributes().addAll(attrPaths);
-    }
-
-    /**
-     * Returns <code>true</code> if there is at least one custom query attribute
-     * specified, otherwise returns <code>false</code> for the case when the
query results
-     * will contain only the root entity attributes.
-     * <p>
-     * Note that queries that are fetching custom attributes always return data rows
-     * instead of DataObjects.
-     * </p>
-     */
-    public boolean isFetchingCustomAttributes() {
-        return (root instanceof DbEntity)
-                || (customDbAttributes != null && !customDbAttributes.isEmpty());
-    }
-
-    /**
      * @since 1.2
      */
     public PrefetchTreeNode getPrefetchTree() {
@@ -512,15 +448,15 @@
      * QueryEngine executing this query.
      */
     public boolean isFetchingDataRows() {
-        return this.isFetchingCustomAttributes() || metaData.isFetchingDataRows();
+        return (root instanceof DbEntity) || metaData.isFetchingDataRows();
     }
 
     /**
      * Sets query result type. If <code>flag</code> parameter is <code>true</code>,
then
      * results will be in the form of data rows.
      * <p>
-     * <i>Note that if <code>isFetchingCustAttributes()</code> returns
<code>true</code>,
-     * this setting has no effect, and data rows are always fetched. </i>
+     * <i>Note that if the root of this query is a {@link DbEntity}, this setting has
no
+     * effect, and data rows are always fetched. </i>
      * </p>
      */
     public void setFetchingDataRows(boolean flag) {
@@ -671,19 +607,6 @@
     }
 
     /**
-     * Returns a list that internally stores custom db attributes, creating it on demand.
-     * 
-     * @since 1.2
-     */
-    List<String> nonNullCustomDbAttributes() {
-        if (customDbAttributes == null) {
-            customDbAttributes = new ArrayList<String>();
-        }
-
-        return customDbAttributes;
-    }
-
-    /**
      * Returns a list that internally stores orderings, creating it on demand.
      * 
      * @since 1.2
@@ -695,15 +618,16 @@
 
         return orderings;
     }
-    
+
     /**
      * Sets statement's fetch size (0 for no default size)
-     * @since 3.0 
+     * 
+     * @since 3.0
      */
     public void setStatementFetchSize(int size) {
         metaData.setStatementFetchSize(size);
     }
-    
+
     /**
      * @return statement's fetch size
      * @since 3.0

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java?rev=811963&r1=811962&r2=811963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
Mon Sep  7 01:24:56 2009
@@ -165,16 +165,6 @@
     }
 
     @Override
-    public void addCustomDbAttribute(String attributePath) {
-        query.addCustomDbAttribute(attributePath);
-    }
-
-    @Override
-    public void addCustomDbAttributes(List attrPaths) {
-        query.addCustomDbAttributes(attrPaths);
-    }
-
-    @Override
     public void addOrdering(Ordering ordering) {
         query.addOrdering(ordering);
     }
@@ -245,11 +235,6 @@
     }
 
     @Override
-    public List<String> getCustomDbAttributes() {
-        return query.getCustomDbAttributes();
-    }
-
-    @Override
     public int getFetchLimit() {
         return query.getFetchLimit();
     }
@@ -300,11 +285,6 @@
     }
 
     @Override
-    public boolean isFetchingCustomAttributes() {
-        return query.isFetchingCustomAttributes();
-    }
-
-    @Override
     public boolean isFetchingDataRows() {
         return query.isFetchingDataRows();
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBasicsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBasicsTest.java?rev=811963&r1=811962&r2=811963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBasicsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryBasicsTest.java
Mon Sep  7 01:24:56 2009
@@ -99,37 +99,6 @@
         assertTrue(q.isDistinct());
     }
 
-    public void testFetchingDataRowsSpecial() {
-        SelectQuery q = new SelectQuery();
-
-        assertFalse(q.isFetchingDataRows());
-        q.addCustomDbAttribute("ARTIST_ID");
-        assertTrue(q.isFetchingDataRows());
-
-        // this shouldn't have any effect, since custom attributes are fetched
-        q.setFetchingDataRows(false);
-        assertTrue(q.isFetchingDataRows());
-    }
-
-    public void testQueryAttributes() throws Exception {
-        SelectQuery q = new SelectQuery();
-
-        assertEquals(0, q.getCustomDbAttributes().size());
-
-        q.addCustomDbAttribute("ARTIST_ID");
-        assertEquals(1, q.getCustomDbAttributes().size());
-        assertEquals("ARTIST_ID", q.getCustomDbAttributes().get(0));
-    }
-
-    public void testUsingRootEntityAttributes() throws Exception {
-        SelectQuery q = new SelectQuery();
-
-        assertFalse(q.isFetchingCustomAttributes());
-
-        q.addCustomDbAttribute("ARTIST_ID");
-        assertTrue(q.isFetchingCustomAttributes());
-    }
-
     public void testQueryWithParams1() {
         SelectQuery q = new SelectQuery();
         q.setRoot(Artist.class);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java?rev=811963&r1=811962&r2=811963&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
Mon Sep  7 01:24:56 2009
@@ -30,6 +30,7 @@
 import org.apache.art.Exhibit;
 import org.apache.art.Gallery;
 import org.apache.art.Painting;
+import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
@@ -65,6 +66,16 @@
         assertEquals(totalRows - 5, results.size());
         assertEquals("artist6", results.get(0).getArtistName());
     }
+    
+    public void testDbEntityRoot() {
+        ObjectContext context = createDataContext();
+
+        SelectQuery query = new SelectQuery(getDbEntity("ARTIST"));
+        List results = context.performQuery(query);
+
+        assertEquals(20, results.size());
+        assertTrue(results.get(0) instanceof DataRow);
+    }
 
     public void testFetchLimitWithOffset() throws Exception {
         ObjectContext context = createDataContext();
@@ -312,20 +323,6 @@
         assertEquals(20, objects.size());
     }
 
-    public void testSelectCustAttributes() throws Exception {
-        query.setRoot(Artist.class);
-        query.addCustomDbAttribute("ARTIST_NAME");
-
-        List results = createDataContext().performQuery(query);
-
-        // check query results
-        assertEquals(_artistCount, results.size());
-
-        Map row = (Map) results.get(0);
-        assertNotNull(row.get("ARTIST_NAME"));
-        assertEquals(1, row.size());
-    }
-
     public void testSelectBooleanTrue() throws Exception {
         query.setRoot(Artist.class);
         Expression qual = ExpressionFactory.expTrue();



Mime
View raw message