cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r448357 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/util/ test/java/org/apache/cayenne/access/
Date Wed, 20 Sep 2006 21:52:21 GMT
Author: aadamchik
Date: Wed Sep 20 14:52:20 2006
New Revision: 448357

URL: http://svn.apache.org/viewvc?view=rev&rev=448357
Log:
Basic CAY-658 implementation

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/util/DataChannelDecorator.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTst.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java?view=diff&rev=448357&r1=448356&r2=448357
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataContext.java
Wed Sep 20 14:52:20 2006
@@ -414,8 +414,12 @@
             return (DataDomain) channel;
         }
 
-        if (channel instanceof DataContext) {
-            return ((DataContext) channel).getParentDataDomain();
+        List response = channel.onQuery(this, new DataDomainQuery()).firstList();
+
+        if (response != null
+                && response.size() > 0
+                && response.get(0) instanceof DataDomain) {
+            return (DataDomain) response.get(0);
         }
 
         return null;

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQuery.java?view=auto&rev=448357
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQuery.java
Wed Sep 20 14:52:20 2006
@@ -0,0 +1,113 @@
+/*****************************************************************
+ *   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 org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.Procedure;
+import org.apache.cayenne.query.PrefetchTreeNode;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.QueryMetadata;
+import org.apache.cayenne.query.QueryRouter;
+import org.apache.cayenne.query.SQLAction;
+import org.apache.cayenne.query.SQLActionVisitor;
+
+/**
+ * A query that allows DataContext to retrieve parent DataDomain through a chain of
+ * decorator DataChannels.
+ * 
+ * @author Andrus Adamchik
+ * @since 3.0
+ */
+class DataDomainQuery implements Query, QueryMetadata {
+
+    public SQLAction createSQLAction(SQLActionVisitor visitor) {
+        throw new UnsupportedOperationException("Not an executable query.");
+    }
+
+    public QueryMetadata getMetaData(EntityResolver resolver) {
+        return this;
+    }
+
+    public String getName() {
+        return null;
+    }
+
+    public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)
{
+    }
+
+    public String[] getCacheGroups() {
+        return null;
+    }
+
+    public String getCacheKey() {
+        return null;
+    }
+
+    public String getCachePolicy() {
+        return null;
+    }
+
+    public DataMap getDataMap() {
+        return null;
+    }
+
+    public DbEntity getDbEntity() {
+        return null;
+    }
+
+    public int getFetchLimit() {
+        return 0;
+    }
+
+    public int getFetchStartIndex() {
+        return 0;
+    }
+
+    public ObjEntity getObjEntity() {
+        return null;
+    }
+
+    public int getPageSize() {
+        return 0;
+    }
+
+    public PrefetchTreeNode getPrefetchTree() {
+        return null;
+    }
+
+    public Procedure getProcedure() {
+        return null;
+    }
+
+    public boolean isFetchingDataRows() {
+        // must return true, otherwise the stack will attempt DataObject conversion
+        return true;
+    }
+
+    public boolean isRefreshingObjects() {
+        return false;
+    }
+
+    public boolean isResolvingInherited() {
+        return false;
+    }
+}

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java?view=diff&rev=448357&r1=448356&r2=448357
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
Wed Sep 20 14:52:20 2006
@@ -109,7 +109,9 @@
             if (interceptRelationshipQuery() != DONE) {
                 if (interceptRefreshQuery() != DONE) {
                     if (interceptSharedCache() != DONE) {
-                        runQueryInTransaction();
+                        if (interceptDataDomainQuery() != DONE) {
+                            runQueryInTransaction();
+                        }
                     }
                 }
             }
@@ -119,6 +121,15 @@
         interceptObjectConversion();
 
         return response;
+    }
+    
+    private boolean interceptDataDomainQuery() {
+        if (query instanceof DataDomainQuery) {
+            response = new ListResponse(domain);
+            return DONE;
+        }
+
+        return !DONE;
     }
 
     private boolean interceptOIDQuery() {

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/util/DataChannelDecorator.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/util/DataChannelDecorator.java?view=auto&rev=448357
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/util/DataChannelDecorator.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/util/DataChannelDecorator.java
Wed Sep 20 14:52:20 2006
@@ -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.util;
+
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.QueryResponse;
+import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.graph.GraphDiff;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.query.Query;
+
+/**
+ * A helper {@link DataChannel} implementation that passes all requests to the underlying
+ * decorated channel for execution. Intended for subclassing.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class DataChannelDecorator implements DataChannel {
+
+    protected DataChannel channel;
+
+    protected DataChannelDecorator() {
+
+    }
+
+    public DataChannelDecorator(DataChannel channel) {
+        setChannel(channel);
+    }
+
+    public EntityResolver getEntityResolver() {
+        return channel.getEntityResolver();
+    }
+
+    public EventManager getEventManager() {
+        return channel.getEventManager();
+    }
+
+    public QueryResponse onQuery(ObjectContext originatingContext, Query query) {
+        return channel.onQuery(originatingContext, query);
+    }
+
+    public GraphDiff onSync(
+            ObjectContext originatingContext,
+            GraphDiff changes,
+            int syncType) {
+        return channel.onSync(originatingContext, changes, syncType);
+    }
+
+    public DataChannel getChannel() {
+        return channel;
+    }
+
+    public void setChannel(DataChannel channel) {
+        // TODO: andrus, 9/20/2006 - register as listener of the channel events
+        this.channel = channel;
+    }
+}

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTst.java?view=auto&rev=448357
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTst.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/DataContextDecoratedStackTst.java
Wed Sep 20 14:52:20 2006
@@ -0,0 +1,63 @@
+/*****************************************************************
+ *   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.Map;
+
+import org.apache.art.Artist;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.DataObjectUtils;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.unit.CayenneTestCase;
+import org.apache.cayenne.util.DataChannelDecorator;
+
+public class DataContextDecoratedStackTst extends CayenneTestCase {
+
+    protected void setUp() throws Exception {
+        deleteTestData();
+    }
+
+    public void testCommitDecorated() {
+        DataDomain dd = getDomain();
+        DataChannel decorator = new DataChannelDecorator(dd);
+        DataContext context = new DataContext(decorator, new ObjectStore(dd
+                .getSharedSnapshotCache()));
+
+        Artist a = (Artist) context.newObject(Artist.class);
+        a.setArtistName("XXX");
+        context.commitChanges();
+
+        SQLTemplate query = new SQLTemplate(
+                Artist.class,
+                "select #result('count(1)' 'int' 'c') from ARTIST");
+        query.setFetchingDataRows(true);
+        Map count = (Map) DataObjectUtils.objectForQuery(context, query);
+        assertNotNull(count);
+        assertEquals(new Integer(1), count.get("c"));
+    }
+
+    public void testGetParentDataDomain() {
+        DataDomain dd = getDomain();
+        DataChannel decorator = new DataChannelDecorator(dd);
+        DataContext context = new DataContext(decorator, new ObjectStore(dd
+                .getSharedSnapshotCache()));
+
+        assertSame(dd, context.getParentDataDomain());
+    }
+}



Mime
View raw message