001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb.plugins.cmp.jdbc.metadata;
023:
024: import java.lang.reflect.Method;
025:
026: import org.w3c.dom.Element;
027: import org.jboss.deployment.DeploymentException;
028: import org.jboss.metadata.MetaData;
029:
030: /**
031: * Immutable class which contains information about an JBossQL query.
032: *
033: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
034: * @version $Revision: 57209 $
035: */
036: public final class JDBCJBossQLQueryMetaData implements
037: JDBCQueryMetaData {
038: /**
039: * The method to which this query is bound.
040: */
041: private final Method method;
042:
043: /**
044: * The ejb-ql fro the query.
045: */
046: private final String jbossQL;
047:
048: /**
049: * Should the query return Local or Remote beans.
050: */
051: private final boolean resultTypeMappingLocal;
052:
053: /**
054: * Read ahead meta data.
055: */
056: private final JDBCReadAheadMetaData readAhead;
057:
058: private final Class compiler;
059:
060: private final boolean lazyResultSetLoading;
061:
062: /**
063: * Constructs a JDBCJBossQLQueryMetaData with JBossQL declared in the
064: * jboss-ql elemnt and is invoked by the specified method.
065: */
066: public JDBCJBossQLQueryMetaData(JDBCJBossQLQueryMetaData defaults,
067: JDBCReadAheadMetaData readAhead, Class qlCompiler,
068: boolean lazyResultSetLoading) throws DeploymentException {
069: this .method = defaults.getMethod();
070: this .readAhead = readAhead;
071: this .jbossQL = defaults.getJBossQL();
072: this .resultTypeMappingLocal = defaults
073: .isResultTypeMappingLocal();
074: this .compiler = qlCompiler;
075: this .lazyResultSetLoading = lazyResultSetLoading;
076: }
077:
078: /**
079: * Constructs a JDBCJBossQLQueryMetaData with JBossQL declared in the
080: * jboss-ql elemnt and is invoked by the specified method.
081: */
082: public JDBCJBossQLQueryMetaData(boolean resultTypeMappingLocal,
083: Element element, Method method,
084: JDBCReadAheadMetaData readAhead, Class compiler,
085: boolean lazyResultSetLoading) throws DeploymentException {
086: this .method = method;
087: this .readAhead = readAhead;
088: jbossQL = MetaData.getElementContent(element);
089: if (jbossQL == null || jbossQL.trim().length() == 0) {
090: throw new DeploymentException("jboss-ql element is empty");
091: }
092: this .resultTypeMappingLocal = resultTypeMappingLocal;
093: this .compiler = compiler;
094: this .lazyResultSetLoading = lazyResultSetLoading;
095: }
096:
097: // javadoc in parent class
098: public Method getMethod() {
099: return method;
100: }
101:
102: public Class getQLCompilerClass() {
103: return compiler;
104: }
105:
106: /**
107: * Gets the JBossQL query which will be invoked.
108: *
109: * @return the ejb ql String for this query
110: */
111: public String getJBossQL() {
112: return jbossQL;
113: }
114:
115: // javadoc in parent class
116: public boolean isResultTypeMappingLocal() {
117: return resultTypeMappingLocal;
118: }
119:
120: /**
121: * Gets the read ahead metadata for the query.
122: *
123: * @return the read ahead metadata for the query.
124: */
125: public JDBCReadAheadMetaData getReadAhead() {
126: return readAhead;
127: }
128:
129: public boolean isLazyResultSetLoading() {
130: return lazyResultSetLoading;
131: }
132:
133: /**
134: * Compares this JDBCJBossQLQueryMetaData against the specified object.
135: * Returns true if the objects are the same. Two JDBCJBossQLQueryMetaData
136: * are the same if they are both invoked by the same method.
137: *
138: * @param o the reference object with which to compare
139: * @return true if this object is the same as the object argument;
140: * false otherwise
141: */
142: public boolean equals(Object o) {
143: if (o instanceof JDBCJBossQLQueryMetaData) {
144: return ((JDBCJBossQLQueryMetaData) o).method.equals(method);
145: }
146: return false;
147: }
148:
149: /**
150: * Returns a hashcode for this JDBCJBossQLQueryMetaData. The hashcode is
151: * computed by the method which invokes this query.
152: *
153: * @return a hash code value for this object
154: */
155: public int hashCode() {
156: return method.hashCode();
157: }
158:
159: /**
160: * Returns a string describing this JDBCJBossQLQueryMetaData. The exact
161: * details of the representation are unspecified and subject to change, but
162: * the following may be regarded as typical:
163: * <p/>
164: * "[JDBCJBossQLQueryMetaData: method=public org.foo.User
165: * findByName(java.lang.String)]"
166: *
167: * @return a string representation of the object
168: */
169: public String toString() {
170: return "[JDBCJBossQLQueryMetaData : method=" + method + "]";
171: }
172: }
|