1 19 20 package org.apache.cayenne.query; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.apache.cayenne.map.EntityResolver; 29 import org.apache.cayenne.map.Procedure; 30 31 class ProcedureQueryMetadata extends BaseQueryMetadata { 32 33 transient Procedure procedure; 34 35 public Procedure getProcedure() { 36 return procedure; 37 } 38 39 void copyFromInfo(QueryMetadata info) { 40 procedure = null; 41 super.copyFromInfo(info); 42 } 43 44 void resolve( 45 Object root, 46 Object resultRoot, 47 EntityResolver resolver, 48 ProcedureQuery query) { 49 if (super.resolve(resultRoot, resolver, null)) { 50 procedure = null; 51 52 if (root != null) { 53 if (root instanceof String ) { 54 this.procedure = resolver.lookupProcedure((String ) root); 55 } 56 else if (root instanceof Procedure) { 57 this.procedure = (Procedure) root; 58 } 59 60 if (this.procedure != null && this.dataMap == null) { 63 this.dataMap = procedure.getDataMap(); 64 } 65 } 66 67 if (QueryMetadata.NO_CACHE.equals(getCachePolicy())) { 69 70 } 71 else if (query.getName() != null) { 72 this.cacheKey = query.getName(); 73 } 74 else { 75 76 78 StringBuffer key = new StringBuffer ("proc:"); 79 if (procedure != null) { 80 key.append(procedure.getName()); 81 } 82 83 Map parameters = query.getParameters(); 84 if (!parameters.isEmpty()) { 85 86 List keys = new ArrayList (parameters.keySet()); 87 Collections.sort(keys); 88 89 Iterator it = keys.iterator(); 90 while (it.hasNext()) { 91 Object parameterKey = it.next(); 92 key.append('/').append(parameterKey).append('=').append( 93 parameters.get(parameterKey)); 94 } 95 } 96 97 this.cacheKey = key.toString(); 98 } 99 100 } 101 } 102 } 103 | Popular Tags |