cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r432617 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src: main/java/org/apache/cayenne/query/RefreshQuery.java test/java/org/apache/cayenne/query/RefreshQueryTst.java
Date Fri, 18 Aug 2006 15:14:36 GMT
Author: aadamchik
Date: Fri Aug 18 08:14:35 2006
New Revision: 432617

URL: http://svn.apache.org/viewvc?rev=432617&view=rev
Log:
CAY-632 - initial RefreshQuery checked in. Stack can't process it yet.

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/query/RefreshQuery.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/query/RefreshQueryTst.java

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/query/RefreshQuery.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/query/RefreshQuery.java?rev=432617&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/query/RefreshQuery.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/main/java/org/apache/cayenne/query/RefreshQuery.java
Fri Aug 18 08:14:35 2006
@@ -0,0 +1,90 @@
+/*****************************************************************
+ *   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.query;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.map.EntityResolver;
+
+/**
+ * A query that allows to clear both object and list caches either via refetch (eager
+ * refresh) or invalidate (lazy refresh).
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class RefreshQuery implements Query {
+
+    protected Collection objects;
+    protected Query query;
+    protected String[] groupKeys;
+    
+    // noop constructor used for hessian serialization
+    private RefreshQuery() {
+        
+    }
+
+    public RefreshQuery(Collection objects) {
+        this.objects = objects;
+    }
+
+    public RefreshQuery(Persistent object) {
+        this(Arrays.asList(new Object[] {
+            object
+        }));
+    }
+
+    public RefreshQuery(Query query) {
+        this.query = query;
+    }
+
+    public RefreshQuery(String[] groupKeys) {
+        this.groupKeys = groupKeys;
+    }
+
+    public QueryMetadata getMetaData(EntityResolver resolver) {
+        return null;
+    }
+
+    public String getName() {
+        return null;
+    }
+
+    public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)
{
+    }
+
+    public SQLAction createSQLAction(SQLActionVisitor visitor) {
+        throw new CayenneRuntimeException("Unsupported operation");
+    }
+
+    public String[] getGroupKeys() {
+        return groupKeys;
+    }
+
+    public Collection getObjects() {
+        return objects;
+    }
+
+    public Query getQuery() {
+        return query;
+    }
+}

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/query/RefreshQueryTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/query/RefreshQueryTst.java?rev=432617&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/query/RefreshQueryTst.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4-core/src/test/java/org/apache/cayenne/query/RefreshQueryTst.java
Fri Aug 18 08:14:35 2006
@@ -0,0 +1,70 @@
+/*****************************************************************
+ *   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.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.MockPersistentObject;
+import org.apache.cayenne.Persistent;
+
+public class RefreshQueryTst extends TestCase {
+
+    public void testCollectionConstructor() {
+        Collection c = new ArrayList();
+        c.add(new Object());
+        c.add(new Object());
+
+        RefreshQuery q = new RefreshQuery(c);
+        assertSame(c, q.getObjects());
+        assertNull(q.getQuery());
+        assertNull(q.getGroupKeys());
+    }
+
+    public void testObjectConstructor() {
+        Persistent p = new MockPersistentObject();
+
+        RefreshQuery q = new RefreshQuery(p);
+        assertNotNull(q.getObjects());
+        assertEquals(1, q.getObjects().size());
+        assertSame(p, q.getObjects().iterator().next());
+        assertNull(q.getQuery());
+        assertNull(q.getGroupKeys());
+    }
+    
+    public void testQueryConstructor() {
+        Query query = new MockQuery();
+        
+        RefreshQuery q = new RefreshQuery(query);
+        assertNull(q.getObjects());
+        assertEquals(query, q.getQuery());
+        assertNull(q.getGroupKeys());
+    }
+    
+    public void testGroupKeysConstructor() {
+        String[] groupKeys = new String[] {"a", "b"};
+        
+        RefreshQuery q = new RefreshQuery(groupKeys);
+        assertNull(q.getObjects());
+        assertNull(q.getQuery());
+        assertSame(groupKeys, q.getGroupKeys());
+    }
+}



Mime
View raw message