1 29 30 package com.caucho.ejb.cfg; 31 32 import com.caucho.bytecode.JMethod; 33 import com.caucho.config.ConfigException; 34 import com.caucho.util.L10N; 35 36 import java.util.ArrayList ; 37 38 46 public class Query { 47 private static L10N L = new L10N(MethodSignature.class); 48 49 private EjbEntityBean _entity; 50 51 private String _location; 52 53 private String _description; 54 55 private MethodSignature _signature; 56 57 private String methodName; 58 private String methodIntf; 59 60 private Object value; 61 62 private String _ejbQL; 63 64 private ArrayList paramTypes; 65 66 public Query(EjbEntityBean entity) 67 { 68 _entity = entity; 69 } 70 71 public void setConfigLocation(String filename, int line) 72 { 73 if (filename != null) 74 _location = filename + ':' + line + ": "; 75 } 76 77 public String getConfigLocation() 78 { 79 return _location; 80 } 81 82 public void setDescription(String description) 83 { 84 _description = description; 85 } 86 87 90 public void setQueryMethod(QueryMethod queryMethod) 91 throws ConfigException 92 { 93 _signature = queryMethod.getSignature(); 94 95 String methodName = _signature.getName(); 96 97 if (methodName.equals("findByPrimaryKey")) { 98 throw new ConfigException(L.l("'findByPrimaryKey' can't be defined in a query.")); 99 } 100 else if (methodName.startsWith("find")) { 101 JMethod method = _entity.findMethod(_signature, _entity.getRemoteHome(), "home"); 102 103 if (method == null) 104 method = _entity.findMethod(_signature, _entity.getLocalHome(), "local-home"); 105 106 if (method == null) 107 throw new ConfigException(L.l("Query method '{0}' must be defined in either the <home> or <local-home>.", 108 _signature.toSignatureString())); 109 } 110 else if (methodName.startsWith("ejbSelect")) { 111 JMethod method = _entity.findMethod(_signature, 112 _entity.getEJBClassWrapper(), 113 null); 114 115 if (method == null) 116 throw new ConfigException(L.l("{0}: Query method '{1}' must be defined.", 117 _entity.getEJBClass().getName(), 118 _signature.toSignatureString())); 119 } 120 else 121 throw new ConfigException(L.l("'{0}' is an invalid method name for an ejb-ql query. Only findXXX and ejbSelectXXX methods have queries.", 122 methodName)); 123 } 124 125 128 public MethodSignature getSignature() 129 { 130 return _signature; 131 } 132 133 136 public void setEjbQl(String ejbQL) 137 { 138 _ejbQL = ejbQL; 139 } 140 141 144 public String getEjbQl() 145 { 146 return _ejbQL; 147 } 148 } 149 | Popular Tags |