cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r649261 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query: BaseQueryMetadata.java QueryCacheStrategy.java
Date Thu, 17 Apr 2008 20:18:56 GMT
Author: aadamchik
Date: Thu Apr 17 13:18:55 2008
New Revision: 649261

URL: http://svn.apache.org/viewvc?rev=649261&view=rev
Log:
CAY-1035 Replace QueryMetadata String cache policies with an enum
(legacy policy translation layer)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryCacheStrategy.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java?rev=649261&r1=649260&r2=649261&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/BaseQueryMetadata.java
Thu Apr 17 13:18:55 2008
@@ -50,7 +50,6 @@
     boolean fetchingDataRows = QueryMetadata.FETCHING_DATA_ROWS_DEFAULT;
     boolean refreshingObjects = QueryMetadata.REFRESHING_OBJECTS_DEFAULT;
     boolean resolvingInherited = QueryMetadata.RESOLVING_INHERITED_DEFAULT;
-    String cachePolicy = QueryMetadata.CACHE_POLICY_DEFAULT;
     QueryCacheStrategy cacheStrategy = QueryCacheStrategy.getDefaultStrategy();
 
     PrefetchTreeNode prefetchTree;
@@ -78,7 +77,6 @@
         this.pageSize = info.getPageSize();
         this.refreshingObjects = info.isRefreshingObjects();
         this.resolvingInherited = info.isResolvingInherited();
-        this.cachePolicy = info.getCachePolicy();
         this.cacheStrategy = info.getCacheStrategy();
         this.cacheKey = info.getCacheKey();
 
@@ -189,14 +187,15 @@
                 ? "true".equalsIgnoreCase(resolvingInherited.toString())
                 : QueryMetadata.RESOLVING_INHERITED_DEFAULT;
 
-        this.cachePolicy = (cachePolicy != null)
-                ? cachePolicy.toString()
-                : QueryMetadata.CACHE_POLICY_DEFAULT;
-
         this.cacheStrategy = (cacheStrategy != null) ? QueryCacheStrategy
                 .safeValueOf(cacheStrategy.toString()) : QueryCacheStrategy
                 .getDefaultStrategy();
 
+        // use legacy cachePolicy if it is provided and no strategy is set...
+        if (cacheStrategy == null && cachePolicy != null) {
+            setCachePolicy(cachePolicy.toString());
+        }
+
         this.cacheGroups = null;
         if (cacheGroups instanceof String[]) {
             this.cacheGroups = (String[]) cacheGroups;
@@ -210,20 +209,6 @@
         }
     }
 
-    /**
-     * @since 3.0
-     */
-    public QueryCacheStrategy getCacheStrategy() {
-        return cacheStrategy;
-    }
-    
-    /**
-     * @since 3.0
-     */
-    void setCacheStrategy(QueryCacheStrategy cacheStrategy) {
-        this.cacheStrategy = cacheStrategy;
-    }
-
     public void encodeAsXML(XMLEncoder encoder) {
         if (refreshingObjects != QueryMetadata.REFRESHING_OBJECTS_DEFAULT) {
             encoder.printProperty(
@@ -251,11 +236,6 @@
             encoder.printProperty(QueryMetadata.PAGE_SIZE_PROPERTY, pageSize);
         }
 
-        if (cachePolicy != null
-                && !QueryMetadata.CACHE_POLICY_DEFAULT.equals(cachePolicy)) {
-            encoder.printProperty(QueryMetadata.CACHE_POLICY_PROPERTY, cachePolicy);
-        }
-
         if (cacheStrategy != null
                 && QueryCacheStrategy.getDefaultStrategy() != cacheStrategy) {
             encoder.printProperty(QueryMetadata.CACHE_STRATEGY_PROPERTY, cacheStrategy
@@ -271,7 +251,7 @@
             for (int i = 1; i < cacheGroups.length; i++) {
                 buffer.append(',').append(cacheGroups[i]);
             }
-            encoder.printProperty(QueryMetadata.CACHE_GROUPS_PROPERTY, cachePolicy);
+            encoder.printProperty(QueryMetadata.CACHE_GROUPS_PROPERTY, buffer.toString());
         }
     }
 
@@ -356,14 +336,67 @@
      * @deprecated since 3.0 {@link #getCacheStrategy()} replaces this method.
      */
     public String getCachePolicy() {
-        return cachePolicy;
+        if (cacheStrategy == null) {
+            return QueryMetadata.CACHE_POLICY_DEFAULT;
+        }
+
+        switch (cacheStrategy) {
+            case NO_CACHE:
+                return QueryMetadata.NO_CACHE;
+            case LOCAL_CACHE:
+                return QueryMetadata.LOCAL_CACHE;
+            case LOCAL_CACHE_REFRESH:
+                return QueryMetadata.LOCAL_CACHE_REFRESH;
+            case SHARED_CACHE:
+                return QueryMetadata.SHARED_CACHE;
+            case SHARED_CACHE_REFRESH:
+                return QueryMetadata.SHARED_CACHE_REFRESH;
+
+            default:
+                return QueryMetadata.CACHE_POLICY_DEFAULT;
+        }
     }
 
     /**
-     * @deprecated since 3.0 {@link #setCacheStrategy(QueryCacheStrategy)} replaces this
method.
+     * @deprecated since 3.0 {@link #setCacheStrategy(QueryCacheStrategy)} replaces this
+     *             method.
      */
     void setCachePolicy(String policy) {
-        this.cachePolicy = policy;
+        if (policy == null) {
+            cacheStrategy = null;
+        }
+        else if (QueryMetadata.NO_CACHE.equals(policy)) {
+            cacheStrategy = QueryCacheStrategy.NO_CACHE;
+        }
+        else if (QueryMetadata.LOCAL_CACHE.equals(policy)) {
+            cacheStrategy = QueryCacheStrategy.LOCAL_CACHE;
+        }
+        else if (QueryMetadata.LOCAL_CACHE_REFRESH.equals(policy)) {
+            cacheStrategy = QueryCacheStrategy.LOCAL_CACHE_REFRESH;
+        }
+        else if (QueryMetadata.SHARED_CACHE.equals(policy)) {
+            cacheStrategy = QueryCacheStrategy.SHARED_CACHE;
+        }
+        else if (QueryMetadata.SHARED_CACHE_REFRESH.equals(policy)) {
+            cacheStrategy = QueryCacheStrategy.SHARED_CACHE_REFRESH;
+        }
+        else {
+            cacheStrategy = QueryCacheStrategy.NO_CACHE;
+        }
+    }
+
+    /**
+     * @since 3.0
+     */
+    public QueryCacheStrategy getCacheStrategy() {
+        return cacheStrategy;
+    }
+
+    /**
+     * @since 3.0
+     */
+    void setCacheStrategy(QueryCacheStrategy cacheStrategy) {
+        this.cacheStrategy = cacheStrategy;
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryCacheStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryCacheStrategy.java?rev=649261&r1=649260&r2=649261&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryCacheStrategy.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/QueryCacheStrategy.java
Thu Apr 17 13:18:55 2008
@@ -71,6 +71,9 @@
         }
     }
 
+    /**
+     * Returns the default strategy - {@link #NO_CACHE}.
+     */
     public static QueryCacheStrategy getDefaultStrategy() {
         return NO_CACHE;
     }



Mime
View raw message