001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.cfg21;
031:
032: import com.caucho.ejb.cfg.*;
033: import com.caucho.ejb.cfg21.EjbEntityBean;
034: import com.caucho.config.ConfigException;
035: import com.caucho.util.L10N;
036:
037: import java.util.ArrayList;
038:
039: /**
040: * <pre>
041: * query ::= (description?,
042: * query-method,
043: * result-type-mapping?,
044: * ejb-ql)
045: * </pre>
046: */
047: public class Query {
048: private static L10N L = new L10N(MethodSignature.class);
049:
050: private EjbEntityBean _entity;
051:
052: private String _location;
053:
054: private String _description;
055:
056: private MethodSignature _signature;
057:
058: private String methodName;
059: private String methodIntf;
060:
061: private Object value;
062:
063: private String _ejbQL;
064:
065: private ArrayList paramTypes;
066:
067: public Query(EjbEntityBean entity) {
068: _entity = entity;
069: }
070:
071: public void setConfigLocation(String filename, int line) {
072: if (filename != null)
073: _location = filename + ':' + line + ": ";
074: }
075:
076: public String getConfigLocation() {
077: return _location;
078: }
079:
080: public void setDescription(String description) {
081: _description = description;
082: }
083:
084: /**
085: * Sets the query method.
086: */
087: public void setQueryMethod(QueryMethod queryMethod)
088: throws ConfigException {
089: _signature = queryMethod.getSignature();
090:
091: String methodName = _signature.getName();
092:
093: if (methodName.equals("findByPrimaryKey")) {
094: throw new ConfigException(
095: L
096: .l("'findByPrimaryKey' can't be defined in a query."));
097: } else if (methodName.startsWith("find")) {
098: ApiMethod method = _entity.findMethod(_signature, _entity
099: .getRemoteHome(), "home");
100:
101: if (method == null)
102: method = _entity.findMethod(_signature, _entity
103: .getLocalHome(), "local-home");
104:
105: if (method == null)
106: throw new ConfigException(
107: L
108: .l(
109: "Query method '{0}' must be defined in either the <home> or <local-home>.",
110: _signature.toSignatureString()));
111: } else if (methodName.startsWith("ejbSelect")) {
112: ApiMethod method = _entity.findMethod(_signature, _entity
113: .getEJBClassWrapper(), null);
114:
115: if (method == null)
116: throw new ConfigException(L.l(
117: "{0}: Query method '{1}' must be defined.",
118: _entity.getEJBClass().getName(), _signature
119: .toSignatureString()));
120: } else
121: throw new ConfigException(
122: L
123: .l(
124: "'{0}' is an invalid method name for an ejb-ql query. Only findXXX and ejbSelectXXX methods have queries.",
125: methodName));
126: }
127:
128: /**
129: * Returns the signature.
130: */
131: public MethodSignature getSignature() {
132: return _signature;
133: }
134:
135: /**
136: * Sets the query.
137: */
138: public void setEjbQl(String ejbQL) {
139: _ejbQL = ejbQL;
140: }
141:
142: /**
143: * Returns the query.
144: */
145: public String getEjbQl() {
146: return _ejbQL;
147: }
148: }
|