You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by sk...@apache.org on 2015/04/23 13:42:13 UTC
cayenne git commit: cleanup SelectById API
Repository: cayenne
Updated Branches:
refs/heads/master 2c41b0a8a -> fceecc42a
cleanup SelectById API
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/fceecc42
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/fceecc42
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/fceecc42
Branch: refs/heads/master
Commit: fceecc42a93759ba3b35e6bc3f2ac061d361cd48
Parents: 2c41b0a
Author: Savva Kolbachev <s....@gmail.com>
Authored: Thu Apr 23 14:41:39 2015 +0300
Committer: Savva Kolbachev <s....@gmail.com>
Committed: Thu Apr 23 14:41:39 2015 +0300
----------------------------------------------------------------------
.../org/apache/cayenne/query/SQLSelect.java | 9 +-
.../org/apache/cayenne/query/SelectById.java | 87 ++++++++++++++------
2 files changed, 66 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fceecc42/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
index 4f54648..1451bdb 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SQLSelect.java
@@ -297,10 +297,7 @@ public class SQLSelect<T> extends IndirectQuery implements Select<T> {
* </pre>
*/
public SQLSelect<T> localCache(String... cacheGroups) {
- cacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
- cacheGroups(cacheGroups);
-
- return this;
+ return cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroups);
}
/**
@@ -312,8 +309,8 @@ public class SQLSelect<T> extends IndirectQuery implements Select<T> {
* </pre>
*/
public SQLSelect<T> sharedCache(String... cacheGroups) {
- return cacheStrategy(QueryCacheStrategy.SHARED_CACHE).cacheGroups(cacheGroups);
- }
+ return cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroups);
+ }
public QueryCacheStrategy getCacheStrategy() {
return cacheStrategy;
http://git-wip-us.apache.org/repos/asf/cayenne/blob/fceecc42/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
index 78e0146..8b998e0 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectById.java
@@ -169,49 +169,88 @@ public class SelectById<T> extends IndirectQuery implements Select<T> {
}
/**
- * Instructs Cayenne to look for query results in the "local" cache when
- * running the query. This is a short-hand notation for:
- *
- * <pre>
- * query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
- * query.setCacheGroups("group1", "group2");
- * </pre>
- *
- * @since 4.0
- */
+ * Instructs Cayenne to look for query results in the "local" cache when
+ * running the query. This is a short-hand notation for:
+ *
+ * <pre>
+ * query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroups);
+ * </pre>
+ *
+ * @since 4.0.M3
+ */
+ public SelectById<T> localCache(String... cacheGroups) {
+ return cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroups);
+ }
+
+ /**
+ * Instructs Cayenne to look for query results in the "shared" cache when
+ * running the query. This is a short-hand notation for:
+ *
+ * <pre>
+ * query.cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroups);
+ * </pre>
+ *
+ * @since 4.0.M3
+ */
+ public SelectById<T> sharedCache(String... cacheGroups) {
+ return cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroups);
+ }
+
+ /**
+ * Instructs Cayenne to look for query results in the "local" cache when
+ * running the query. This is a short-hand notation for:
+ *
+ * @deprecated since 4.0.M3 use {@link #localCache(String...)}
+ */
+ @Deprecated
public SelectById<T> useLocalCache(String... cacheGroups) {
- cacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
- cacheGroups(cacheGroups);
- return this;
+ return localCache(cacheGroups);
}
+ /**
+ * Instructs Cayenne to look for query results in the "shared" cache when
+ * running the query. This is a short-hand notation for:
+ *
+ * @deprecated since 4.0.M3 use {@link #sharedCache(String...)}
+ */
+ @Deprecated
public SelectById<T> useSharedCache(String... cacheGroups) {
- return cacheStrategy(QueryCacheStrategy.SHARED_CACHE).cacheGroups(cacheGroups);
+ return sharedCache(cacheGroups);
}
public QueryCacheStrategy getCacheStrategy() {
return cacheStrategy;
}
- private SelectById<T> cacheStrategy(QueryCacheStrategy strategy) {
- if (this.cacheStrategy != strategy) {
- this.cacheStrategy = strategy;
- this.replacementQuery = null;
- }
+ public SelectById<T> cacheStrategy(QueryCacheStrategy strategy, String... cacheGroups) {
+ if (this.cacheStrategy != strategy) {
+ this.cacheStrategy = strategy;
+ this.replacementQuery = null;
+ }
- return this;
- }
+ return cacheGroups(cacheGroups);
+ }
public String[] getCacheGroups() {
return cacheGroups;
}
- private SelectById<T> cacheGroups(String... cacheGroups) {
- this.cacheGroups = cacheGroups;
- this.replacementQuery = null;
+ public SelectById<T> cacheGroups(String... cacheGroups) {
+ this.cacheGroups = cacheGroups != null && cacheGroups.length > 0 ? cacheGroups : null;
+ this.replacementQuery = null;
return this;
}
+ public SelectById<T> cacheGroups(Collection<String> cacheGroups) {
+
+ if (cacheGroups == null) {
+ return cacheGroups((String) null);
+ }
+
+ String[] array = new String[cacheGroups.size()];
+ return cacheGroups(cacheGroups.toArray(array));
+ }
+
public boolean isFetchingDataRows() {
return fetchingDataRows;
}