1 19 package org.apache.cayenne.query; 20 21 import java.util.Iterator ; 22 23 import org.apache.cayenne.map.EntityResolver; 24 import org.apache.cayenne.map.ObjEntity; 25 26 30 class SelectQueryMetadata extends BaseQueryMetadata { 31 32 boolean resolve(Object root, EntityResolver resolver, SelectQuery query) { 33 34 if (super.resolve(root, resolver, null)) { 35 36 if (QueryMetadata.NO_CACHE.equals(getCachePolicy())) { 38 39 } 40 else if (query.getName() != null) { 41 this.cacheKey = query.getName(); 42 } 43 else { 44 47 StringBuffer key = new StringBuffer (); 48 49 ObjEntity entity = getObjEntity(); 50 if (entity != null) { 51 key.append(entity.getName()); 52 } 53 else if (dbEntity != null) { 54 key.append("db:").append(dbEntity.getName()); 55 } 56 57 if (query.getQualifier() != null) { 58 key.append('/').append(query.getQualifier()); 59 } 60 61 if (!query.getOrderings().isEmpty()) { 62 Iterator it = query.getOrderings().iterator(); 63 while (it.hasNext()) { 64 65 Ordering o = (Ordering) it.next(); 66 key.append('/').append(o.getSortSpecString()); 67 if (!o.isAscending()) { 68 key.append(":d"); 69 } 70 71 if (o.isCaseInsensitive()) { 72 key.append(":i"); 73 } 74 } 75 } 76 77 if(query.getFetchLimit() > 0) { 78 key.append('/').append(query.getFetchLimit()); 79 } 80 81 this.cacheKey = key.toString(); 82 } 83 84 return true; 85 } 86 87 return false; 88 } 89 } 90 | Popular Tags |