001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 Continuent, Inc.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.common.sql;
021:
022: import java.io.IOException;
023:
024: import org.continuent.sequoia.common.stream.DriverBufferedInputStream;
025: import org.continuent.sequoia.common.stream.DriverBufferedOutputStream;
026:
027: /**
028: * This class defines a Request with additional parameters indicating how the
029: * ResulSet should be fetched. This is only useful for calls to
030: * Statement.executeQuery() or Statement.execute() when ResultSets are returned.
031: *
032: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
033: * @version 1.0
034: */
035: public class RequestWithResultSetParameters extends Request {
036:
037: /*
038: * ResultSet Parameters
039: */
040: private int maxRows = 0;
041: private int fetchSize = 0;
042: private String cursorName = null;
043:
044: //
045: // Constructors
046: //
047:
048: /**
049: * Creates a new <code>RequestWithResultSetParameters</code> object
050: * @param sqlTemplate the SQL template (using ? as parameter placeholders) or
051: * null
052: * @param parameters the SQL statement
053: * @param escapeProcessing Should the backend driver do escape processing
054: * before sending to the database?
055: * @param timeoutInSeconds Timeout for this request in seconds, value 0 means
056: * no timeout
057: */
058: public RequestWithResultSetParameters(String sqlTemplate,
059: String parameters, boolean escapeProcessing,
060: int timeoutInSeconds) {
061: super (sqlTemplate, parameters, escapeProcessing,
062: timeoutInSeconds);
063: }
064:
065: //
066: // Serialization methods
067: //
068:
069: /**
070: * Creates a new <code>RequestWithResultSetParameters</code> object,
071: * deserializing it from an input stream. Has to mirror the serialization
072: * method below.
073: *
074: * @param in input stream
075: * @throws IOException stream error
076: */
077: public RequestWithResultSetParameters(DriverBufferedInputStream in)
078: throws IOException {
079: super (in);
080: this .maxRows = in.readInt();
081: this .fetchSize = in.readInt();
082:
083: if (in.readBoolean()) // do we have a cursor name ?
084: this .cursorName = in.readLongUTF();
085: }
086:
087: /**
088: * Also serialize ResultSet parameters to the stream. Optionally used by
089: * serializers of those derived requests that expect a ResultSet.
090: *
091: * @see org.continuent.sequoia.common.sql.Request#sendToStream(org.continuent.sequoia.common.stream.DriverBufferedOutputStream)
092: */
093: public void sendToStream(DriverBufferedOutputStream out)
094: throws IOException {
095: super .sendToStream(out);
096:
097: out.writeInt(maxRows);
098: out.writeInt(fetchSize);
099:
100: if (this .cursorName != null) // do we have a cursor name ?
101: {
102: out.writeBoolean(true);
103: out.writeLongUTF(cursorName);
104: } else
105: out.writeBoolean(false);
106: }
107:
108: //
109: // Getter/Setter
110: //
111:
112: /**
113: * Returns the cursorName value.
114: *
115: * @return Returns the cursorName.
116: */
117: public final String getCursorName() {
118: return cursorName;
119: }
120:
121: /**
122: * Sets the cursorName value.
123: *
124: * @param cursorName The cursorName to set.
125: */
126: public final void setCursorName(String cursorName) {
127: this .cursorName = cursorName;
128: }
129:
130: /**
131: * Returns the fetchSize value.
132: *
133: * @return Returns the fetchSize.
134: */
135: public final int getFetchSize() {
136: return fetchSize;
137: }
138:
139: /**
140: * Sets the fetchSize value.
141: *
142: * @param fetchSize The fetchSize to set.
143: */
144: public final void setFetchSize(int fetchSize) {
145: this .fetchSize = fetchSize;
146: }
147:
148: /**
149: * Returns the maxRows value.
150: *
151: * @return Returns the maxRows.
152: */
153: public final int getMaxRows() {
154: return maxRows;
155: }
156:
157: /**
158: * Sets the maxRows value.
159: *
160: * @param maxRows The maxRows to set.
161: */
162: public final void setMaxRows(int maxRows) {
163: this.maxRows = maxRows;
164: }
165:
166: }
|