KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > sql > RequestWithResultSetParameters


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Continuent, Inc.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Emmanuel Cecchet.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.common.sql;
23
24 import java.io.IOException JavaDoc;
25
26 import org.continuent.sequoia.common.stream.DriverBufferedInputStream;
27 import org.continuent.sequoia.common.stream.DriverBufferedOutputStream;
28
29 /**
30  * This class defines a Request with additional parameters indicating how the
31  * ResulSet should be fetched. This is only useful for calls to
32  * Statement.executeQuery() or Statement.execute() when ResultSets are returned.
33  *
34  * @author <a HREF="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
35  * @version 1.0
36  */

37 public class RequestWithResultSetParameters extends Request
38 {
39
40   /*
41    * ResultSet Parameters
42    */

43   private int maxRows = 0;
44   private int fetchSize = 0;
45   private String JavaDoc cursorName = null;
46
47   //
48
// Constructors
49
//
50

51   /**
52    * Creates a new <code>RequestWithResultSetParameters</code> object
53    * @param sqlTemplate the SQL template (using ? as parameter placeholders) or
54    * null
55    * @param parameters the SQL statement
56    * @param escapeProcessing Should the backend driver do escape processing
57    * before sending to the database?
58    * @param timeoutInSeconds Timeout for this request in seconds, value 0 means
59    * no timeout
60    */

61   public RequestWithResultSetParameters(String JavaDoc sqlTemplate, String JavaDoc parameters,
62       boolean escapeProcessing, int timeoutInSeconds)
63   {
64     super(sqlTemplate, parameters, escapeProcessing, timeoutInSeconds);
65   }
66
67   //
68
// Serialization methods
69
//
70

71   /**
72    * Creates a new <code>RequestWithResultSetParameters</code> object,
73    * deserializing it from an input stream. Has to mirror the serialization
74    * method below.
75    *
76    * @param in input stream
77    * @throws IOException stream error
78    */

79   public RequestWithResultSetParameters(DriverBufferedInputStream in)
80       throws IOException JavaDoc
81   {
82     super(in);
83     this.maxRows = in.readInt();
84     this.fetchSize = in.readInt();
85
86     if (in.readBoolean()) // do we have a cursor name ?
87
this.cursorName = in.readLongUTF();
88   }
89
90   /**
91    * Also serialize ResultSet parameters to the stream. Optionally used by
92    * serializers of those derived requests that expect a ResultSet.
93    *
94    * @see org.continuent.sequoia.common.sql.Request#sendToStream(org.continuent.sequoia.common.stream.DriverBufferedOutputStream)
95    */

96   public void sendToStream(DriverBufferedOutputStream out) throws IOException JavaDoc
97   {
98     super.sendToStream(out);
99
100     out.writeInt(maxRows);
101     out.writeInt(fetchSize);
102
103     if (this.cursorName != null) // do we have a cursor name ?
104
{
105       out.writeBoolean(true);
106       out.writeLongUTF(cursorName);
107     }
108     else
109       out.writeBoolean(false);
110   }
111
112   //
113
// Getter/Setter
114
//
115

116   /**
117    * Returns the cursorName value.
118    *
119    * @return Returns the cursorName.
120    */

121   public final String JavaDoc getCursorName()
122   {
123     return cursorName;
124   }
125
126   /**
127    * Sets the cursorName value.
128    *
129    * @param cursorName The cursorName to set.
130    */

131   public final void setCursorName(String JavaDoc cursorName)
132   {
133     this.cursorName = cursorName;
134   }
135
136   /**
137    * Returns the fetchSize value.
138    *
139    * @return Returns the fetchSize.
140    */

141   public final int getFetchSize()
142   {
143     return fetchSize;
144   }
145
146   /**
147    * Sets the fetchSize value.
148    *
149    * @param fetchSize The fetchSize to set.
150    */

151   public final void setFetchSize(int fetchSize)
152   {
153     this.fetchSize = fetchSize;
154   }
155
156   /**
157    * Returns the maxRows value.
158    *
159    * @return Returns the maxRows.
160    */

161   public final int getMaxRows()
162   {
163     return maxRows;
164   }
165
166   /**
167    * Sets the maxRows value.
168    *
169    * @param maxRows The maxRows to set.
170    */

171   public final void setMaxRows(int maxRows)
172   {
173     this.maxRows = maxRows;
174   }
175
176 }
177
Popular Tags