KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > jdbc > metadata > JDBCJBossQLQueryMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.jdbc.metadata;
23
24 import java.lang.reflect.Method JavaDoc;
25
26 import org.w3c.dom.Element JavaDoc;
27 import org.jboss.deployment.DeploymentException;
28 import org.jboss.metadata.MetaData;
29
30 /**
31  * Immutable class which contains information about an JBossQL query.
32  *
33  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
34  * @version $Revision: 37459 $
35  */

36 public final class JDBCJBossQLQueryMetaData implements JDBCQueryMetaData
37 {
38    /**
39     * The method to which this query is bound.
40     */

41    private final Method JavaDoc method;
42
43    /**
44     * The ejb-ql fro the query.
45     */

46    private final String JavaDoc jbossQL;
47
48    /**
49     * Should the query return Local or Remote beans.
50     */

51    private final boolean resultTypeMappingLocal;
52
53    /**
54     * Read ahead meta data.
55     */

56    private final JDBCReadAheadMetaData readAhead;
57
58    private final Class JavaDoc compiler;
59
60    private final boolean lazyResultSetLoading;
61
62    /**
63     * Constructs a JDBCJBossQLQueryMetaData with JBossQL declared in the
64     * jboss-ql elemnt and is invoked by the specified method.
65     */

66    public JDBCJBossQLQueryMetaData(JDBCJBossQLQueryMetaData defaults,
67                                    JDBCReadAheadMetaData readAhead,
68                                    Class JavaDoc qlCompiler,
69                                    boolean lazyResultSetLoading)
70       throws DeploymentException
71    {
72       this.method = defaults.getMethod();
73       this.readAhead = readAhead;
74       this.jbossQL = defaults.getJBossQL();
75       this.resultTypeMappingLocal = defaults.isResultTypeMappingLocal();
76       this.compiler = qlCompiler;
77       this.lazyResultSetLoading = lazyResultSetLoading;
78    }
79
80    /**
81     * Constructs a JDBCJBossQLQueryMetaData with JBossQL declared in the
82     * jboss-ql elemnt and is invoked by the specified method.
83     */

84    public JDBCJBossQLQueryMetaData(boolean resultTypeMappingLocal,
85                                    Element JavaDoc element,
86                                    Method JavaDoc method,
87                                    JDBCReadAheadMetaData readAhead,
88                                    Class JavaDoc compiler,
89                                    boolean lazyResultSetLoading)
90       throws DeploymentException
91    {
92       this.method = method;
93       this.readAhead = readAhead;
94       jbossQL = MetaData.getElementContent(element);
95       if(jbossQL == null || jbossQL.trim().length() == 0)
96       {
97          throw new DeploymentException("jboss-ql element is empty");
98       }
99       this.resultTypeMappingLocal = resultTypeMappingLocal;
100       this.compiler = compiler;
101       this.lazyResultSetLoading = lazyResultSetLoading;
102    }
103
104    // javadoc in parent class
105
public Method JavaDoc getMethod()
106    {
107       return method;
108    }
109
110    public Class JavaDoc getQLCompilerClass()
111    {
112       return compiler;
113    }
114
115    /**
116     * Gets the JBossQL query which will be invoked.
117     *
118     * @return the ejb ql String for this query
119     */

120    public String JavaDoc getJBossQL()
121    {
122       return jbossQL;
123    }
124
125    // javadoc in parent class
126
public boolean isResultTypeMappingLocal()
127    {
128       return resultTypeMappingLocal;
129    }
130
131    /**
132     * Gets the read ahead metadata for the query.
133     *
134     * @return the read ahead metadata for the query.
135     */

136    public JDBCReadAheadMetaData getReadAhead()
137    {
138       return readAhead;
139    }
140
141    public boolean isLazyResultSetLoading()
142    {
143       return lazyResultSetLoading;
144    }
145
146    /**
147     * Compares this JDBCJBossQLQueryMetaData against the specified object.
148     * Returns true if the objects are the same. Two JDBCJBossQLQueryMetaData
149     * are the same if they are both invoked by the same method.
150     *
151     * @param o the reference object with which to compare
152     * @return true if this object is the same as the object argument;
153     * false otherwise
154     */

155    public boolean equals(Object JavaDoc o)
156    {
157       if(o instanceof JDBCJBossQLQueryMetaData)
158       {
159          return ((JDBCJBossQLQueryMetaData) o).method.equals(method);
160       }
161       return false;
162    }
163
164    /**
165     * Returns a hashcode for this JDBCJBossQLQueryMetaData. The hashcode is
166     * computed by the method which invokes this query.
167     *
168     * @return a hash code value for this object
169     */

170    public int hashCode()
171    {
172       return method.hashCode();
173    }
174
175    /**
176     * Returns a string describing this JDBCJBossQLQueryMetaData. The exact
177     * details of the representation are unspecified and subject to change, but
178     * the following may be regarded as typical:
179     * <p/>
180     * "[JDBCJBossQLQueryMetaData: method=public org.foo.User
181     * findByName(java.lang.String)]"
182     *
183     * @return a string representation of the object
184     */

185    public String JavaDoc toString()
186    {
187       return "[JDBCJBossQLQueryMetaData : method=" + method + "]";
188    }
189 }
190
Popular Tags