Author: aadamchik
Date: Wed Jun 21 09:25:09 2006
New Revision: 416023
URL: http://svn.apache.org/viewvc?rev=416023&view=rev
Log:
CAY-576
(also moved the storage of server side IncrementalFaultLists for CWS from the
server-side channel to server-side ObjectStore)
Added:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/query/InvalidateListCacheQuery.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/query/InvalidateListCacheQueryTst.java
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextGraphManager.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextQueryAction.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ClientServerChannel.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataContextQueryAction.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataDomainQueryAction.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowStore.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ObjectStore.java
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextGraphManager.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextGraphManager.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextGraphManager.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextGraphManager.java
Wed Jun 21 09:25:09 2006
@@ -119,6 +119,13 @@
synchronized List getCachedQueryResult(String name) {
return (List) queryResultMap.get(name);
}
+
+ /**
+ * @since 3.0
+ */
+ Map getCachedQueryResults() {
+ return queryResultMap;
+ }
boolean hasChangesSinceLastFlush() {
int size = changeLog.hasMarker(FLUSH_MARKER) ? changeLog
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextQueryAction.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextQueryAction.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextQueryAction.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/CayenneContextQueryAction.java
Wed Jun 21 09:25:09 2006
@@ -55,11 +55,15 @@
*/
package org.objectstyle.cayenne;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import org.objectstyle.cayenne.query.InvalidateListCacheQuery;
import org.objectstyle.cayenne.query.Query;
import org.objectstyle.cayenne.query.QueryMetadata;
import org.objectstyle.cayenne.remote.RemoteIncrementalFaultList;
+import org.objectstyle.cayenne.util.GenericResponse;
import org.objectstyle.cayenne.util.ListResponse;
import org.objectstyle.cayenne.util.ObjectContextQueryAction;
@@ -78,9 +82,11 @@
if (interceptOIDQuery() != DONE) {
if (interceptRelationshipQuery() != DONE) {
- if (interceptLocalCache() != DONE) {
- if (interceptPaginatedQuery() != DONE) {
- runQuery();
+ if (interceptInvalidateQuery() != DONE) {
+ if (interceptLocalCache() != DONE) {
+ if (interceptPaginatedQuery() != DONE) {
+ runQuery();
+ }
}
}
}
@@ -133,5 +139,38 @@
graphManager.cacheQueryResult(cacheKey, response.firstList());
return DONE;
+ }
+
+ private boolean interceptInvalidateQuery() {
+ if (query instanceof InvalidateListCacheQuery) {
+ InvalidateListCacheQuery invalidateQuery =
(InvalidateListCacheQuery) query;
+
+ CayenneContextGraphManager graphManager = ((CayenneContext)
actingContext)
+ .internalGraphManager();
+
+ int count = 0;
+ synchronized (graphManager) {
+ Iterator it =
graphManager.getCachedQueryResults().entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry) it.next();
+ if (invalidateQuery.matchesCacheKey((String)
entry.getKey())) {
+ count++;
+ it.remove();
+ }
+ }
+ }
+
+ if (invalidateQuery.isCascade()) {
+ return !DONE;
+ }
+ else {
+ GenericResponse response = new GenericResponse();
+ response.addUpdateCount(count);
+ this.response = response;
+ return DONE;
+ }
+ }
+
+ return !DONE;
}
}
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ClientServerChannel.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ClientServerChannel.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ClientServerChannel.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ClientServerChannel.java
Wed Jun 21 09:25:09 2006
@@ -55,8 +55,7 @@
*/
package org.objectstyle.cayenne.access;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
import org.objectstyle.cayenne.CayenneRuntimeException;
import org.objectstyle.cayenne.DataChannel;
@@ -80,8 +79,7 @@
protected DataContext serverContext;
protected boolean lifecycleEventsEnabled;
- protected Map paginatedResults;
-
+
public ClientServerChannel(DataDomain domain) {
this(domain, false);
}
@@ -99,17 +97,15 @@
return new ClientServerChannelQueryAction(this, query).execute();
}
- synchronized void addPaginatedResult(String cacheKey, IncrementalFaultList
result) {
- if (paginatedResults == null) {
- paginatedResults = new HashMap();
- }
-
- paginatedResults.put(cacheKey, result);
+ void addPaginatedResult(String cacheKey, IncrementalFaultList result) {
+ serverContext.getObjectStore().cacheQueryResult(cacheKey, result);
}
- synchronized IncrementalFaultList getPaginatedResult(String cacheKey) {
- return (paginatedResults != null) ? (IncrementalFaultList)
paginatedResults
- .get(cacheKey) : null;
+ IncrementalFaultList getPaginatedResult(String cacheKey) {
+ List result =
serverContext.getObjectStore().getCachedQueryResult(cacheKey);
+ return (result instanceof IncrementalFaultList)
+ ? (IncrementalFaultList) result
+ : null;
}
DataContext getServerContext() {
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataContextQueryAction.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataContextQueryAction.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataContextQueryAction.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataContextQueryAction.java
Wed Jun 21 09:25:09 2006
@@ -55,14 +55,18 @@
*/
package org.objectstyle.cayenne.access;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.objectstyle.cayenne.DataObject;
import org.objectstyle.cayenne.ObjectContext;
import org.objectstyle.cayenne.QueryResponse;
+import org.objectstyle.cayenne.query.InvalidateListCacheQuery;
+import org.objectstyle.cayenne.query.ObjectIdQuery;
import org.objectstyle.cayenne.query.Query;
import org.objectstyle.cayenne.query.QueryMetadata;
-import org.objectstyle.cayenne.query.ObjectIdQuery;
+import org.objectstyle.cayenne.util.GenericResponse;
import org.objectstyle.cayenne.util.ListResponse;
import org.objectstyle.cayenne.util.ObjectContextQueryAction;
@@ -86,8 +90,10 @@
if (interceptPaginatedQuery() != DONE) {
if (interceptOIDQuery() != DONE) {
if (interceptRelationshipQuery() != DONE) {
- if (interceptLocalCache() != DONE) {
- runQuery();
+ if (interceptInvalidateQuery() != DONE) {
+ if (interceptLocalCache() != DONE) {
+ runQuery();
+ }
}
}
}
@@ -165,5 +171,37 @@
runQuery();
objectStore.cacheQueryResult(cacheKey, response.firstList());
return DONE;
+ }
+
+ private boolean interceptInvalidateQuery() {
+ if (query instanceof InvalidateListCacheQuery) {
+ InvalidateListCacheQuery invalidateQuery =
(InvalidateListCacheQuery) query;
+
+ ObjectStore objectStore = ((DataContext)
actingContext).getObjectStore();
+
+ int count = 0;
+ synchronized (objectStore) {
+ Iterator it =
objectStore.getCachedQueryResults().entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry) it.next();
+ if (invalidateQuery.matchesCacheKey((String)
entry.getKey())) {
+ count++;
+ it.remove();
+ }
+ }
+ }
+
+ if (invalidateQuery.isCascade()) {
+ return !DONE;
+ }
+ else {
+ GenericResponse response = new GenericResponse();
+ response.addUpdateCount(count);
+ this.response = response;
+ return DONE;
+ }
+ }
+
+ return !DONE;
}
}
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataDomainQueryAction.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataDomainQueryAction.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataDomainQueryAction.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataDomainQueryAction.java
Wed Jun 21 09:25:09 2006
@@ -75,6 +75,7 @@
import org.objectstyle.cayenne.map.DbRelationship;
import org.objectstyle.cayenne.map.ObjEntity;
import org.objectstyle.cayenne.map.ObjRelationship;
+import org.objectstyle.cayenne.query.InvalidateListCacheQuery;
import org.objectstyle.cayenne.query.PrefetchSelectQuery;
import org.objectstyle.cayenne.query.PrefetchTreeNode;
import org.objectstyle.cayenne.query.Query;
@@ -141,8 +142,10 @@
// run chain...
if (interceptOIDQuery() != DONE) {
if (interceptRelationshipQuery() != DONE) {
- if (interceptSharedCache() != DONE) {
- runQueryInTransaction();
+ if (interceptInvalidateQuery() != DONE) {
+ if (interceptSharedCache() != DONE) {
+ runQueryInTransaction();
+ }
}
}
}
@@ -267,6 +270,35 @@
return !DONE;
}
+ /**
+ * @since 3.0
+ */
+ private boolean interceptInvalidateQuery() {
+ if (query instanceof InvalidateListCacheQuery) {
+ InvalidateListCacheQuery invalidateQuery =
(InvalidateListCacheQuery) query;
+
+ int count = 0;
+ synchronized (cache) {
+ Iterator it = cache.getCachedSnapshots().entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry) it.next();
+ if (invalidateQuery.matchesCacheKey((String)
entry.getKey())) {
+ count++;
+ it.remove();
+ }
+ }
+ }
+
+ // ignore 'cascade' setting - we are at the bottom of the stack
already...
+ GenericResponse response = new GenericResponse();
+ response.addUpdateCount(count);
+ this.response = response;
+ return DONE;
+ }
+
+ return !DONE;
+ }
+
/*
* Wraps execution in shared cache checks
*/
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowStore.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowStore.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowStore.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/DataRowStore.java
Wed Jun 21 09:25:09 2006
@@ -444,6 +444,13 @@
return snapshot;
}
}
+
+ /**
+ * @since 3.0
+ */
+ Map getCachedSnapshots() {
+ return snapshotLists;
+ }
/**
* Registers a list of snapshots with internal cache, using a String key.
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ObjectStore.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ObjectStore.java?rev=416023&r1=416022&r2=416023&view=diff
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ObjectStore.java
(original)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/access/ObjectStore.java
Wed Jun 21 09:25:09 2006
@@ -698,6 +698,13 @@
// they were originally cached... do no conversions here
return (List) queryResultMap.get(name);
}
+
+ /**
+ * @since 3.0
+ */
+ Map getCachedQueryResults() {
+ return queryResultMap;
+ }
/**
* Caches a list of query results.
Added:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/query/InvalidateListCacheQuery.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/query/InvalidateListCacheQuery.java?rev=416023&view=auto
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/query/InvalidateListCacheQuery.java
(added)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/query/InvalidateListCacheQuery.java
Wed Jun 21 09:25:09 2006
@@ -0,0 +1,162 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowlegement:
+ * "This product includes software developed by independent contributors
+ * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ * or promote products derived from this software without prior written
+ * permission. For written permission, email
+ * "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ * names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site. For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.query;
+
+import java.util.regex.Pattern;
+
+import org.objectstyle.cayenne.CayenneRuntimeException;
+import org.objectstyle.cayenne.map.EntityResolver;
+
+/**
+ * A Query that allows to clear list caches. Lists to invalidate are located
by matching a
+ * regex pattern against the cache key. For non-cascading query result
returned from the
+ * query execution is the number of cached invalidated lists. For cascading
query the
+ * result is undefined.
+ *
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class InvalidateListCacheQuery implements Query {
+
+ protected String cacheKeyPattern;
+ protected boolean cascade;
+
+ protected transient Pattern cacheKeyCompiledPattern;
+
+ // needed for hessian serialization
+ private InvalidateListCacheQuery() {
+
+ }
+
+ /**
+ * Creates a new InvalidateCacheQuery.
+ *
+ * @param cacheKeyPattern a String that can be compiled to a valid
+ * java.regex.util.Pattern that will be used to match against
query cache
+ * keys.
+ * @param cascade whether to invalidate cache in the local ObjectContext,
or to
+ * propagate the operation through the entire stack.
+ */
+ public InvalidateListCacheQuery(String cacheKeyPattern, boolean cascade) {
+ this.cacheKeyPattern = cacheKeyPattern;
+ this.cascade = cascade;
+ }
+
+ public boolean isCascade() {
+ return cascade;
+ }
+
+ public Pattern getCacheKeyCompiledPattern() {
+
+ // compiling pattern lazily is good for serialization
+ if (cacheKeyCompiledPattern == null) {
+ cacheKeyCompiledPattern = Pattern.compile(cacheKeyPattern);
+ }
+
+ return cacheKeyCompiledPattern;
+ }
+
+ public String getCacheKeyPattern() {
+ return cacheKeyPattern;
+ }
+
+ /**
+ * Returns true if the cache key argument matches the pattern.
+ */
+ public boolean matchesCacheKey(String cacheKey) {
+ return cacheKey == null ? false : getCacheKeyCompiledPattern()
+ .matcher(cacheKey)
+ .matches();
+ }
+
+ public QueryMetadata getMetaData(EntityResolver resolver) {
+ return new BaseQueryMetadata();
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ /**
+ * @deprecated since 1.2
+ */
+ public Object getRoot() {
+ return null;
+ }
+
+ public void route(QueryRouter router, EntityResolver resolver, Query
substitutedQuery) {
+ // noop
+ }
+
+ public SQLAction createSQLAction(SQLActionVisitor visitor) {
+ throw new CayenneRuntimeException("Unsupported operation");
+ }
+
+ /**
+ * @deprecated since 1.2
+ */
+ public void setName(String name) {
+ // noop
+ }
+
+ /**
+ * @deprecated since 1.2
+ */
+ public void setRoot(Object root) {
+ // noop
+ }
+
+}
Added:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/query/InvalidateListCacheQueryTst.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/query/InvalidateListCacheQueryTst.java?rev=416023&view=auto
==============================================================================
---
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/query/InvalidateListCacheQueryTst.java
(added)
+++
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/query/InvalidateListCacheQueryTst.java
Wed Jun 21 09:25:09 2006
@@ -0,0 +1,100 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowlegement:
+ * "This product includes software developed by independent contributors
+ * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ * or promote products derived from this software without prior written
+ * permission. For written permission, email
+ * "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ * names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site. For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.query;
+
+import junit.framework.TestCase;
+
+import org.objectstyle.cayenne.map.EntityResolver;
+import org.objectstyle.cayenne.remote.hessian.service.HessianUtil;
+
+public class InvalidateListCacheQueryTst extends TestCase {
+
+ public void testMatchesCacheKey() {
+
+ InvalidateListCacheQuery q1 = new InvalidateListCacheQuery("abc.",
true);
+
+ assertTrue(q1.matchesCacheKey("abcd"));
+ assertTrue(q1.matchesCacheKey("abc4"));
+
+ assertFalse(q1.matchesCacheKey("abcde"));
+ assertFalse(q1.matchesCacheKey("abc"));
+ assertFalse(q1.matchesCacheKey("xxxx"));
+
+ InvalidateListCacheQuery q2 = new InvalidateListCacheQuery("abc.*",
true);
+
+ assertTrue(q2.matchesCacheKey("abcd"));
+ assertTrue(q2.matchesCacheKey("abc4"));
+
+ assertTrue(q2.matchesCacheKey("abcde"));
+ assertTrue(q2.matchesCacheKey("abc"));
+
+ assertFalse(q2.matchesCacheKey("xxxx"));
+ }
+
+ public void testSerializabilityWithHessian() throws Exception {
+ InvalidateListCacheQuery o = new InvalidateListCacheQuery("XXX", true);
+ Object clone = HessianUtil.cloneViaClientServerSerialization(
+ o,
+ new EntityResolver());
+
+ assertTrue(clone instanceof InvalidateListCacheQuery);
+ InvalidateListCacheQuery c1 = (InvalidateListCacheQuery) clone;
+
+ assertNotSame(o, c1);
+ assertEquals(o.getCacheKeyPattern(), c1.getCacheKeyPattern());
+ assertTrue(c1.isCascade());
+ }
+}