1 19 package org.apache.cayenne.query; 20 21 import java.util.ArrayList ; 22 import java.util.Collections ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import org.apache.cayenne.map.EntityResolver; 28 import org.apache.cayenne.map.ObjEntity; 29 30 34 class SQLTemplateMetadata extends BaseQueryMetadata { 35 36 private SQLResultSetMapping resultSetMapping; 37 38 void setResultSetMapping(SQLResultSetMapping resultSetMapping) { 39 this.resultSetMapping = resultSetMapping; 40 } 41 42 public SQLResultSetMapping getResultSetMapping() { 43 return resultSetMapping; 44 } 45 46 boolean resolve(Object root, EntityResolver resolver, SQLTemplate query) { 47 48 if (super.resolve(root, resolver, null)) { 49 50 if (QueryMetadata.NO_CACHE.equals(getCachePolicy())) { 52 53 } 54 else if (query.getName() != null) { 55 this.cacheKey = query.getName(); 56 } 57 else { 58 59 61 StringBuffer key = new StringBuffer (); 62 ObjEntity entity = getObjEntity(); 63 if (entity != null) { 64 key.append(entity.getName()); 65 } 66 else if (dbEntity != null) { 67 key.append("db:").append(dbEntity.getName()); 68 } 69 70 if (query.getDefaultTemplate() != null) { 71 key.append('/').append(query.getDefaultTemplate()); 72 } 73 74 Map parameters = query.getParameters(); 75 if (!parameters.isEmpty()) { 76 77 List keys = new ArrayList (parameters.keySet()); 78 Collections.sort(keys); 79 80 Iterator it = keys.iterator(); 81 while (it.hasNext()) { 82 Object parameterKey = it.next(); 83 key.append('/').append(parameterKey).append('=').append( 84 parameters.get(parameterKey)); 85 } 86 } 87 88 this.cacheKey = key.toString(); 89 } 90 91 return true; 92 } 93 94 return false; 95 } 96 } 97 | Popular Tags |