1 19 package org.apache.cayenne.query; 20 21 import java.util.Arrays ; 22 import java.util.Collection ; 23 24 import org.apache.cayenne.CayenneRuntimeException; 25 import org.apache.cayenne.Persistent; 26 import org.apache.cayenne.map.EntityResolver; 27 28 35 public class RefreshQuery implements Query { 36 37 protected Collection objects; 38 protected Query query; 39 protected String [] groupKeys; 40 41 45 public RefreshQuery() { 46 47 } 48 49 53 public RefreshQuery(Collection objects) { 54 this.objects = objects; 55 } 56 57 61 public RefreshQuery(Persistent object) { 62 this(Arrays.asList(new Object [] { 63 object 64 })); 65 } 66 67 71 public RefreshQuery(Query query) { 72 this.query = query; 73 } 74 75 78 public RefreshQuery(String [] groupKeys) { 79 this.groupKeys = groupKeys; 80 } 81 82 public QueryMetadata getMetaData(EntityResolver resolver) { 83 return new BaseQueryMetadata(); 84 } 85 86 public String getName() { 87 return null; 88 } 89 90 public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery) { 91 } 93 94 public SQLAction createSQLAction(SQLActionVisitor visitor) { 95 throw new CayenneRuntimeException("Unsupported operation"); 96 } 97 98 public boolean isRefreshAll() { 99 return objects == null && query == null && groupKeys == null; 100 } 101 102 public String [] getGroupKeys() { 103 return groupKeys; 104 } 105 106 public Collection getObjects() { 107 return objects; 108 } 109 110 114 public Query getQuery() { 115 116 if (query == null) { 117 return null; 118 } 119 120 return new Query() { 121 122 public SQLAction createSQLAction(SQLActionVisitor visitor) { 123 throw new CayenneRuntimeException("Unsupported"); 124 } 125 126 public QueryMetadata getMetaData(EntityResolver resolver) { 127 QueryMetadata md = query.getMetaData(resolver); 128 129 QueryMetadataWrapper wrappedMd = new QueryMetadataWrapper(md); 130 if (QueryMetadata.LOCAL_CACHE.equals(md.getCachePolicy())) { 131 wrappedMd.override( 132 QueryMetadata.CACHE_POLICY_PROPERTY, 133 QueryMetadata.LOCAL_CACHE_REFRESH); 134 } 135 else if (QueryMetadata.SHARED_CACHE.equals(md.getCachePolicy())) { 136 wrappedMd.override( 137 QueryMetadata.CACHE_POLICY_PROPERTY, 138 QueryMetadata.SHARED_CACHE_REFRESH); 139 } 140 141 return wrappedMd; 142 } 143 144 public String getName() { 145 return query.getName(); 146 } 147 148 public void route( 149 QueryRouter router, 150 EntityResolver resolver, 151 Query substitutedQuery) { 152 query.route(router, resolver, this); 153 } 154 }; 155 } 156 } 157 | Popular Tags |