KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

39    private final Method JavaDoc method;
40
41    /**
42     * Should the query return Local or Remote beans.
43     */

44    private final boolean resultTypeMappingLocal;
45
46    private final JDBCReadAheadMetaData readAhead;
47
48    private final Class JavaDoc compiler;
49
50    private final boolean lazyResultSetLoading;
51
52    /**
53     * Constructs a JDBCDynamicQLQueryMetaData with DynamicQL declared in the
54     * jboss-ql elemnt and is invoked by the specified method.
55     *
56     * @param defaults the metadata about this query
57     */

58    public JDBCDynamicQLQueryMetaData(JDBCDynamicQLQueryMetaData defaults,
59                                      JDBCReadAheadMetaData readAhead,
60                                      Class JavaDoc qlCompiler,
61                                      boolean lazyResultSetLoading)
62       throws DeploymentException
63    {
64       this.method = defaults.getMethod();
65       this.readAhead = readAhead;
66       this.resultTypeMappingLocal = defaults.isResultTypeMappingLocal();
67       compiler = qlCompiler;
68       this.lazyResultSetLoading = lazyResultSetLoading;
69    }
70
71
72    /**
73     * Constructs a JDBCDynamicQLQueryMetaData with DynamicQL declared in the
74     * jboss-ql elemnt and is invoked by the specified method.
75     */

76    public JDBCDynamicQLQueryMetaData(boolean resultTypeMappingLocal,
77                                      Method JavaDoc method,
78                                      JDBCReadAheadMetaData readAhead,
79                                      Class JavaDoc compiler,
80                                      boolean lazyResultSetLoading)
81       throws DeploymentException
82    {
83
84       this.method = method;
85       this.readAhead = readAhead;
86       this.resultTypeMappingLocal = resultTypeMappingLocal;
87
88       Class JavaDoc[] parameterTypes = method.getParameterTypes();
89       if(parameterTypes.length != 2
90          ||
91          !parameterTypes[0].equals(String JavaDoc.class) ||
92          !parameterTypes[1].equals(Object JavaDoc[].class))
93       {
94          throw new DeploymentException(
95             "Dynamic-ql method must have two " +
96             "parameters of type String and Object[]."
97          );
98       }
99
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    // javadoc in parent class
111
public boolean isResultTypeMappingLocal()
112    {
113       return resultTypeMappingLocal;
114    }
115
116    /**
117     * Gets the read ahead metadata for the query.
118     *
119     * @return the read ahead metadata for the query.
120     */

121    public JDBCReadAheadMetaData getReadAhead()
122    {
123       return readAhead;
124    }
125
126    public Class JavaDoc getQLCompilerClass()
127    {
128       return compiler;
129    }
130
131    public boolean isLazyResultSetLoading()
132    {
133       return lazyResultSetLoading;
134    }
135
136    /**
137     * Compares this JDBCDynamicQLQueryMetaData against the specified object.
138     * Returns true if the objects are the same. Two JDBCDynamicQLQueryMetaData
139     * are the same if they are both invoked by the same method.
140     *
141     * @param o the reference object with which to compare
142     * @return true if this object is the same as the object argument;
143     * false otherwise
144     */

145    public boolean equals(Object JavaDoc o)
146    {
147       if(o instanceof JDBCDynamicQLQueryMetaData)
148       {
149          return ((JDBCDynamicQLQueryMetaData) o).method.equals(method);
150       }
151       return false;
152    }
153
154    /**
155     * Returns a hashcode for this JDBCDynamicQLQueryMetaData. The hashcode is
156     * computed by the method which invokes this query.
157     *
158     * @return a hash code value for this object
159     */

160    public int hashCode()
161    {
162       return method.hashCode();
163    }
164
165    /**
166     * Returns a string describing this JDBCDynamicQLQueryMetaData. The exact
167     * details of the representation are unspecified and subject to change, but
168     * the following may be regarded as typical:
169     * <p/>
170     * "[JDBCDynamicQLQueryMetaData: method=public org.foo.User
171     * findByName(java.lang.String)]"
172     *
173     * @return a string representation of the object
174     */

175    public String JavaDoc toString()
176    {
177       return "[JDBCDynamicQLQueryMetaData : method=" + method + "]";
178    }
179 }
180
Popular Tags