1 56 package org.objectstyle.cayenne.query; 57 58 import java.io.Serializable ; 59 import java.util.Collection ; 60 import java.util.Collections ; 61 import java.util.HashSet ; 62 import java.util.Map ; 63 import java.util.Set ; 64 65 import org.objectstyle.cayenne.util.XMLEncoder; 66 import org.objectstyle.cayenne.util.XMLSerializable; 67 68 75 final class SelectExecutionProperties implements XMLSerializable, Serializable { 76 77 int fetchLimit = GenericSelectQuery.FETCH_LIMIT_DEFAULT; 78 int pageSize = GenericSelectQuery.PAGE_SIZE_DEFAULT; 79 boolean fetchingDataRows = GenericSelectQuery.FETCHING_DATA_ROWS_DEFAULT; 80 boolean refreshingObjects = GenericSelectQuery.REFRESHING_OBJECTS_DEFAULT; 81 boolean resolvingInherited = GenericSelectQuery.RESOLVING_INHERITED_DEFAULT; 82 String cachePolicy = GenericSelectQuery.CACHE_POLICY_DEFAULT; 83 Set jointPrefetches; 84 85 88 void copyToProperties(SelectExecutionProperties anotherProperties) { 89 anotherProperties.fetchingDataRows = this.fetchingDataRows; 90 anotherProperties.fetchLimit = this.fetchLimit; 91 anotherProperties.pageSize = this.pageSize; 92 anotherProperties.refreshingObjects = this.refreshingObjects; 93 anotherProperties.resolvingInherited = this.resolvingInherited; 94 anotherProperties.cachePolicy = this.cachePolicy; 95 anotherProperties.jointPrefetches = (this.jointPrefetches != null) ? new HashSet ( 96 jointPrefetches) : null; 97 } 98 99 void initWithProperties(Map properties) { 100 if (properties == null) { 102 properties = Collections.EMPTY_MAP; 103 } 104 105 Object fetchLimit = properties.get(GenericSelectQuery.FETCH_LIMIT_PROPERTY); 106 Object pageSize = properties.get(GenericSelectQuery.PAGE_SIZE_PROPERTY); 107 Object refreshingObjects = properties 108 .get(GenericSelectQuery.REFRESHING_OBJECTS_PROPERTY); 109 Object fetchingDataRows = properties 110 .get(GenericSelectQuery.FETCHING_DATA_ROWS_PROPERTY); 111 112 Object resolvingInherited = properties 113 .get(GenericSelectQuery.RESOLVING_INHERITED_PROPERTY); 114 115 Object cachePolicy = properties.get(GenericSelectQuery.CACHE_POLICY_PROPERTY); 116 117 this.fetchLimit = (fetchLimit != null) 119 ? Integer.parseInt(fetchLimit.toString()) 120 : GenericSelectQuery.FETCH_LIMIT_DEFAULT; 121 122 this.pageSize = (pageSize != null) 123 ? Integer.parseInt(pageSize.toString()) 124 : GenericSelectQuery.PAGE_SIZE_DEFAULT; 125 126 this.refreshingObjects = (refreshingObjects != null) 127 ? "true".equalsIgnoreCase(refreshingObjects.toString()) 128 : GenericSelectQuery.REFRESHING_OBJECTS_DEFAULT; 129 130 this.fetchingDataRows = (fetchingDataRows != null) 131 ? "true".equalsIgnoreCase(fetchingDataRows.toString()) 132 : GenericSelectQuery.FETCHING_DATA_ROWS_DEFAULT; 133 134 this.resolvingInherited = (resolvingInherited != null) 135 ? "true".equalsIgnoreCase(resolvingInherited.toString()) 136 : GenericSelectQuery.RESOLVING_INHERITED_DEFAULT; 137 138 this.cachePolicy = (cachePolicy != null) 139 ? cachePolicy.toString() 140 : GenericSelectQuery.CACHE_POLICY_DEFAULT; 141 } 142 143 public void encodeAsXML(XMLEncoder encoder) { 144 if (refreshingObjects != GenericSelectQuery.REFRESHING_OBJECTS_DEFAULT) { 145 encoder.printProperty(GenericSelectQuery.REFRESHING_OBJECTS_PROPERTY, 146 refreshingObjects); 147 } 148 149 if (fetchingDataRows != GenericSelectQuery.FETCHING_DATA_ROWS_DEFAULT) { 150 encoder.printProperty(GenericSelectQuery.FETCHING_DATA_ROWS_PROPERTY, 151 fetchingDataRows); 152 } 153 154 if (resolvingInherited != GenericSelectQuery.RESOLVING_INHERITED_DEFAULT) { 155 encoder.printProperty(GenericSelectQuery.RESOLVING_INHERITED_PROPERTY, 156 resolvingInherited); 157 } 158 159 if (fetchLimit != GenericSelectQuery.FETCH_LIMIT_DEFAULT) { 160 encoder.printProperty(GenericSelectQuery.FETCH_LIMIT_PROPERTY, fetchLimit); 161 } 162 163 if (pageSize != GenericSelectQuery.PAGE_SIZE_DEFAULT) { 164 encoder.printProperty(GenericSelectQuery.PAGE_SIZE_PROPERTY, pageSize); 165 } 166 167 if (cachePolicy != null 168 && !GenericSelectQuery.CACHE_POLICY_DEFAULT.equals(cachePolicy)) { 169 encoder.printProperty(GenericSelectQuery.CACHE_POLICY_PROPERTY, cachePolicy); 170 } 171 } 172 173 String getCachePolicy() { 174 return cachePolicy; 175 } 176 177 void setCachePolicy(String policy) { 178 this.cachePolicy = policy; 179 } 180 181 boolean isFetchingDataRows() { 182 return fetchingDataRows; 183 } 184 185 int getFetchLimit() { 186 return fetchLimit; 187 } 188 189 int getPageSize() { 190 return pageSize; 191 } 192 193 boolean isRefreshingObjects() { 194 return refreshingObjects; 195 } 196 197 boolean isResolvingInherited() { 198 return resolvingInherited; 199 } 200 201 void setFetchingDataRows(boolean b) { 202 fetchingDataRows = b; 203 } 204 205 void setFetchLimit(int i) { 206 fetchLimit = i; 207 } 208 209 void setPageSize(int i) { 210 pageSize = i; 211 } 212 213 void setRefreshingObjects(boolean b) { 214 refreshingObjects = b; 215 } 216 217 void setResolvingInherited(boolean b) { 218 resolvingInherited = b; 219 } 220 221 226 Collection nonNullJointPrefetches() { 227 if (jointPrefetches == null) { 228 jointPrefetches = new HashSet (); 229 } 230 231 return jointPrefetches; 232 } 233 234 239 Collection getJointPrefetches() { 240 return (jointPrefetches != null) ? jointPrefetches : Collections.EMPTY_SET; 241 } 242 243 248 void addJointPrefetch(String relationshipPath) { 249 nonNullJointPrefetches().add(relationshipPath); 250 } 251 252 257 void addJointPrefetches(Collection relationshipPaths) { 258 nonNullJointPrefetches().addAll(relationshipPaths); 259 } 260 261 266 void clearJointPrefetches() { 267 jointPrefetches = null; 268 } 269 270 275 void removeJointPrefetch(String relationshipPath) { 276 if (jointPrefetches != null) { 277 jointPrefetches.remove(relationshipPath); 278 } 279 } 280 } | Popular Tags |