KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > cfg > Query


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

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 JavaDoc;
37
38 /**
39  * <pre>
40  * query ::= (description?,
41  * query-method,
42  * result-type-mapping?,
43  * ejb-ql)
44  * </pre>
45  */

46 public class Query {
47   private static L10N L = new L10N(MethodSignature.class);
48
49   private EjbEntityBean _entity;
50
51   private String JavaDoc _location;
52   
53   private String JavaDoc _description;
54
55   private MethodSignature _signature;
56   
57   private String JavaDoc methodName;
58   private String JavaDoc methodIntf;
59
60   private Object JavaDoc value;
61
62   private String JavaDoc _ejbQL;
63
64   private ArrayList JavaDoc paramTypes;
65
66   public Query(EjbEntityBean entity)
67   {
68     _entity = entity;
69   }
70
71   public void setConfigLocation(String JavaDoc filename, int line)
72   {
73     if (filename != null)
74       _location = filename + ':' + line + ": ";
75   }
76
77   public String JavaDoc getConfigLocation()
78   {
79     return _location;
80   }
81
82   public void setDescription(String JavaDoc description)
83   {
84     _description = description;
85   }
86
87   /**
88    * Sets the query method.
89    */

90   public void setQueryMethod(QueryMethod queryMethod)
91     throws ConfigException
92   {
93     _signature = queryMethod.getSignature();
94
95     String JavaDoc 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   /**
126    * Returns the signature.
127    */

128   public MethodSignature getSignature()
129   {
130     return _signature;
131   }
132
133   /**
134    * Sets the query.
135    */

136   public void setEjbQl(String JavaDoc ejbQL)
137   {
138     _ejbQL = ejbQL;
139   }
140
141   /**
142    * Returns the query.
143    */

144   public String JavaDoc getEjbQl()
145   {
146     return _ejbQL;
147   }
148 }
149
Popular Tags