KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > jdbc > pool > StatementWrapper


1 package com.protomatter.jdbc.pool;
2
3 import java.io.*;
4 import java.sql.*;
5 import java.util.*;
6
7 import com.protomatter.syslog.Channel;
8
9 /**
10  * A wrapper for JDBC statements.
11  *
12  * @see Statement
13  */

14 class StatementWrapper
15 extends JDBCWrapper
16 implements Statement
17 {
18     private ConnectionWrapper connection = null;
19     private Statement statement = null;
20     private boolean isClosed = false;
21     private Channel log = Channel.forPackage(StatementWrapper.class);
22
23     public StatementWrapper(ConnectionWrapper connection, Statement statement)
24     {
25         super();
26         this.connection = connection;
27         this.statement = statement;
28     }
29
30     public Statement getStatement()
31     {
32         if (this.statement == null)
33             return null;
34         return this.statement;
35     }
36
37     private final void checkClosed()
38     throws SQLException
39     {
40         if (this.isClosed)
41             throw new SQLException("Statement is already closed.");
42     }
43     
44     public ResultSet executeQuery(String JavaDoc sql)
45     throws SQLException
46     {
47         checkClosed();
48         return (ResultSet)callMethod(statement, "executeQuery", new Class JavaDoc[] { String JavaDoc.class }, new Object JavaDoc[] { sql });
49     }
50
51     public int executeUpdate(String JavaDoc sql)
52     throws SQLException
53     {
54         checkClosed();
55         return callIntMethod(statement, "executeUpdate", new Class JavaDoc[] { String JavaDoc.class }, new Object JavaDoc[] { sql });
56     }
57
58     public void close()
59     throws SQLException
60     {
61         if (this.isClosed)
62             return;
63
64         callMethod(statement, "close");
65
66         this.isClosed = true;
67         this.connection = null;
68         this.statement = null;
69     }
70
71     public int getMaxFieldSize()
72     throws SQLException
73     {
74         checkClosed();
75         return callIntMethod(statement, "getMaxFieldSize", new Class JavaDoc[0], new Object JavaDoc[0]);
76     }
77
78     public void setMaxFieldSize(int size)
79     throws SQLException
80     {
81         checkClosed();
82         callMethod(statement, "setMaxFieldSize", new Class JavaDoc[] { Integer.TYPE }, new Object JavaDoc[] { new Integer JavaDoc(size) });
83     }
84
85     public int getMaxRows()
86     throws SQLException
87     {
88         checkClosed();
89         return callIntMethod(statement, "getMaxRows", new Class JavaDoc[0], new Object JavaDoc[0]);
90     }
91
92     public void setMaxRows(int rows)
93     throws SQLException
94     {
95         checkClosed();
96         callMethod(statement, "setMaxRows", new Class JavaDoc[] { Integer.TYPE }, new Object JavaDoc[] { new Integer JavaDoc(rows) });
97     }
98
99     public void setEscapeProcessing(boolean setting)
100     throws SQLException
101     {
102         checkClosed();
103         callMethod(statement, "setEscapeProcessing", new Class JavaDoc[] { Boolean JavaDoc.class }, new Object JavaDoc[] { new Boolean JavaDoc(setting) });
104     }
105
106     public int getQueryTimeout()
107     throws SQLException
108     {
109         checkClosed();
110         return callIntMethod(statement, "getQueryTimeout", new Class JavaDoc[0], new Object JavaDoc[0]);
111     }
112
113     public void setQueryTimeout(int timeout)
114     throws SQLException
115     {
116         checkClosed();
117         callMethod(statement, "setQueryTimeout", new Class JavaDoc[] { Integer.TYPE }, new Object JavaDoc[] { new Integer JavaDoc(timeout) });
118     }
119
120     public void cancel()
121     throws SQLException
122     {
123         checkClosed();
124         callMethod(statement, "cancel");
125     }
126
127     public SQLWarning getWarnings()
128     throws SQLException
129     {
130         checkClosed();
131         return (SQLWarning)callMethod(statement, "getWarnings");
132     }
133
134     public void clearWarnings()
135     throws SQLException
136     {
137         checkClosed();
138         callMethod(statement, "clearWarnings");
139     }
140
141     public void setCursorName(String JavaDoc name)
142     throws SQLException
143     {
144         checkClosed();
145         callMethod(statement, "setCursorName", new Class JavaDoc[] { String JavaDoc.class }, new Object JavaDoc[] { name });
146     }
147
148     public boolean execute(String JavaDoc sql)
149     throws SQLException
150     {
151         checkClosed();
152         return callBooleanMethod(statement, "execute", new Class JavaDoc[] { String JavaDoc.class }, new Object JavaDoc[] { sql });
153     }
154
155     public ResultSet getResultSet()
156     throws SQLException
157     {
158         checkClosed();
159         return (ResultSet)callMethod(statement, "getResultSet");
160     }
161
162     public int getUpdateCount()
163     throws SQLException
164     {
165         checkClosed();
166         return callIntMethod(statement, "getUpdateCount", new Class JavaDoc[0], new Object JavaDoc[0]);
167     }
168
169     public boolean getMoreResults()
170     throws SQLException
171     {
172         checkClosed();
173         return callBooleanMethod(statement, "getMoreResults", new Class JavaDoc[0], new Object JavaDoc[0]);
174     }
175
176     public void setFetchDirection(int direction)
177     throws SQLException
178     {
179         checkClosed();
180         callMethod(statement, "setFetchDirection", new Class JavaDoc[] { Integer.TYPE }, new Object JavaDoc[] { new Integer JavaDoc(direction) });
181     }
182
183     public int getFetchDirection()
184     throws SQLException
185     {
186         checkClosed();
187         return callIntMethod(statement, "getFetchDirection", new Class JavaDoc[0], new Object JavaDoc[0]);
188     }
189
190     public void setFetchSize(int size)
191     throws SQLException
192     {
193         checkClosed();
194         callMethod(statement, "setFetchSize", new Class JavaDoc[] { Integer.TYPE }, new Object JavaDoc[] { new Integer JavaDoc(size) });
195     }
196
197     public int getFetchSize()
198     throws SQLException
199     {
200         checkClosed();
201         return callIntMethod(statement, "getFetchSize", new Class JavaDoc[0], new Object JavaDoc[0]);
202     }
203
204     public int getResultSetConcurrency()
205     throws SQLException
206     {
207         checkClosed();
208         return callIntMethod(statement, "getResultSetConcurrency", new Class JavaDoc[0], new Object JavaDoc[0]);
209     }
210
211     public int getResultSetType()
212     throws SQLException
213     {
214         checkClosed();
215         return callIntMethod(statement, "getResultSetType", new Class JavaDoc[0], new Object JavaDoc[0]);
216     }
217
218     public void addBatch(String JavaDoc sql)
219     throws SQLException
220     {
221         checkClosed();
222         callMethod(statement, "addBatch", new Class JavaDoc[] { String JavaDoc.class }, new Object JavaDoc[] { sql });
223     }
224
225     public void clearBatch()
226     throws SQLException
227     {
228         checkClosed();
229         callMethod(statement, "clearBatch", new Class JavaDoc[0], new Object JavaDoc[0]);
230     }
231
232     public int[] executeBatch()
233     throws SQLException
234     {
235         checkClosed();
236         // yes, this does work... int[] is an Object.
237
return (int[])callMethod(statement, "executeBatch", new Class JavaDoc[0], new Object JavaDoc[0]);
238     }
239
240     public Connection getConnection()
241     throws SQLException
242     {
243         checkClosed();
244         return (Connection)callMethod(statement, "getConnection", new Class JavaDoc[0], new Object JavaDoc[0]);
245     }
246 }
247
Popular Tags