KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > db > OracleStatement


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Rodrigo Westrupp
28  */

29
30 package com.caucho.quercus.lib.db;
31
32 import com.caucho.quercus.env.Value;
33 import com.caucho.util.L10N;
34
35 import java.sql.CallableStatement JavaDoc;
36 import java.util.HashMap JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39
40 /**
41  * Oracle statement class. Since Oracle has no object oriented API,
42  * this is essentially a JdbcStatementResource.
43  */

44 public class OracleStatement extends JdbcStatementResource {
45   private static final Logger JavaDoc log = Logger.getLogger(OracleStatement.class.getName());
46   private static final L10N L = new L10N(OracleStatement.class);
47
48   // Oracle statement has a notion of number of fetched rows
49
// (See also: OracleModule.oci_num_rows)
50
private int _fetchedRows;
51
52   // Binding variables for Oracle statements
53
private HashMap JavaDoc<String JavaDoc,Integer JavaDoc> _bindingVariables = new HashMap JavaDoc<String JavaDoc,Integer JavaDoc>();
54   private OracleOciLob _outParameter;
55
56   // Oracle internal result buffer
57
private Value _resultBuffer;
58
59   // Binding variables for Oracle statements with define_by_name (TOTALLY DIFFERENT FROM ?)
60
//
61
// Example:
62
//
63
// $stmt = oci_parse($conn, "SELECT empno, ename FROM emp");
64
//
65
// /* the define MUST be done BEFORE oci_execute! */
66
//
67
// oci_define_by_name($stmt, "EMPNO", $empno);
68
// oci_define_by_name($stmt, "ENAME", $ename);
69
//
70
// oci_execute($stmt);
71
//
72
// while (oci_fetch($stmt)) {
73
// echo "empno:" . $empno . "\n";
74
// echo "ename:" . $ename . "\n";
75
// }
76
//
77
private HashMap JavaDoc<String JavaDoc,Value> _byNameVariables = new HashMap JavaDoc<String JavaDoc,Value>();
78
79   /**
80    * Constructs an OracleStatement
81    *
82    * @param conn Oracle connection
83    */

84   OracleStatement(Oracle conn)
85   {
86     super(conn);
87     _fetchedRows = 0;
88     _outParameter = null;
89   }
90
91   /**
92    * Assigns a variable name to the corresponding index
93    *
94    * @param name the variable name
95    * @param value the corresponding index
96    */

97   public void putBindingVariable(String JavaDoc name, Integer JavaDoc value)
98   {
99     _bindingVariables.put(name, value);
100   }
101
102   /**
103    * Returns a binding variable index
104    *
105    * @param name the variable name
106    * @return the binding variable index
107    */

108   public Integer JavaDoc getBindingVariable(String JavaDoc name)
109   {
110     return _bindingVariables.get(name);
111   }
112
113   /**
114    * Removes a binding variable
115    *
116    * @param name the binding variable name
117    * @return the binding variable index
118    */

119   public Integer JavaDoc removeBindingVariable(String JavaDoc name)
120   {
121     return _bindingVariables.remove(name);
122   }
123
124   /**
125    * Returns all binding variables
126    *
127    * @return a HashMap of variable name to index values
128    */

129   public HashMap JavaDoc<String JavaDoc,Integer JavaDoc> getBindingVariables()
130   {
131     return _bindingVariables;
132   }
133
134   /**
135    * Removes all binding variables
136    */

137   public void resetBindingVariables()
138   {
139     _bindingVariables = new HashMap JavaDoc<String JavaDoc,Integer JavaDoc>();
140   }
141
142   /**
143    * Sets the internal result buffer
144    */

145   public void setResultBuffer(Value resultBuffer)
146   {
147     _resultBuffer = resultBuffer;
148   }
149
150   /**
151    * Returns the internal result buffer
152    *
153    * @return the result buffer
154    */

155   public Value getResultBuffer()
156   {
157     return _resultBuffer;
158   }
159
160   /**
161    * Assigns a value to a variable
162    *
163    * @param name a variable name
164    * @param value the variable value
165    */

166   public void putByNameVariable(String JavaDoc name, Value value)
167   {
168     _byNameVariables.put(name, value);
169   }
170
171   /**
172    * Returns the variable value by name
173    *
174    * @param name the variable name
175    * @return the variable value
176    */

177   public Value getByNameVariable(String JavaDoc name)
178   {
179     return _byNameVariables.get(name);
180   }
181
182   /**
183    * Removes a variable given the corresponding name
184    *
185    * @param name the variable name
186    * @return the variable value
187    */

188   public Value removeByNameVariable(String JavaDoc name)
189   {
190     return _byNameVariables.remove(name);
191   }
192
193   /**
194    * Returns all variable names and corresponding values
195    *
196    * @return a HashMap of variable names to corresponding values
197    */

198   public HashMap JavaDoc<String JavaDoc,Value> getByNameVariables()
199   {
200     return _byNameVariables;
201   }
202
203   /**
204    * Removes all variables
205    */

206   public void resetByNameVariables()
207   {
208     _byNameVariables = new HashMap JavaDoc<String JavaDoc,Value>();
209   }
210
211   /**
212    * Increases the number of fetched rows.
213    *
214    * @return the new number of fetched rows
215    */

216   protected int increaseFetchedRows() {
217     return ++_fetchedRows;
218   }
219
220   /**
221    * Gets the underlying callable statement.
222    */

223   protected CallableStatement JavaDoc getCallableStatement()
224   {
225     return (CallableStatement JavaDoc) getPreparedStatement();
226   }
227
228   /**
229    * Gets the number of fetched rows.
230    *
231    * @return the number of fetched rows
232    */

233   protected int getFetchedRows() {
234     return _fetchedRows;
235   }
236
237   /**
238    * Gets the out parameter.
239    *
240    * @return the out parameter
241    */

242   protected OracleOciLob getOutParameter() {
243     return _outParameter;
244   }
245
246   /**
247    * Sets the out parameter.
248    *
249    * @param outParameter the new out parameter
250    */

251   protected void setOutParameter(OracleOciLob outParameter) {
252     _outParameter = outParameter;
253   }
254 }
255
Popular Tags