KickJava   Java API By Example, From Geeks To Geeks.

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


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.jboss.metadata.QueryMetaData;
27
28 /**
29  * Immutable class which contains information about an EJB QL query.
30  *
31  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
32  * @version $Revision: 58415 $
33  */

34 public final class JDBCQlQueryMetaData implements JDBCQueryMetaData
35 {
36    /**
37     * The method to which this query is bound.
38     */

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

44    private final String JavaDoc ejbQl;
45
46    /**
47     * Should the query return Local or Remote beans.
48     */

49    private final boolean resultTypeMappingLocal;
50
51    /**
52     * Read ahead meta data.
53     */

54    private final JDBCReadAheadMetaData readAhead;
55
56    private final Class JavaDoc compiler;
57
58    private final boolean lazyResultSetLoading;
59
60    /**
61     * Constructs a JDBCQlQueryMetaData which is defined by the queryMetaData
62     * and is invoked by the specified method.
63     *
64     * @param queryMetaData the metadata about this query which was loaded
65     * from the ejb-jar.xml file
66     * @param method the method which invokes this query
67     */

68    public JDBCQlQueryMetaData(QueryMetaData queryMetaData, Method JavaDoc method, Class JavaDoc qlCompiler, boolean lazyResultSetLoading)
69    {
70       this.method = method;
71       this.readAhead = JDBCReadAheadMetaData.DEFAULT;
72       ejbQl = queryMetaData.getEjbQl();
73       resultTypeMappingLocal = queryMetaData.getResultTypeMapping().equals(QueryMetaData.LOCAL);
74
75       compiler = qlCompiler;
76       this.lazyResultSetLoading = lazyResultSetLoading;
77    }
78
79    /**
80     * Constructs a JDBCQlQueryMetaData with data from the jdbcQueryMetaData
81     * and additional data from the xml element
82     */

83    public JDBCQlQueryMetaData(JDBCQlQueryMetaData defaults,
84                               JDBCReadAheadMetaData readAhead,
85                               Class JavaDoc compiler,
86                               boolean lazyResultSetLoading)
87    {
88       this.method = defaults.getMethod();
89       this.readAhead = readAhead;
90       this.ejbQl = defaults.getEjbQl();
91       this.resultTypeMappingLocal = defaults.resultTypeMappingLocal;
92       this.compiler = compiler;
93       this.lazyResultSetLoading = lazyResultSetLoading;
94    }
95
96
97    /**
98     * Constructs a JDBCQlQueryMetaData with data from the jdbcQueryMetaData
99     * and additional data from the xml element
100     */

101    public JDBCQlQueryMetaData(JDBCQlQueryMetaData jdbcQueryMetaData,
102                               Method JavaDoc method,
103                               JDBCReadAheadMetaData readAhead)
104    {
105       this.method = method;
106       this.readAhead = readAhead;
107       ejbQl = jdbcQueryMetaData.getEjbQl();
108       resultTypeMappingLocal = jdbcQueryMetaData.resultTypeMappingLocal;
109       compiler = jdbcQueryMetaData.compiler;
110       lazyResultSetLoading = jdbcQueryMetaData.lazyResultSetLoading;
111    }
112
113    // javadoc in parent class
114
public Method JavaDoc getMethod()
115    {
116       return method;
117    }
118
119    public Class JavaDoc getQLCompilerClass()
120    {
121       return compiler;
122    }
123
124    /**
125     * Gets the EJB QL query which will be invoked.
126     *
127     * @return the ejb ql String for this query
128     */

129    public String JavaDoc getEjbQl()
130    {
131       return ejbQl;
132    }
133
134    // javadoc in parent class
135
public boolean isResultTypeMappingLocal()
136    {
137       return resultTypeMappingLocal;
138    }
139
140    /**
141     * Gets the read ahead metadata for the query.
142     *
143     * @return the read ahead metadata for the query.
144     */

145    public JDBCReadAheadMetaData getReadAhead()
146    {
147       return readAhead;
148    }
149
150    public boolean isLazyResultSetLoading()
151    {
152       return lazyResultSetLoading;
153    }
154
155    /**
156     * Compares this JDBCQlQueryMetaData against the specified object. Returns
157     * true if the objects are the same. Two JDBCQlQueryMetaData are the same
158     * if they are both invoked by the same method.
159     *
160     * @param o the reference object with which to compare
161     * @return true if this object is the same as the object argument;
162     * false otherwise
163     */

164    public boolean equals(Object JavaDoc o)
165    {
166       if(o instanceof JDBCQlQueryMetaData)
167       {
168          return ((JDBCQlQueryMetaData) o).method.equals(method);
169       }
170       return false;
171    }
172
173    /**
174     * Returns a hashcode for this JDBCQlQueryMetaData. The hashcode is computed
175     * by the method which invokes this query.
176     *
177     * @return a hash code value for this object
178     */

179    public int hashCode()
180    {
181       return method.hashCode();
182    }
183
184    /**
185     * Returns a string describing this JDBCQlQueryMetaData. The exact details
186     * of the representation are unspecified and subject to change, but the
187     * following may be regarded as typical:
188     * <p/>
189     * "[JDBCQlQueryMetaData: method=public org.foo.User
190     * findByName(java.lang.String)]"
191     *
192     * @return a string representation of the object
193     */

194    public String JavaDoc toString()
195    {
196       return "[JDBCQlQueryMetaData : method=" + method + "]";
197    }
198 }
199
Popular Tags