1 19 20 package org.apache.cayenne.query; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.apache.cayenne.map.DataMap; 26 import org.apache.cayenne.map.DbEntity; 27 import org.apache.cayenne.map.ObjEntity; 28 import org.apache.cayenne.map.Procedure; 29 import org.apache.cayenne.reflect.ClassDescriptor; 30 31 38 class QueryMetadataWrapper implements QueryMetadata { 39 40 static final String CACHE_KEY_PROPERTY = "QueryMetadataWrapper.CacheKey"; 41 42 QueryMetadata info; 43 Map overrides; 44 45 public QueryMetadataWrapper(QueryMetadata info) { 46 this.info = info; 47 } 48 49 53 void override(String key, Object value) { 54 if (overrides == null) { 55 overrides = new HashMap (); 56 } 57 58 overrides.put(key, value); 59 } 60 61 boolean overrideExists(String key) { 62 return overrides != null && overrides.containsKey(key); 63 } 64 65 68 public SQLResultSetMapping getResultSetMapping() { 69 return info.getResultSetMapping(); 70 } 71 72 public DataMap getDataMap() { 73 return info.getDataMap(); 74 } 75 76 public Procedure getProcedure() { 77 return info.getProcedure(); 78 } 79 80 public DbEntity getDbEntity() { 81 return info.getDbEntity(); 82 } 83 84 public ObjEntity getObjEntity() { 85 return info.getObjEntity(); 86 } 87 88 91 public ClassDescriptor getClassDescriptor() { 92 return info.getClassDescriptor(); 93 } 94 95 public String getCacheKey() { 96 return (overrideExists(CACHE_KEY_PROPERTY)) ? (String ) overrides 97 .get(CACHE_KEY_PROPERTY) : info.getCacheKey(); 98 } 99 100 public String getCachePolicy() { 101 return (overrideExists(QueryMetadata.CACHE_POLICY_PROPERTY)) ? (String ) overrides 102 .get(QueryMetadata.CACHE_POLICY_PROPERTY) : info.getCachePolicy(); 103 } 104 105 public String [] getCacheGroups() { 106 return (overrideExists(QueryMetadata.CACHE_GROUPS_PROPERTY)) 107 ? (String []) overrides.get(QueryMetadata.CACHE_GROUPS_PROPERTY) 108 : info.getCacheGroups(); 109 } 110 111 public boolean isFetchingDataRows() { 112 if (!overrideExists(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY)) { 113 return info.isFetchingDataRows(); 114 } 115 116 Boolean b = (Boolean ) overrides.get(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY); 117 return b != null && b.booleanValue(); 118 } 119 120 public boolean isRefreshingObjects() { 121 if (!overrideExists(QueryMetadata.REFRESHING_OBJECTS_PROPERTY)) { 122 return info.isRefreshingObjects(); 123 } 124 125 Boolean b = (Boolean ) overrides.get(QueryMetadata.REFRESHING_OBJECTS_PROPERTY); 126 return b != null && b.booleanValue(); 127 } 128 129 public boolean isResolvingInherited() { 130 if (!overrideExists(QueryMetadata.RESOLVING_INHERITED_PROPERTY)) { 131 return info.isResolvingInherited(); 132 } 133 134 Boolean b = (Boolean ) overrides.get(QueryMetadata.RESOLVING_INHERITED_PROPERTY); 135 return b != null && b.booleanValue(); 136 } 137 138 public int getPageSize() { 139 if (!overrideExists(QueryMetadata.PAGE_SIZE_PROPERTY)) { 140 return info.getPageSize(); 141 } 142 143 Number n = (Number ) overrides.get(QueryMetadata.PAGE_SIZE_PROPERTY); 144 return n != null ? n.intValue() : 0; 145 } 146 147 public int getFetchStartIndex() { 148 return info.getFetchStartIndex(); 149 } 150 151 public int getFetchLimit() { 152 if (!overrideExists(QueryMetadata.FETCH_LIMIT_PROPERTY)) { 153 return info.getFetchLimit(); 154 } 155 156 Number n = (Number ) overrides.get(QueryMetadata.FETCH_LIMIT_PROPERTY); 157 return n != null ? n.intValue() : 0; 158 } 159 160 public PrefetchTreeNode getPrefetchTree() { 161 return info.getPrefetchTree(); 162 } 163 } 164 | Popular Tags |