KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > org > primrose > pool > core > PoolPreparedStatement


1 /**
2 * Library name : Primrose - A Java Database Connection Pool.
3 * Published by Ben Keeping, http://primrose.org.uk .
4 * Copyright (C) 2004 Ben Keeping, primrose.org.uk
5 * Email: Use "Contact Us Form" on website
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library 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 library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */

21
22 package uk.org.primrose.pool.core;
23
24 import java.math.BigDecimal JavaDoc;
25 import java.util.Calendar JavaDoc;
26 import java.sql.*;
27
28 /**
29 * A wrapper for a vendor specific implementation of PreparedStatement.
30 * Allows for complete logging of SQL transactions, aswell as identifying
31 * unclosed statements before Connection close() calls.
32 */

33 public class PoolPreparedStatement extends PoolStatement implements PreparedStatement {
34     PreparedStatement ps = null;
35     PoolSqlMonitor poolSqlMonitor = null;
36
37     public PoolPreparedStatement(PreparedStatement ps, PoolSqlMonitor poolSqlMonitor) {
38         super(ps, poolSqlMonitor);
39         this.poolSqlMonitor = poolSqlMonitor;
40         poolSqlMonitor.setStatementClosed(false);
41         poolSqlMonitor.setStatement(this);
42         this.ps = ps;
43     }
44
45     public PoolPreparedStatement(){
46         super();
47     }
48
49     public void setPoolSqlMonitor(PoolSqlMonitor poolSqlMonitor) {
50         this.poolSqlMonitor = poolSqlMonitor;
51     }
52
53     public PoolSqlMonitor getPoolSqlMonitor() {
54         return poolSqlMonitor;
55     }
56
57
58     public ResultSet executeQuery() throws SQLException {
59         PoolResultSet prs = new PoolResultSet(ps.executeQuery(), this.getPoolSqlMonitor());
60         return prs;
61     }
62
63     public int executeUpdate() throws SQLException {
64         return ps.executeUpdate();
65     }
66
67     public void setNull(int parameterIndex, int sqlType) throws SQLException {
68         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +sqlType +")");
69         ps.setNull(parameterIndex, sqlType);
70     }
71
72     public void setBoolean(int parameterIndex, boolean x) throws SQLException {
73         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
74         ps.setBoolean(parameterIndex, x);
75     }
76
77     public void setByte(int parameterIndex, byte x) throws SQLException {
78         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
79         ps.setByte(parameterIndex, x);
80     }
81
82     public void setShort(int parameterIndex, short x) throws SQLException {
83         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
84         ps.setShort(parameterIndex, x);
85     }
86
87     public void setInt(int parameterIndex, int x) throws SQLException {
88         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
89         ps.setInt(parameterIndex, x);
90     }
91
92     public void setLong(int parameterIndex, long x) throws SQLException {
93         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
94         ps.setLong(parameterIndex, x);
95     }
96
97     public void setFloat(int parameterIndex, float x) throws SQLException {
98         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
99         ps.setFloat(parameterIndex, x);
100     }
101
102     public void setDouble(int parameterIndex, double x) throws SQLException {
103         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
104         ps.setDouble(parameterIndex, x);
105     }
106
107     public void setBigDecimal(int parameterIndex, BigDecimal JavaDoc x) throws SQLException {
108         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
109         ps.setBigDecimal(parameterIndex, x);
110     }
111
112     public void setString(int parameterIndex, String JavaDoc x) throws SQLException {
113         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
114         ps.setString(parameterIndex, x);
115     }
116
117     public void setBytes(int parameterIndex, byte x[]) throws SQLException {
118         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
119         ps.setBytes(parameterIndex, x);
120     }
121
122     public void setDate(int parameterIndex, java.sql.Date JavaDoc x) throws SQLException {
123         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
124         ps.setDate(parameterIndex, x);
125     }
126
127     public void setTime(int parameterIndex, java.sql.Time JavaDoc x) throws SQLException {
128         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
129         ps.setTime(parameterIndex, x);
130     }
131
132     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x) throws SQLException {
133         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
134         ps.setTimestamp(parameterIndex, x);
135     }
136
137     public void setAsciiStream(int parameterIndex, java.io.InputStream JavaDoc x, int length) throws SQLException {
138         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
139         ps.setAsciiStream(parameterIndex, x, length);
140     }
141
142     public void setUnicodeStream(int parameterIndex, java.io.InputStream JavaDoc x, int length) throws SQLException {
143         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
144         ps.setUnicodeStream(parameterIndex, x, length);
145     }
146
147     public void setBinaryStream(int parameterIndex, java.io.InputStream JavaDoc x, int length) throws SQLException {
148         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
149         ps.setBinaryStream(parameterIndex, x, length);
150     }
151
152     public void clearParameters() throws SQLException {
153         ps.clearParameters();
154     }
155
156     public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType, int scale) throws SQLException {
157         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
158         ps.setObject(parameterIndex, x, targetSqlType, scale);
159     }
160
161     public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType) throws SQLException {
162         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
163         ps.setObject(parameterIndex, x, targetSqlType);
164     }
165
166     public void setObject(int parameterIndex, Object JavaDoc x) throws SQLException {
167         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
168         ps.setObject(parameterIndex, x);
169     }
170
171     public boolean execute() throws SQLException {
172         return ps.execute();
173     }
174
175     public void addBatch() throws SQLException {
176         ps.addBatch();
177     }
178
179     public void setCharacterStream(int parameterIndex, java.io.Reader JavaDoc reader, int length) throws SQLException {
180         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +reader +")");
181         ps.setCharacterStream(parameterIndex, reader, length);
182     }
183
184     public void setRef (int i, Ref x) throws SQLException {
185         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +i +"(" +x +")");
186         ps.setRef(i, x);
187     }
188
189     public void setBlob (int i, Blob x) throws SQLException {
190         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +i +"(" +x +")");
191         ps.setBlob(i, x);
192     }
193
194     public void setClob (int i, Clob x) throws SQLException {
195         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +i +"(" +x +")");
196         ps.setClob(i, x);
197     }
198
199     public void setArray (int i, Array x) throws SQLException {
200         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +i +"(" +x +")");
201         ps.setArray(i, x);
202     }
203
204     public ResultSetMetaData getMetaData() throws SQLException {
205         return ps.getMetaData();
206     }
207
208     public void setDate(int parameterIndex, java.sql.Date JavaDoc x, Calendar JavaDoc cal) throws SQLException {
209         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
210         ps.setDate(parameterIndex, x, cal);
211     }
212
213     public void setTime(int parameterIndex, java.sql.Time JavaDoc x, Calendar JavaDoc cal) throws SQLException {
214         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
215         ps.setTime(parameterIndex, x, cal);
216     }
217
218     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x, Calendar JavaDoc cal) throws SQLException {
219         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
220         ps.setTimestamp(parameterIndex, x, cal);
221     }
222
223     public void setNull (int parameterIndex, int sqlType, String JavaDoc typeName) throws SQLException {
224         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +typeName +")");
225         ps.setNull(parameterIndex, sqlType, typeName);
226     }
227
228     public void setURL(int parameterIndex, java.net.URL JavaDoc x) throws SQLException {
229         poolSqlMonitor.setSql(poolSqlMonitor.getSql() +" " +parameterIndex +"(" +x +")");
230         ps.setURL(parameterIndex, x);
231     }
232
233     public ParameterMetaData getParameterMetaData() throws SQLException {
234         return ps.getParameterMetaData();
235     }
236
237 }
238
Popular Tags