1 19 20 package org.apache.cayenne.query; 21 22 import org.apache.cayenne.CayenneRuntimeException; 23 import org.apache.cayenne.map.EntityResolver; 24 25 32 public abstract class IndirectQuery implements Query { 33 34 protected String name; 35 36 protected transient Query replacementQuery; 37 protected transient EntityResolver lastResolver; 38 39 42 public QueryMetadata getMetaData(EntityResolver resolver) { 43 return getReplacementQuery(resolver).getMetaData(resolver); 44 } 45 46 public String getName() { 47 return name; 48 } 49 50 public void setName(String name) { 51 this.name = name; 52 } 53 54 57 public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery) { 58 getReplacementQuery(resolver).route( 59 router, 60 resolver, 61 substitutedQuery != null ? substitutedQuery : this); 62 } 63 64 68 protected abstract Query createReplacementQuery(EntityResolver resolver); 69 70 73 protected Query getReplacementQuery(EntityResolver resolver) { 74 if (replacementQuery == null || lastResolver != resolver) { 75 this.replacementQuery = createReplacementQuery(resolver); 76 this.lastResolver = resolver; 77 } 78 79 return replacementQuery; 80 } 81 82 85 public SQLAction createSQLAction(SQLActionVisitor visitor) { 86 throw new CayenneRuntimeException(this.getClass().getName() 87 + " is an indirect query and doesn't support its own sql actions. " 88 + "It should've been delegated to another " 89 + "query during resolution or routing phase."); 90 } 91 } 92 | Popular Tags |