1 29 30 package com.caucho.ejb.ql; 31 32 import com.caucho.amber.type.EntityType; 33 import com.caucho.bytecode.JClass; 34 import com.caucho.bytecode.JField; 35 import com.caucho.bytecode.JMethod; 36 import com.caucho.config.ConfigException; 37 import com.caucho.ejb.cfg.EjbEntityBean; 38 import com.caucho.util.CharBuffer; 39 40 43 class ArgExpr extends Expr { 44 private int _index; 46 47 private Class _coerceType; 48 49 54 ArgExpr(Query query, int index) 55 throws ConfigException 56 { 57 _query = query; 58 _index = index; 59 60 evalTypes(); 61 } 62 63 66 int getIndex() 67 { 68 return _query.getArgIndex(_index); 69 } 70 71 74 void evalTypes() 75 throws ConfigException 76 { 77 if (getJavaType() != null) 78 return; 79 80 JMethod method = _query.getMethod(); 81 82 JClass []args = method.getParameterTypes(); 83 84 if (args.length <= _index - 1) 85 throw error(L.l("`{0}' exceeds number of arguments", "?" + _index)); 86 87 setJavaType(args[_index - 1]); 88 89 _query.setArgSize(_index, getComponentCount()); 90 } 91 92 void setCoerceType(Class javaType) 93 { 94 _coerceType = javaType; 95 } 96 97 100 boolean canCoerce() 101 { 102 return true; 103 } 104 105 int getComponentCount() 106 { 107 JClass javaType = getJavaType(); 108 109 if (javaType.isPrimitive() || 110 javaType.isArray() || 111 javaType.getName().startsWith("java.")) 112 return 1; 113 114 if (javaType.isAssignableTo(javax.ejb.EJBLocalObject .class)) { 115 EjbEntityBean bean = _query.getConfig().findEntityByLocal(javaType); 116 117 EntityType type = bean.getEntityType(); 118 119 return type.getId().getKeys().size(); 120 } 121 122 JField []fields = javaType.getFields(); 123 return fields.length; 124 } 125 126 131 void generateWhere(CharBuffer cb) 132 { 133 cb.append("?" + getIndex()); 134 } 135 136 void generateComponent(CharBuffer cb, int index) 137 { 138 cb.append("?" + (getIndex() + index)); 139 } 140 141 144 public String toString() 145 { 146 return "?" + _index; 147 } 148 } 149 | Popular Tags |