1 19 package org.apache.cayenne.access.jdbc; 20 21 import java.util.Collection ; 22 import java.util.Map ; 23 24 import org.apache.cayenne.ejbql.EJBQLException; 25 26 32 abstract class EJBQLMultiColumnOperand { 33 34 static EJBQLMultiColumnOperand getPathOperand( 35 EJBQLTranslationContext context, 36 Map pathMap) { 37 return new PathMultiColumnOperand(context, pathMap); 38 } 39 40 static EJBQLMultiColumnOperand getObjectOperand( 41 EJBQLTranslationContext context, 42 Map object) { 43 return new ObjectMultiColumnOperand(context, object); 44 } 45 46 EJBQLTranslationContext context; 47 Map map; 48 49 Collection getKeys() { 50 return map.keySet(); 51 } 52 53 abstract void appendValue(Object key); 54 55 private static class PathMultiColumnOperand extends EJBQLMultiColumnOperand { 56 57 PathMultiColumnOperand(EJBQLTranslationContext context, Map pathMap) { 58 this.context = context; 59 this.map = pathMap; 60 } 61 62 void appendValue(Object key) { 63 64 Object column = map.get(key); 65 if (column == null) { 66 throw new EJBQLException("Invalid match path, no match for ID column " 67 + key); 68 } 69 70 context.append(' ').append(column.toString()); 71 } 72 } 73 74 private static class ObjectMultiColumnOperand extends EJBQLMultiColumnOperand { 75 76 ObjectMultiColumnOperand(EJBQLTranslationContext context, Map pathMap) { 77 this.context = context; 78 this.map = pathMap; 79 } 80 81 void appendValue(Object key) { 82 Object value = map.get(key); 83 if (value == null) { 84 throw new EJBQLException("Invalid object, no match for ID column " + key); 85 } 86 87 String var = context.bindParameter(value); 88 context.append(" #bind($").append(var).append(')'); 89 } 90 } 91 } 92 | Popular Tags |