64
by Marcus Eriksson
add copyright header to all files |
1 |
/*
|
347
by Vladislav Vaintroub
rebranding driver |
2 |
MariaDB Client for Java
|
3 |
||
374
by Vladislav Vaintroub
remove 'All rights reserved' from the copyright notice |
4 |
Copyright (c) 2012 Monty Program Ab.
|
347
by Vladislav Vaintroub
rebranding driver |
5 |
|
6 |
This library is free software; you can redistribute it and/or modify it under
|
|
7 |
the terms of the GNU Lesser General Public License as published by the Free
|
|
8 |
Software Foundation; either version 2.1 of the License, or (at your option)
|
|
9 |
any later version.
|
|
10 |
||
11 |
This library is distributed in the hope that it will be useful, but
|
|
12 |
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
14 |
for more details.
|
|
15 |
||
16 |
You should have received a copy of the GNU Lesser General Public License along
|
|
17 |
with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
|
18 |
||
349
by Vladislav Vaintroub
Fixed typo. |
19 |
This particular MariaDB Client for Java file is work
|
347
by Vladislav Vaintroub
rebranding driver |
20 |
derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
21 |
the following copyright and notice provisions:
|
|
22 |
||
23 |
Copyright (c) 2009-2011, Marcus Eriksson
|
|
24 |
||
25 |
Redistribution and use in source and binary forms, with or without modification,
|
|
26 |
are permitted provided that the following conditions are met:
|
|
27 |
Redistributions of source code must retain the above copyright notice, this list
|
|
28 |
of conditions and the following disclaimer.
|
|
29 |
||
30 |
Redistributions in binary form must reproduce the above copyright notice, this
|
|
31 |
list of conditions and the following disclaimer in the documentation and/or
|
|
32 |
other materials provided with the distribution.
|
|
33 |
||
34 |
Neither the name of the driver nor the names of its contributors may not be
|
|
35 |
used to endorse or promote products derived from this software without specific
|
|
36 |
prior written permission.
|
|
37 |
||
38 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
39 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
40 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
41 |
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
42 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
43 |
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
44 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
45 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
46 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
47 |
OF SUCH DAMAGE.
|
|
48 |
*/
|
|
64
by Marcus Eriksson
add copyright header to all files |
49 |
|
346
by Vladislav Vaintroub
rebranding to mariadb driver |
50 |
package org.mariadb.jdbc; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
51 |
|
346
by Vladislav Vaintroub
rebranding to mariadb driver |
52 |
import org.mariadb.jdbc.internal.SQLExceptionMapper; |
53 |
import org.mariadb.jdbc.internal.common.QueryException; |
|
54 |
import org.mariadb.jdbc.internal.common.Utils; |
|
411
by Vladislav Vaintroub
Small refactoring : remove yet another unnecessary level of abstraction - MySQLQueryFactory. Use MySQLQuery directory |
55 |
import org.mariadb.jdbc.internal.common.query.MySQLQuery; |
346
by Vladislav Vaintroub
rebranding to mariadb driver |
56 |
import org.mariadb.jdbc.internal.common.query.Query; |
57 |
import org.mariadb.jdbc.internal.common.queryresults.ModifyQueryResult; |
|
58 |
import org.mariadb.jdbc.internal.common.queryresults.QueryResult; |
|
59 |
import org.mariadb.jdbc.internal.common.queryresults.ResultSetType; |
|
60 |
import org.mariadb.jdbc.internal.mysql.MySQLProtocol; |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
61 |
|
311
by Vladislav Vaintroub
Statement.cancel() should skip/read off the rest of data on the current connection, until EOF or error packet . Ditto timeout |
62 |
import java.io.IOException; |
502.3.1
by Massimo Siani
Implement load data local infile |
63 |
import java.io.InputStream; |
257
by Vladislav Vaintroub
implement getWarnings(), clearWarnings() |
64 |
import java.sql.*; |
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
65 |
import java.util.*; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
66 |
|
353
by Vladislav Vaintroub
Remove comments, mostly IDE generated, but also wrong and trivial ones |
67 |
|
263
by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX |
68 |
public class MySQLStatement implements Statement { |
111
by Marcus Eriksson
start fixing checkstyle errors |
69 |
/**
|
70 |
* the protocol used to talk to the server.
|
|
71 |
*/
|
|
297
by Vladislav Vaintroub
- Make getObject() use the same datatypes as connector/j does (as documented here : http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-type-conversions.html) |
72 |
private final MySQLProtocol protocol; |
111
by Marcus Eriksson
start fixing checkstyle errors |
73 |
/**
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
74 |
* the Connection object.
|
111
by Marcus Eriksson
start fixing checkstyle errors |
75 |
*/
|
290
by Vladislav Vaintroub
Rework NO_BACKSLASH_ESCAPES - instead of changing sql_mode to remove this option, |
76 |
protected MySQLConnection connection; |
111
by Marcus Eriksson
start fixing checkstyle errors |
77 |
|
78 |
||
79 |
/**
|
|
80 |
* The actual query result.
|
|
81 |
*/
|
|
82 |
private QueryResult queryResult; |
|
83 |
/**
|
|
84 |
* are warnings cleared?
|
|
85 |
*/
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
86 |
private boolean warningsCleared; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
87 |
|
244
by Marcus Eriksson
move executor thread pool to connection - have one timer thread per connection instead of one per statement |
88 |
|
227
by Marcus Eriksson
support for timeouts and cancel query |
89 |
private int queryTimeout; |
269
by Vladislav Vaintroub
support nativeSQL()/JDBC escape sequences |
90 |
private boolean escapeProcessing; |
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
91 |
private int fetchSize; |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
92 |
private int maxRows; |
373
by Vladislav Vaintroub
simplify Statement.close |
93 |
boolean isClosed; |
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
94 |
private static volatile Timer timer; |
95 |
private TimerTask timerTask; |
|
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
96 |
boolean isTimedout; |
476
by Vladislav Vaintroub
CONJ-58 : do not issue "kill query" in Statement.cancel() , if Statement is not being executed. |
97 |
volatile boolean executing; |
98 |
||
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
99 |
List<String> batchQueries; |
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
100 |
Queue<Object> cachedResultSets; |
518
by Massimo Siani
Change TimezoneDaylightSavingTimeTest |
101 |
private boolean isRewriteable = true; |
102 |
private String firstRewrite = null; |
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
103 |
|
470
by Vladislav Vaintroub
use bit flags instead of enums |
104 |
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
105 |
public boolean isStreaming() { |
106 |
return fetchSize == Integer.MIN_VALUE; |
|
107 |
}
|
|
227
by Marcus Eriksson
support for timeouts and cancel query |
108 |
|
111
by Marcus Eriksson
start fixing checkstyle errors |
109 |
/**
|
110 |
* Creates a new Statement.
|
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
111 |
* @param connection the connection to return in getConnection.
|
111
by Marcus Eriksson
start fixing checkstyle errors |
112 |
*/
|
113 |
||
411
by Vladislav Vaintroub
Small refactoring : remove yet another unnecessary level of abstraction - MySQLQueryFactory. Use MySQLQuery directory |
114 |
public MySQLStatement(MySQLConnection connection) { |
115 |
this.protocol = connection.getProtocol(); |
|
111
by Marcus Eriksson
start fixing checkstyle errors |
116 |
this.connection = connection; |
269
by Vladislav Vaintroub
support nativeSQL()/JDBC escape sequences |
117 |
this.escapeProcessing = true; |
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
118 |
cachedResultSets = new LinkedList<Object>(); |
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
119 |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
120 |
}
|
111
by Marcus Eriksson
start fixing checkstyle errors |
121 |
|
122 |
/**
|
|
123 |
* returns the protocol.
|
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
124 |
*
|
111
by Marcus Eriksson
start fixing checkstyle errors |
125 |
* @return the protocol used.
|
126 |
*/
|
|
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
127 |
public MySQLProtocol getProtocol() { |
25
by Marcus Eriksson
reworked parameterized queries (still lots to do...) |
128 |
return protocol; |
129 |
}
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
130 |
|
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
131 |
private static Timer getTimer() { |
132 |
Timer result = timer; |
|
133 |
if (result == null) { |
|
134 |
synchronized(MySQLStatement.class) { |
|
135 |
result = timer; |
|
136 |
if (result == null) { |
|
490
by Vladislav Vaintroub
Use Timer constructor with thread name argument |
137 |
timer = result = new Timer("MariaDB-JDBC-Timer", true); |
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
138 |
}
|
139 |
}
|
|
140 |
}
|
|
141 |
return result; |
|
142 |
}
|
|
143 |
||
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
144 |
// Part of query prolog - setup timeout timer
|
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
145 |
private void setTimerTask() { |
146 |
assert(timerTask == null); |
|
147 |
timerTask = new TimerTask() { |
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
148 |
@Override
|
149 |
public void run() { |
|
150 |
try { |
|
151 |
isTimedout = true; |
|
152 |
protocol.cancelCurrentQuery(); |
|
153 |
} catch (Throwable e) { |
|
154 |
}
|
|
155 |
}
|
|
156 |
};
|
|
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
157 |
getTimer().schedule(timerTask, queryTimeout*1000); |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
158 |
}
|
159 |
||
160 |
// Part of query prolog - check if connection is broken and reconnect
|
|
161 |
private void checkReconnect() throws SQLException { |
|
162 |
if (protocol.shouldReconnect()) { |
|
163 |
try { |
|
164 |
protocol.connect(); |
|
165 |
} catch (QueryException qe) { |
|
166 |
SQLExceptionMapper.throwException(qe, connection, this); |
|
167 |
}
|
|
168 |
} else if (protocol.shouldTryFailback()) { |
|
169 |
try { |
|
170 |
protocol.reconnectToMaster(); |
|
171 |
} catch (Exception e) { |
|
172 |
// Do nothing
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|
|
176 |
||
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
177 |
void executeQueryProlog() throws SQLException{ |
383
by Vladislav Vaintroub
Fix asserton that is thrown if Connection.getWarnings() called after connection is closed. |
178 |
if (isClosed()) { |
179 |
throw new SQLException("execute() is called on closed statement"); |
|
180 |
}
|
|
384
by Vladislav Vaintroub
CONJ-12 - support dumpQueriesOnException=true in JDBC URL. |
181 |
checkReconnect(); |
383
by Vladislav Vaintroub
Fix asserton that is thrown if Connection.getWarnings() called after connection is closed. |
182 |
if (protocol.isClosed()){ |
183 |
throw new SQLException("execute() is called on closed connection"); |
|
184 |
}
|
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
185 |
if (protocol.hasUnreadData()) { |
186 |
throw new SQLException("There is an open result set on the current connection, "+ |
|
187 |
"which must be closed prior to executing a query"); |
|
188 |
}
|
|
189 |
if (protocol.hasMoreResults()) { |
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
190 |
// Skip remaining result sets. CallableStatement might return many of them -
|
191 |
// not only the "select" result sets, but also the "update" results
|
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
192 |
while(getMoreResults(true)) { |
193 |
}
|
|
194 |
}
|
|
337
by Vladislav Vaintroub
implement failover during query and failback to master |
195 |
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
196 |
cachedResultSets.clear(); |
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
197 |
MySQLConnection conn = (MySQLConnection)getConnection(); |
198 |
conn.reenableWarnings(); |
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
199 |
|
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
200 |
try { |
201 |
protocol.setMaxRows(maxRows); |
|
202 |
} catch(QueryException qe) { |
|
313
by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource) |
203 |
SQLExceptionMapper.throwException(qe, connection, this); |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
204 |
}
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
205 |
|
206 |
if (queryTimeout != 0) { |
|
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
207 |
setTimerTask(); |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
208 |
}
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
209 |
}
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
210 |
|
211 |
private void cacheMoreResults() { |
|
212 |
||
213 |
if (isStreaming()) |
|
214 |
return; |
|
215 |
QueryResult saveResult = queryResult; |
|
216 |
for(;;) { |
|
217 |
try { |
|
218 |
if (getMoreResults(false)) { |
|
219 |
cachedResultSets.add(queryResult); |
|
220 |
} else { |
|
221 |
break; |
|
222 |
}
|
|
223 |
} catch(SQLException e) { |
|
224 |
cachedResultSets.add(e); |
|
225 |
break; |
|
226 |
}
|
|
227 |
}
|
|
228 |
queryResult = saveResult; |
|
229 |
}
|
|
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
230 |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
231 |
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
232 |
|
233 |
/*
|
|
384
by Vladislav Vaintroub
CONJ-12 - support dumpQueriesOnException=true in JDBC URL. |
234 |
Reset timeout after query, re-throw SQL exception
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
235 |
*/
|
375
by Vladislav Vaintroub
support dumpQueriesOnException=true in the JDBC URL. |
236 |
private void executeQueryEpilog(QueryException e, Query query) throws SQLException{ |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
237 |
|
376
by Vladislav Vaintroub
CONJ-1 : use a single (static) java.util.Timer and multiple TimerTasks to implement timeouts, rather than multiple Timers, since every java.util.Timer has a background thread attached to it. |
238 |
if (timerTask != null) { |
239 |
timerTask.cancel(); |
|
240 |
timerTask = null; |
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
241 |
}
|
375
by Vladislav Vaintroub
support dumpQueriesOnException=true in the JDBC URL. |
242 |
|
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
243 |
if (isTimedout) { |
244 |
isTimedout = false; |
|
375
by Vladislav Vaintroub
support dumpQueriesOnException=true in the JDBC URL. |
245 |
e = new QueryException("Query timed out", 1317, "JZ0002", e); |
246 |
}
|
|
247 |
||
248 |
if (e == null) |
|
249 |
return; |
|
250 |
||
384
by Vladislav Vaintroub
CONJ-12 - support dumpQueriesOnException=true in JDBC URL. |
251 |
/* Include query into exception message, if dumpQueriesOnException is true,
|
252 |
* or on SQL syntax error (MySQL error code 1064).
|
|
253 |
*
|
|
254 |
* If SQL query is too long, truncate it to reasonable (for exception messages)
|
|
255 |
* length.
|
|
256 |
*/
|
|
257 |
if (protocol.getInfo().getProperty("dumpQueriesOnException", "false").equalsIgnoreCase("true") |
|
258 |
|| e.getErrorCode() == 1064 ) { |
|
259 |
String queryString = query.toString(); |
|
391
by Vladislav Vaintroub
improve several DatabaseMetaData methods : |
260 |
if (queryString.length() > 4096) { |
261 |
queryString = queryString.substring(0, 4096); |
|
384
by Vladislav Vaintroub
CONJ-12 - support dumpQueriesOnException=true in JDBC URL. |
262 |
}
|
391
by Vladislav Vaintroub
improve several DatabaseMetaData methods : |
263 |
e.setMessage(e.getMessage()+ "\nQuery is:\n" + queryString); |
375
by Vladislav Vaintroub
support dumpQueriesOnException=true in the JDBC URL. |
264 |
}
|
265 |
||
474
by Vladislav Vaintroub
CONJ-57 - support preparedStatement.setObject() with java.util.Date |
266 |
SQLExceptionMapper.throwException(e, connection, this); |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
267 |
}
|
15
by Marcus Eriksson
tests and fixes for update, prepared statements etc |
268 |
|
111
by Marcus Eriksson
start fixing checkstyle errors |
269 |
/**
|
270 |
* executes a query.
|
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
271 |
*
|
111
by Marcus Eriksson
start fixing checkstyle errors |
272 |
* @param query the query
|
273 |
* @return true if there was a result set, false otherwise.
|
|
274 |
* @throws SQLException
|
|
275 |
*/
|
|
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
276 |
protected boolean execute(Query query) throws SQLException { |
384
by Vladislav Vaintroub
CONJ-12 - support dumpQueriesOnException=true in JDBC URL. |
277 |
//System.out.println(query);
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
278 |
synchronized (protocol) { |
517
by Massimo Siani
Fix for CONJ-90 |
279 |
if (protocol.activeResult != null) { |
280 |
protocol.activeResult.close(); |
|
281 |
}
|
|
476
by Vladislav Vaintroub
CONJ-58 : do not issue "kill query" in Statement.cancel() , if Statement is not being executed. |
282 |
executing = true; |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
283 |
QueryException exception = null; |
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
284 |
executeQueryProlog(); |
285 |
try { |
|
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
286 |
queryResult = protocol.executeQuery(query, isStreaming()); |
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
287 |
cacheMoreResults(); |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
288 |
return (queryResult.getResultSetType() == ResultSetType.SELECT); |
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
289 |
} catch (QueryException e) { |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
290 |
exception = e; |
291 |
return false; |
|
292 |
} finally { |
|
375
by Vladislav Vaintroub
support dumpQueriesOnException=true in the JDBC URL. |
293 |
executeQueryEpilog(exception, query); |
476
by Vladislav Vaintroub
CONJ-58 : do not issue "kill query" in Statement.cancel() , if Statement is not being executed. |
294 |
executing = false; |
372
by Vladislav Vaintroub
CONJ-1 - Timeout behavior is erratic. |
295 |
}
|
27
by Marcus Eriksson
refactor query handling again... |
296 |
}
|
297 |
}
|
|
111
by Marcus Eriksson
start fixing checkstyle errors |
298 |
|
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
299 |
/**
|
300 |
* executes a select query.
|
|
301 |
*
|
|
302 |
* @param query the query to send to the server
|
|
303 |
* @return a result set
|
|
304 |
* @throws SQLException if something went wrong
|
|
305 |
*/
|
|
306 |
protected ResultSet executeQuery(Query query) throws SQLException { |
|
307 |
if (execute(query)) { |
|
470
by Vladislav Vaintroub
use bit flags instead of enums |
308 |
return getResultSet(); |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
309 |
}
|
310 |
//throw new SQLException("executeQuery() with query '" + query +"' did not return a result set");
|
|
311 |
return MySQLResultSet.EMPTY; |
|
312 |
}
|
|
313 |
||
314 |
/**
|
|
315 |
* Executes an update.
|
|
316 |
*
|
|
317 |
* @param query the update query.
|
|
318 |
* @return update count
|
|
319 |
* @throws SQLException if the query could not be sent to server.
|
|
320 |
*/
|
|
321 |
protected int executeUpdate(Query query) throws SQLException { |
|
322 |
if (execute(query)) |
|
323 |
return 0; |
|
324 |
return getUpdateCount(); |
|
325 |
}
|
|
326 |
||
327 |
private Query stringToQuery(String queryString) throws SQLException { |
|
328 |
if (escapeProcessing) { |
|
290
by Vladislav Vaintroub
Rework NO_BACKSLASH_ESCAPES - instead of changing sql_mode to remove this option, |
329 |
queryString = Utils.nativeSQL(queryString,connection.noBackslashEscapes); |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
330 |
}
|
411
by Vladislav Vaintroub
Small refactoring : remove yet another unnecessary level of abstraction - MySQLQueryFactory. Use MySQLQuery directory |
331 |
return new MySQLQuery(queryString); |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
332 |
}
|
333 |
||
334 |
||
335 |
/**
|
|
336 |
* executes a query.
|
|
337 |
*
|
|
338 |
* @param queryString the query
|
|
339 |
* @return true if there was a result set, false otherwise.
|
|
340 |
* @throws SQLException
|
|
341 |
*/
|
|
342 |
public boolean execute(String queryString) throws SQLException { |
|
343 |
return execute(stringToQuery(queryString)); |
|
344 |
}
|
|
345 |
||
346 |
/**
|
|
347 |
* Executes an update.
|
|
348 |
*
|
|
349 |
* @param queryString the update query.
|
|
350 |
* @return update count
|
|
351 |
* @throws SQLException if the query could not be sent to server.
|
|
352 |
*/
|
|
353 |
public int executeUpdate(String queryString) throws SQLException { |
|
354 |
return executeUpdate(stringToQuery(queryString)); |
|
355 |
}
|
|
356 |
||
357 |
||
358 |
/**
|
|
359 |
* executes a select query.
|
|
360 |
*
|
|
361 |
* @param queryString the query to send to the server
|
|
362 |
* @return a result set
|
|
363 |
* @throws SQLException if something went wrong
|
|
364 |
*/
|
|
365 |
public ResultSet executeQuery(String queryString) throws SQLException { |
|
366 |
return executeQuery(stringToQuery(queryString)); |
|
367 |
}
|
|
368 |
||
104
by Marcus Eriksson
prep stmt generated keys fix |
369 |
|
15
by Marcus Eriksson
tests and fixes for update, prepared statements etc |
370 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
371 |
* Releases this <code>Statement</code> object's database and JDBC resources immediately instead of waiting for this
|
372 |
* to happen when it is automatically closed. It is generally good practice to release resources as soon as you are
|
|
373 |
* finished with them to avoid tying up database resources.
|
|
374 |
* <p/>
|
|
375 |
* Calling the method <code>close</code> on a <code>Statement</code> object that is already closed has no effect.
|
|
376 |
* <p/>
|
|
377 |
* <B>Note:</B>When a <code>Statement</code> object is closed, its current <code>ResultSet</code> object, if one
|
|
378 |
* exists, is also closed.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
379 |
*
|
380 |
* @throws java.sql.SQLException if a database access error occurs
|
|
15
by Marcus Eriksson
tests and fixes for update, prepared statements etc |
381 |
*/
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
382 |
public void close() throws SQLException { |
313
by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource) |
383 |
|
276
by Vladislav Vaintroub
do not try to read outstanding data in MySQLStatement.close(), if streaming is not used (i.e all results is already read off connection) |
384 |
if (queryResult != null) { |
385 |
queryResult.close(); |
|
307.1.3
by Mark Riddoch
Null out cached statements early on when a statement is closed. Attempt to reduce memory overhead |
386 |
queryResult = null; |
276
by Vladislav Vaintroub
do not try to read outstanding data in MySQLStatement.close(), if streaming is not used (i.e all results is already read off connection) |
387 |
}
|
307.1.3
by Mark Riddoch
Null out cached statements early on when a statement is closed. Attempt to reduce memory overhead |
388 |
// No possible future use for the cached results, so these can be cleared
|
389 |
// This makes the cache eligible for garbage collection earlier if the statement is not
|
|
390 |
// immediately garbage collected
|
|
391 |
cachedResultSets.clear(); |
|
314
by Vladislav Vaintroub
After rereading the spec, fix PooledConnection to avoid closing physical connection on Connection.close() |
392 |
if (isStreaming()) { |
393 |
synchronized (protocol) { |
|
394 |
// Skip all outstanding result sets
|
|
395 |
while(getMoreResults(true)) { |
|
396 |
}
|
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
397 |
}
|
270
by Vladislav Vaintroub
Prepare for streaming results sets. Also extend column name to id mapping to allow table.column format |
398 |
}
|
373
by Vladislav Vaintroub
simplify Statement.close |
399 |
isClosed = true; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
400 |
}
|
401 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
402 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
403 |
* Retrieves the maximum number of bytes that can be returned for character and binary column values in a
|
404 |
* <code>ResultSet</code> object produced by this <code>Statement</code> object. This limit applies only to
|
|
405 |
* <code>BINARY</code>, <code>VARBINARY</code>, <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
|
|
406 |
* <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code> and <code>LONGVARCHAR</code> columns. If
|
|
407 |
* the limit is exceeded, the excess data is silently discarded.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
408 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
409 |
* @return the current column size limit for columns storing character and binary values; zero means there is no
|
410 |
* limit
|
|
411 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
412 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
413 |
* @see #setMaxFieldSize
|
414 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
415 |
public int getMaxFieldSize() throws SQLException { |
16
by Marcus Eriksson
initial transaction support and some restructuring |
416 |
return 0; |
417 |
}
|
|
418 |
||
419 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
420 |
* Sets the limit for the maximum number of bytes that can be returned for character and binary column values in a
|
421 |
* <code>ResultSet</code> object produced by this <code>Statement</code> object.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
422 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
423 |
* This limit applies only to <code>BINARY</code>, <code>VARBINARY</code>, <code>LONGVARBINARY</code>,
|
424 |
* <code>CHAR</code>, <code>VARCHAR</code>, <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code> and
|
|
425 |
* <code>LONGVARCHAR</code> fields. If the limit is exceeded, the excess data is silently discarded. For maximum
|
|
426 |
* portability, use values greater than 256.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
427 |
*
|
428 |
* @param max the new column size limit in bytes; zero means there is no limit
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
429 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
430 |
* <code>Statement</code> or the condition max >= 0 is not satisfied
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
431 |
* @see #getMaxFieldSize
|
432 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
433 |
public void setMaxFieldSize(final int max) throws SQLException { |
16
by Marcus Eriksson
initial transaction support and some restructuring |
434 |
//we dont support max field sizes
|
435 |
}
|
|
436 |
||
437 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
438 |
* Retrieves the maximum number of rows that a <code>ResultSet</code> object produced by this <code>Statement</code>
|
439 |
* object can contain. If this limit is exceeded, the excess rows are silently dropped.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
440 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
441 |
* @return the current maximum number of rows for a <code>ResultSet</code> object produced by this
|
442 |
* <code>Statement</code> object; zero means there is no limit
|
|
443 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
444 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
445 |
* @see #setMaxRows
|
446 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
447 |
public int getMaxRows() throws SQLException { |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
448 |
return maxRows; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
449 |
}
|
450 |
||
451 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
452 |
* Sets the limit for the maximum number of rows that any <code>ResultSet</code> object generated by this
|
453 |
* <code>Statement</code> object can contain to the given number. If the limit is exceeded, the excess rows are
|
|
454 |
* silently dropped.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
455 |
*
|
456 |
* @param max the new max rows limit; zero means there is no limit
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
457 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
458 |
* <code>Statement</code> or the condition max >= 0 is not satisfied
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
459 |
* @see #getMaxRows
|
460 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
461 |
public void setMaxRows(final int max) throws SQLException { |
288
by Vladislav Vaintroub
- Implement maxRows limit for a statement. |
462 |
if (max < 0) { |
463 |
throw new SQLException("max rows is negative"); |
|
464 |
}
|
|
465 |
maxRows = max; |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
466 |
}
|
467 |
||
468 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
469 |
* Sets escape processing on or off. If escape scanning is on (the default), the driver will do escape substitution
|
470 |
* before sending the SQL statement to the database.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
471 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
472 |
* Note: Since prepared statements have usually been parsed prior to making this call, disabling escape processing
|
473 |
* for <code>PreparedStatements</code> objects will have no effect.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
474 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
475 |
* @param enable <code>true</code> to enable escape processing; <code>false</code> to disable it
|
476 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
477 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
478 |
*/
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
479 |
public void setEscapeProcessing(final boolean enable) throws SQLException { |
269
by Vladislav Vaintroub
support nativeSQL()/JDBC escape sequences |
480 |
escapeProcessing = enable; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
481 |
}
|
482 |
||
483 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
484 |
* Retrieves the number of seconds the driver will wait for a <code>Statement</code> object to execute. If the limit
|
485 |
* is exceeded, a <code>SQLException</code> is thrown.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
486 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
487 |
* @return the current query timeout limit in seconds; zero means there is no limit
|
488 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
489 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
490 |
* @see #setQueryTimeout
|
491 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
492 |
public int getQueryTimeout() throws SQLException { |
227
by Marcus Eriksson
support for timeouts and cancel query |
493 |
return queryTimeout; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
494 |
}
|
495 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
496 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
497 |
* Sets the number of seconds the driver will wait for a <code>Statement</code> object to execute to the given
|
498 |
* number of seconds. If the limit is exceeded, an <code>SQLException</code> is thrown. A JDBC driver must apply
|
|
499 |
* this limit to the <code>execute</code>, <code>executeQuery</code> and <code>executeUpdate</code> methods. JDBC
|
|
500 |
* driver implementations may also apply this limit to <code>ResultSet</code> methods (consult your driver vendor
|
|
501 |
* documentation for details).
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
502 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
503 |
* @param seconds the new query timeout limit in seconds; zero means there is no limit
|
504 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
505 |
* <code>Statement</code> or the condition seconds >= 0 is not satisfied
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
506 |
* @see #getQueryTimeout
|
507 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
508 |
public void setQueryTimeout(final int seconds) throws SQLException { |
227
by Marcus Eriksson
support for timeouts and cancel query |
509 |
this.queryTimeout = seconds; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
510 |
}
|
511 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
512 |
/**
|
502.3.1
by Massimo Siani
Implement load data local infile |
513 |
* Sets the inputStream that will be used for the next execute that uses
|
514 |
* "LOAD DATA LOCAL INFILE". The name specified as local file/URL will be
|
|
515 |
* ignored.
|
|
516 |
*
|
|
517 |
* @param inputStream
|
|
518 |
*/
|
|
519 |
public void setLocalInfileInputStream(InputStream inputStream) { |
|
520 |
protocol.setLocalInfileInputStream(inputStream); |
|
521 |
}
|
|
522 |
||
523 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
524 |
* Cancels this <code>Statement</code> object if both the DBMS and driver support aborting an SQL statement. This
|
525 |
* method can be used by one thread to cancel a statement that is being executed by another thread.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
526 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
527 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
528 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
529 |
* @throws java.sql.SQLFeatureNotSupportedException
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
530 |
* if the JDBC driver does not support this method
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
531 |
*/
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
532 |
public void cancel() throws SQLException { |
224
by Marcus Eriksson
add cancel to Statement |
533 |
try { |
476
by Vladislav Vaintroub
CONJ-58 : do not issue "kill query" in Statement.cancel() , if Statement is not being executed. |
534 |
if (!executing) { |
535 |
return; |
|
536 |
}
|
|
224
by Marcus Eriksson
add cancel to Statement |
537 |
protocol.cancelCurrentQuery(); |
538 |
} catch (QueryException e) { |
|
313
by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource) |
539 |
SQLExceptionMapper.throwException(e, connection, this); |
540 |
||
224
by Marcus Eriksson
add cancel to Statement |
541 |
}
|
311
by Vladislav Vaintroub
Statement.cancel() should skip/read off the rest of data on the current connection, until EOF or error packet . Ditto timeout |
542 |
catch (IOException e) { |
543 |
// connection gone, query is definitely canceled
|
|
544 |
}
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
545 |
}
|
546 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
547 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
548 |
* Retrieves the first warning reported by calls on this <code>Statement</code> object. Subsequent
|
549 |
* <code>Statement</code> object warnings will be chained to this <code>SQLWarning</code> object.
|
|
550 |
* <p/>
|
|
551 |
* <p>The warning chain is automatically cleared each time a statement is (re)executed. This method may not be
|
|
552 |
* called on a closed <code>Statement</code> object; doing so will cause an <code>SQLException</code> to be thrown.
|
|
553 |
* <p/>
|
|
554 |
* <P><B>Note:</B> If you are processing a <code>ResultSet</code> object, any warnings associated with reads on that
|
|
555 |
* <code>ResultSet</code> object will be chained on it rather than on the <code>Statement</code> object that
|
|
556 |
* produced it.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
557 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
558 |
* @return the first <code>SQLWarning</code> object or <code>null</code> if there are no warnings
|
559 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
560 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
561 |
*/
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
562 |
public SQLWarning getWarnings() throws SQLException { |
257
by Vladislav Vaintroub
implement getWarnings(), clearWarnings() |
563 |
if (!warningsCleared) { |
564 |
return this.connection.getWarnings(); |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
565 |
}
|
566 |
return null; |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
567 |
}
|
568 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
569 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
570 |
* Clears all the warnings reported on this <code>Statement</code> object. After a call to this method, the method
|
571 |
* <code>getWarnings</code> will return <code>null</code> until a new warning is reported for this
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
572 |
* <code>Statement</code> object.
|
573 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
574 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
575 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
576 |
*/
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
577 |
public void clearWarnings() throws SQLException { |
16
by Marcus Eriksson
initial transaction support and some restructuring |
578 |
warningsCleared = true; |
579 |
}
|
|
580 |
||
581 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
582 |
* Sets the SQL cursor name to the given <code>String</code>, which will be used by subsequent
|
583 |
* <code>Statement</code> object <code>execute</code> methods. This name can then be used in SQL positioned update
|
|
584 |
* or delete statements to identify the current row in the <code>ResultSet</code> object generated by this
|
|
585 |
* statement. If the database does not support positioned update/delete, this method is a noop. To insure that a
|
|
586 |
* cursor has the proper isolation level to support updates, the cursor's <code>SELECT</code> statement should have
|
|
587 |
* the form <code>SELECT FOR UPDATE</code>. If <code>FOR UPDATE</code> is not present, positioned updates may
|
|
588 |
* fail.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
589 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
590 |
* <P><B>Note:</B> By definition, the execution of positioned updates and deletes must be done by a different
|
591 |
* <code>Statement</code> object than the one that generated the <code>ResultSet</code> object being used for
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
592 |
* positioning. Also, cursor names must be unique within a connection.
|
593 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
594 |
* @param name the new cursor name, which must be unique within a connection
|
595 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
596 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
597 |
* @throws java.sql.SQLFeatureNotSupportedException
|
598 |
* if the JDBC driver does not support this method
|
|
599 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
600 |
public void setCursorName(final String name) throws SQLException { |
219
by Marcus Eriksson
initial java5 support by Christian Peter |
601 |
throw SQLExceptionMapper.getFeatureNotSupportedException("Cursors are not supported"); |
16
by Marcus Eriksson
initial transaction support and some restructuring |
602 |
}
|
603 |
||
604 |
/**
|
|
605 |
* gets the connection that created this statement
|
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
606 |
*
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
607 |
* @return the connection
|
608 |
* @throws SQLException
|
|
609 |
*/
|
|
610 |
public Connection getConnection() throws SQLException { |
|
44
by Marcus Eriksson
start of command packet refactoring |
611 |
return this.connection; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
612 |
}
|
613 |
||
614 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
615 |
* Moves to this <code>Statement</code> object's next result, deals with any current <code>ResultSet</code>
|
616 |
* object(s) according to the instructions specified by the given flag, and returns <code>true</code> if the next
|
|
617 |
* result is a <code>ResultSet</code> object.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
618 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
619 |
* <P>There are no more results when the following is true: <PRE> // stmt is a Statement object
|
620 |
* ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1)) </PRE>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
621 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
622 |
* @param current one of the following <code>Statement</code> constants indicating what should happen to current
|
623 |
* <code>ResultSet</code> objects obtained using the method <code>getResultSet</code>:
|
|
624 |
* <code>Statement.CLOSE_CURRENT_RESULT</code>, <code>Statement.KEEP_CURRENT_RESULT</code>, or
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
625 |
* <code>Statement.CLOSE_ALL_RESULTS</code>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
626 |
* @return <code>true</code> if the next result is a <code>ResultSet</code> object; <code>false</code> if it is an
|
627 |
* update count or there are no more results
|
|
628 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
629 |
* <code>Statement</code> or the argument supplied is not one of the following:
|
|
630 |
* <code>Statement.CLOSE_CURRENT_RESULT</code>, <code>Statement.KEEP_CURRENT_RESULT</code>
|
|
631 |
* or <code>Statement.CLOSE_ALL_RESULTS</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
632 |
* @throws java.sql.SQLFeatureNotSupportedException
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
633 |
* if <code>DatabaseMetaData.supportsMultipleOpenResults</code> returns
|
634 |
* <code>false</code> and either <code>Statement.KEEP_CURRENT_RESULT</code> or
|
|
635 |
* <code>Statement.CLOSE_ALL_RESULTS</code> are supplied as the argument.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
636 |
* @see #execute
|
637 |
* @since 1.4
|
|
638 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
639 |
public boolean getMoreResults(final int current) throws SQLException { |
250
by Marcus Eriksson
add multi statement support |
640 |
return getMoreResults(); |
16
by Marcus Eriksson
initial transaction support and some restructuring |
641 |
}
|
642 |
||
643 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
644 |
* Retrieves any auto-generated keys created as a result of executing this <code>Statement</code> object. If this
|
645 |
* <code>Statement</code> object did not generate any keys, an empty <code>ResultSet</code> object is returned.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
646 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
647 |
* <p><B>Note:</B>If the columns which represent the auto-generated keys were not specified, the JDBC driver
|
648 |
* implementation will determine the columns which best represent the auto-generated keys.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
649 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
650 |
* @return a <code>ResultSet</code> object containing the auto-generated key(s) generated by the execution of this
|
651 |
* <code>Statement</code> object
|
|
652 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
653 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
654 |
* @throws java.sql.SQLFeatureNotSupportedException
|
655 |
* if the JDBC driver does not support this method
|
|
656 |
* @since 1.4
|
|
657 |
*/
|
|
658 |
public ResultSet getGeneratedKeys() throws SQLException { |
|
142
by Marcus Eriksson
return empty result set if no query executed when asking for generated keys |
659 |
if (queryResult != null && queryResult.getResultSetType() == ResultSetType.MODIFY) { |
435
by Vladislav Vaintroub
CONJ-39 : for multi-row inserts, getGeneratedKeys() will return ResultSet with multiple entries. like ConnectorJ does. |
660 |
long insertId = ((ModifyQueryResult)queryResult).getInsertId(); |
661 |
int updateCount = getUpdateCount(); |
|
662 |
||
663 |
return MySQLResultSet.createGeneratedKeysResultSet(insertId, updateCount, connection); |
|
38
by Marcus Eriksson
major query result handling refactoring |
664 |
}
|
263
by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX |
665 |
return MySQLResultSet.EMPTY; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
666 |
}
|
667 |
||
668 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
669 |
* Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys
|
670 |
* produced by this <code>Statement</code> object should be made available for retrieval. The driver will ignore
|
|
671 |
* the flag if the SQL statement is not an <code>INSERT</code> statement, or an SQL statement able to return
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
672 |
* auto-generated keys (the list of such statements is vendor-specific).
|
673 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
674 |
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>,
|
675 |
* <code>UPDATE</code> or <code>DELETE</code>; or an SQL statement that returns nothing,
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
676 |
* such as a DDL statement.
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
677 |
* @param autoGeneratedKeys a flag indicating whether auto-generated keys should be made available for retrieval;
|
678 |
* one of the following constants: <code>Statement.RETURN_GENERATED_KEYS</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
679 |
* <code>Statement.NO_GENERATED_KEYS</code>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
680 |
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements
|
681 |
* that return nothing
|
|
682 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
683 |
* <code>Statement</code>, the given SQL statement returns a <code>ResultSet</code>
|
|
684 |
* object, or the given constant is not one of those allowed
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
685 |
* @throws java.sql.SQLFeatureNotSupportedException
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
686 |
* if the JDBC driver does not support this method with a constant of
|
687 |
* Statement.RETURN_GENERATED_KEYS
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
688 |
* @since 1.4
|
689 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
690 |
public int executeUpdate(final String sql, final int autoGeneratedKeys) throws SQLException { |
16
by Marcus Eriksson
initial transaction support and some restructuring |
691 |
return executeUpdate(sql); |
692 |
}
|
|
693 |
||
694 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
695 |
* Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array
|
696 |
* should be made available for retrieval. This array contains the indexes of the columns in the target table that
|
|
697 |
* contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL
|
|
698 |
* statement is not an <code>INSERT</code> statement, or an SQL statement able to return auto-generated keys (the
|
|
699 |
* list of such statements is vendor-specific).
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
700 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
701 |
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>,
|
702 |
* <code>UPDATE</code> or <code>DELETE</code>; or an SQL statement that returns nothing, such
|
|
703 |
* as a DDL statement.
|
|
704 |
* @param columnIndexes an array of column indexes indicating the columns that should be returned from the inserted
|
|
705 |
* row
|
|
706 |
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements
|
|
707 |
* that return nothing
|
|
708 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
709 |
* <code>Statement</code>, the SQL statement returns a <code>ResultSet</code> object,
|
|
710 |
* or the second argument supplied to this method is not an <code>int</code> array
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
711 |
* whose elements are valid column indexes
|
712 |
* @throws java.sql.SQLFeatureNotSupportedException
|
|
713 |
* if the JDBC driver does not support this method
|
|
714 |
* @since 1.4
|
|
715 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
716 |
public int executeUpdate(final String sql, final int[] columnIndexes) throws SQLException { |
317
by Vladislav Vaintroub
allow different update() methods with multiple generated values. Rven if it does not work wth MySQL server at all, we cannot stop people complaining we do not support the API. Perhaps they want just to use single generated value, we do not know |
717 |
return executeUpdate(sql); |
16
by Marcus Eriksson
initial transaction support and some restructuring |
718 |
}
|
719 |
||
720 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
721 |
* Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array
|
722 |
* should be made available for retrieval. This array contains the names of the columns in the target table that
|
|
723 |
* contain the auto-generated keys that should be made available. The driver will ignore the array if the SQL
|
|
724 |
* statement is not an <code>INSERT</code> statement, or an SQL statement able to return auto-generated keys (the
|
|
725 |
* list of such statements is vendor-specific).
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
726 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
727 |
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>,
|
728 |
* <code>UPDATE</code> or <code>DELETE</code>; or an SQL statement that returns nothing, such as
|
|
729 |
* a DDL statement.
|
|
730 |
* @param columnNames an array of the names of the columns that should be returned from the inserted row
|
|
731 |
* @return either the row count for <code>INSERT</code>, <code>UPDATE</code>, or <code>DELETE</code> statements, or
|
|
732 |
* 0 for SQL statements that return nothing
|
|
733 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
734 |
* <code>Statement</code>, the SQL statement returns a <code>ResultSet</code> object,
|
|
735 |
* or the second argument supplied to this method is not a <code>String</code> array
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
736 |
* whose elements are valid column names
|
737 |
* @throws java.sql.SQLFeatureNotSupportedException
|
|
738 |
* if the JDBC driver does not support this method
|
|
739 |
* @since 1.4
|
|
740 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
741 |
public int executeUpdate(final String sql, final String[] columnNames) throws SQLException { |
317
by Vladislav Vaintroub
allow different update() methods with multiple generated values. Rven if it does not work wth MySQL server at all, we cannot stop people complaining we do not support the API. Perhaps they want just to use single generated value, we do not know |
742 |
return executeUpdate(sql); |
16
by Marcus Eriksson
initial transaction support and some restructuring |
743 |
}
|
744 |
||
745 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
746 |
* Executes the given SQL statement, which may return multiple results, and signals the driver that any
|
747 |
* auto-generated keys should be made available for retrieval. The driver will ignore this signal if the SQL
|
|
748 |
* statement is not an <code>INSERT</code> statement, or an SQL statement able to return auto-generated keys (the
|
|
749 |
* list of such statements is vendor-specific).
|
|
750 |
* <p/>
|
|
751 |
* In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts.
|
|
752 |
* Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple
|
|
753 |
* results or (2) you are dynamically executing an unknown SQL string.
|
|
754 |
* <p/>
|
|
755 |
* The <code>execute</code> method executes an SQL statement and indicates the form of the first result. You must
|
|
756 |
* then use the methods <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve the result, and
|
|
757 |
* <code>getMoreResults</code> to move to any subsequent result(s).
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
758 |
*
|
759 |
* @param sql any SQL statement
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
760 |
* @param autoGeneratedKeys a constant indicating whether auto-generated keys should be made available for retrieval
|
761 |
* using the method <code>getGeneratedKeys</code>; one of the following constants:
|
|
762 |
* <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>
|
|
763 |
* @return <code>true</code> if the first result is a <code>ResultSet</code> object; <code>false</code> if it is an
|
|
764 |
* update count or there are no results
|
|
765 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
766 |
* <code>Statement</code> or the second parameter supplied to this method is not
|
|
767 |
* <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
768 |
* @throws java.sql.SQLFeatureNotSupportedException
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
769 |
* if the JDBC driver does not support this method with a constant of
|
770 |
* Statement.RETURN_GENERATED_KEYS
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
771 |
* @see #getResultSet
|
772 |
* @see #getUpdateCount
|
|
773 |
* @see #getMoreResults
|
|
774 |
* @see #getGeneratedKeys
|
|
775 |
* @since 1.4
|
|
776 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
777 |
public boolean execute(final String sql, final int autoGeneratedKeys) throws SQLException { |
23
by Marcus Eriksson
ResultSet work |
778 |
return execute(sql); // auto generated keys are always available |
16
by Marcus Eriksson
initial transaction support and some restructuring |
779 |
}
|
780 |
||
781 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
782 |
* Executes the given SQL statement, which may return multiple results, and signals the driver that the
|
783 |
* auto-generated keys indicated in the given array should be made available for retrieval. This array contains the
|
|
784 |
* indexes of the columns in the target table that contain the auto-generated keys that should be made available.
|
|
785 |
* The driver will ignore the array if the SQL statement is not an <code>INSERT</code> statement, or an SQL
|
|
786 |
* statement able to return auto-generated keys (the list of such statements is vendor-specific).
|
|
787 |
* <p/>
|
|
788 |
* Under some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts.
|
|
789 |
* Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple
|
|
790 |
* results or (2) you are dynamically executing an unknown SQL string.
|
|
791 |
* <p/>
|
|
792 |
* The <code>execute</code> method executes an SQL statement and indicates the form of the first result. You must
|
|
793 |
* then use the methods <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve the result, and
|
|
794 |
* <code>getMoreResults</code> to move to any subsequent result(s).
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
795 |
*
|
796 |
* @param sql any SQL statement
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
797 |
* @param columnIndexes an array of the indexes of the columns in the inserted row that should be made available
|
798 |
* for retrieval by a call to the method <code>getGeneratedKeys</code>
|
|
799 |
* @return <code>true</code> if the first result is a <code>ResultSet</code> object; <code>false</code> if it is an
|
|
800 |
* update count or there are no results
|
|
801 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
802 |
* <code>Statement</code> or the elements in the <code>int</code> array passed to this
|
|
803 |
* method are not valid column indexes
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
804 |
* @throws java.sql.SQLFeatureNotSupportedException
|
805 |
* if the JDBC driver does not support this method
|
|
806 |
* @see #getResultSet
|
|
807 |
* @see #getUpdateCount
|
|
808 |
* @see #getMoreResults
|
|
809 |
* @since 1.4
|
|
810 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
811 |
public boolean execute(final String sql, final int[] columnIndexes) throws SQLException { |
317
by Vladislav Vaintroub
allow different update() methods with multiple generated values. Rven if it does not work wth MySQL server at all, we cannot stop people complaining we do not support the API. Perhaps they want just to use single generated value, we do not know |
812 |
return execute(sql); |
16
by Marcus Eriksson
initial transaction support and some restructuring |
813 |
}
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
814 |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
815 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
816 |
* Executes the given SQL statement, which may return multiple results, and signals the driver that the
|
817 |
* auto-generated keys indicated in the given array should be made available for retrieval. This array contains the
|
|
818 |
* names of the columns in the target table that contain the auto-generated keys that should be made available. The
|
|
819 |
* driver will ignore the array if the SQL statement is not an <code>INSERT</code> statement, or an SQL statement
|
|
820 |
* able to return auto-generated keys (the list of such statements is vendor-specific).
|
|
821 |
* <p/>
|
|
822 |
* In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts.
|
|
823 |
* Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple
|
|
824 |
* results or (2) you are dynamically executing an unknown SQL string.
|
|
825 |
* <p/>
|
|
826 |
* The <code>execute</code> method executes an SQL statement and indicates the form of the first result. You must
|
|
827 |
* then use the methods <code>getResultSet</code> or <code>getUpdateCount</code> to retrieve the result, and
|
|
828 |
* <code>getMoreResults</code> to move to any subsequent result(s).
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
829 |
*
|
830 |
* @param sql any SQL statement
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
831 |
* @param columnNames an array of the names of the columns in the inserted row that should be made available for
|
832 |
* retrieval by a call to the method <code>getGeneratedKeys</code>
|
|
833 |
* @return <code>true</code> if the next result is a <code>ResultSet</code> object; <code>false</code> if it is an
|
|
834 |
* update count or there are no more results
|
|
835 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
836 |
* <code>Statement</code> or the elements of the <code>String</code> array passed to
|
|
837 |
* this method are not valid column names
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
838 |
* @throws java.sql.SQLFeatureNotSupportedException
|
839 |
* if the JDBC driver does not support this method
|
|
840 |
* @see #getResultSet
|
|
841 |
* @see #getUpdateCount
|
|
842 |
* @see #getMoreResults
|
|
843 |
* @see #getGeneratedKeys
|
|
844 |
* @since 1.4
|
|
845 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
846 |
public boolean execute(final String sql, final String[] columnNames) throws SQLException { |
317
by Vladislav Vaintroub
allow different update() methods with multiple generated values. Rven if it does not work wth MySQL server at all, we cannot stop people complaining we do not support the API. Perhaps they want just to use single generated value, we do not know |
847 |
return execute(sql); |
16
by Marcus Eriksson
initial transaction support and some restructuring |
848 |
}
|
849 |
||
850 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
851 |
* Retrieves the result set holdability for <code>ResultSet</code> objects generated by this <code>Statement</code>
|
852 |
* object.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
853 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
854 |
* @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
|
855 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
856 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
857 |
* @since 1.4
|
858 |
*/
|
|
859 |
public int getResultSetHoldability() throws SQLException { |
|
23
by Marcus Eriksson
ResultSet work |
860 |
return ResultSet.HOLD_CURSORS_OVER_COMMIT; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
861 |
}
|
862 |
||
863 |
/**
|
|
864 |
* Retrieves whether this <code>Statement</code> object has been closed. A <code>Statement</code> is closed if the
|
|
865 |
* method close has been called on it, or if it is automatically closed.
|
|
866 |
*
|
|
867 |
* @return true if this <code>Statement</code> object is closed; false if it is still open
|
|
868 |
* @throws java.sql.SQLException if a database access error occurs
|
|
869 |
* @since 1.6
|
|
870 |
*/
|
|
871 |
public boolean isClosed() throws SQLException { |
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
872 |
return isClosed; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
873 |
}
|
874 |
||
875 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
876 |
* Requests that a <code>Statement</code> be pooled or not pooled. The value specified is a hint to the statement
|
877 |
* pool implementation indicating whether the applicaiton wants the statement to be pooled. It is up to the
|
|
878 |
* statement pool manager as to whether the hint is used.
|
|
879 |
* <p/>
|
|
880 |
* The poolable value of a statement is applicable to both internal statement caches implemented by the driver and
|
|
881 |
* external statement caches implemented by application servers and other applications.
|
|
882 |
* <p/>
|
|
883 |
* By default, a <code>Statement</code> is not poolable when created, and a <code>PreparedStatement</code> and
|
|
884 |
* <code>CallableStatement</code> are poolable when created.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
885 |
* <p/>
|
886 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
887 |
* @param poolable requests that the statement be pooled if true and that the statement not be pooled if false
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
888 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
889 |
* @throws java.sql.SQLException if this method is called on a closed <code>Statement</code>
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
890 |
* <p/>
|
891 |
* @since 1.6
|
|
892 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
893 |
public void setPoolable(final boolean poolable) throws SQLException { |
44
by Marcus Eriksson
start of command packet refactoring |
894 |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
895 |
}
|
896 |
||
897 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
898 |
* Returns a value indicating whether the <code>Statement</code> is poolable or not.
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
899 |
* <p/>
|
900 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
901 |
* @return <code>true</code> if the <code>Statement</code> is poolable; <code>false</code> otherwise
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
902 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
903 |
* @throws java.sql.SQLException if this method is called on a closed <code>Statement</code>
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
904 |
* <p/>
|
905 |
* @see java.sql.Statement#setPoolable(boolean) setPoolable(boolean)
|
|
906 |
* @since 1.6
|
|
907 |
* <p/>
|
|
908 |
*/
|
|
909 |
public boolean isPoolable() throws SQLException { |
|
39
by Marcus Eriksson
minimize mutability |
910 |
return false; |
16
by Marcus Eriksson
initial transaction support and some restructuring |
911 |
}
|
912 |
||
9
by Marcus Eriksson
add first stmt classes - does not work yet |
913 |
|
914 |
public ResultSet getResultSet() throws SQLException { |
|
395
by Vladislav Vaintroub
CONJ14 - Fix MySQLStatement to return -1 from getUpdateCount() and null from getResultSet() in case there are no more results. |
915 |
if (queryResult == null || queryResult.getResultSetType() != ResultSetType.SELECT) { |
916 |
return null; /* Result is an update count, or there are no more results */ |
|
917 |
}
|
|
487
by Vladislav Vaintroub
CONJ-65 : add new connection parameter serverTimezone, compatible to Connector/J |
918 |
return new MySQLResultSet(queryResult,this,protocol, connection.cal); |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
919 |
}
|
920 |
||
921 |
public int getUpdateCount() throws SQLException { |
|
395
by Vladislav Vaintroub
CONJ14 - Fix MySQLStatement to return -1 from getUpdateCount() and null from getResultSet() in case there are no more results. |
922 |
if (queryResult == null || queryResult.getResultSetType() == ResultSetType.SELECT) { |
923 |
return -1; /* Result comes from SELECT , or there are no more results */ |
|
187
by Marcus Eriksson
fix lots of mysql data type issues - found using tungsten connector test suite |
924 |
}
|
250
by Marcus Eriksson
add multi statement support |
925 |
return (int) ((ModifyQueryResult) queryResult).getUpdateCount(); |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
926 |
}
|
927 |
||
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
928 |
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
929 |
private boolean getMoreResults(boolean streaming) throws SQLException { |
930 |
try { |
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
931 |
synchronized(protocol) { |
932 |
if (queryResult != null) { |
|
933 |
queryResult.close(); |
|
934 |
}
|
|
935 |
||
936 |
queryResult = protocol.getMoreResults(streaming); |
|
937 |
if(queryResult == null) return false; |
|
938 |
warningsCleared = false; |
|
939 |
connection.reenableWarnings(); |
|
940 |
return true; |
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
941 |
}
|
942 |
} catch (QueryException e) { |
|
313
by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource) |
943 |
SQLExceptionMapper.throwException(e, connection, this); |
944 |
return false; |
|
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
945 |
}
|
946 |
}
|
|
947 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
948 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
949 |
* Moves to this <code>Statement</code> object's next result, returns <code>true</code> if it is a
|
950 |
* <code>ResultSet</code> object, and implicitly closes any current <code>ResultSet</code> object(s) obtained with
|
|
951 |
* the method <code>getResultSet</code>.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
952 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
953 |
* <P>There are no more results when the following is true: <PRE> // stmt is a Statement object
|
954 |
* ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1)) </PRE>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
955 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
956 |
* @return <code>true</code> if the next result is a <code>ResultSet</code> object; <code>false</code> if it is an
|
957 |
* update count or there are no more results
|
|
958 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
959 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
960 |
* @see #execute
|
961 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
962 |
public boolean getMoreResults() throws SQLException { |
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
963 |
if (!isStreaming()) { |
964 |
/* return pre-cached result set, if available */
|
|
395
by Vladislav Vaintroub
CONJ14 - Fix MySQLStatement to return -1 from getUpdateCount() and null from getResultSet() in case there are no more results. |
965 |
if(cachedResultSets.isEmpty()) { |
966 |
queryResult = null; |
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
967 |
return false; |
395
by Vladislav Vaintroub
CONJ14 - Fix MySQLStatement to return -1 from getUpdateCount() and null from getResultSet() in case there are no more results. |
968 |
}
|
969 |
||
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
970 |
Object o = cachedResultSets.remove(); |
971 |
if (o instanceof SQLException) |
|
972 |
throw (SQLException)o; |
|
973 |
||
974 |
queryResult = (QueryResult)o; |
|
975 |
return true; |
|
976 |
}
|
|
977 |
return getMoreResults(false); |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
978 |
}
|
979 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
980 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
981 |
* Gives the driver a hint as to the direction in which rows will be processed in <code>ResultSet</code> objects
|
982 |
* created using this <code>Statement</code> object. The default value is <code>ResultSet.FETCH_FORWARD</code>.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
983 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
984 |
* Note that this method sets the default fetch direction for result sets generated by this <code>Statement</code>
|
985 |
* object. Each result set has its own methods for getting and setting its own fetch direction.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
986 |
*
|
987 |
* @param direction the initial direction for processing rows
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
988 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
989 |
* <code>Statement</code> or the given direction is not one of
|
|
990 |
* <code>ResultSet.FETCH_FORWARD</code>, <code>ResultSet.FETCH_REVERSE</code>, or
|
|
991 |
* <code>ResultSet.FETCH_UNKNOWN</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
992 |
* @see #getFetchDirection
|
993 |
* @since 1.2
|
|
994 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
995 |
public void setFetchDirection(final int direction) throws SQLException { |
44
by Marcus Eriksson
start of command packet refactoring |
996 |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
997 |
}
|
998 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
999 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1000 |
* Retrieves the direction for fetching rows from database tables that is the default for result sets generated from
|
1001 |
* this <code>Statement</code> object. If this <code>Statement</code> object has not set a fetch direction by
|
|
1002 |
* calling the method <code>setFetchDirection</code>, the return value is implementation-specific.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1003 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1004 |
* @return the default fetch direction for result sets generated from this <code>Statement</code> object
|
1005 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
1006 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1007 |
* @see #setFetchDirection
|
1008 |
* @since 1.2
|
|
1009 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1010 |
public int getFetchDirection() throws SQLException { |
23
by Marcus Eriksson
ResultSet work |
1011 |
return ResultSet.FETCH_FORWARD; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1012 |
}
|
1013 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
1014 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1015 |
* Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are
|
1016 |
* needed for <code>ResultSet</code> objects genrated by this <code>Statement</code>. If the value specified is
|
|
1017 |
* zero, then the hint is ignored. The default value is zero.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1018 |
*
|
1019 |
* @param rows the number of rows to fetch
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1020 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
1021 |
* <code>Statement</code> or the condition <code>rows >= 0</code> is not satisfied.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1022 |
* @see #getFetchSize
|
1023 |
* @since 1.2
|
|
1024 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1025 |
public void setFetchSize(final int rows) throws SQLException { |
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
1026 |
if (rows < 0 && rows != Integer.MIN_VALUE) |
1027 |
throw new SQLException("invalid fetch size"); |
|
1028 |
this.fetchSize = rows; |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1029 |
}
|
1030 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
1031 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1032 |
* Retrieves the number of result set rows that is the default fetch size for <code>ResultSet</code> objects
|
1033 |
* generated from this <code>Statement</code> object. If this <code>Statement</code> object has not set a fetch size
|
|
1034 |
* by calling the method <code>setFetchSize</code>, the return value is implementation-specific.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1035 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1036 |
* @return the default fetch size for result sets generated from this <code>Statement</code> object
|
1037 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
1038 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1039 |
* @see #setFetchSize
|
1040 |
* @since 1.2
|
|
1041 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1042 |
public int getFetchSize() throws SQLException { |
272
by Vladislav Vaintroub
Streaming result sets are now possible with Statement.setFetchSize(Integer.MIN_VALUE), like in Connector/J |
1043 |
return this.fetchSize; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1044 |
}
|
1045 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
1046 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1047 |
* Retrieves the result set concurrency for <code>ResultSet</code> objects generated by this <code>Statement</code>
|
1048 |
* object.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1049 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1050 |
* @return either <code>ResultSet.CONCUR_READ_ONLY</code> or <code>ResultSet.CONCUR_UPDATABLE</code>
|
1051 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
|
1052 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1053 |
* @since 1.2
|
1054 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1055 |
public int getResultSetConcurrency() throws SQLException { |
23
by Marcus Eriksson
ResultSet work |
1056 |
return ResultSet.CONCUR_READ_ONLY; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1057 |
}
|
1058 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
1059 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1060 |
* Retrieves the result set type for <code>ResultSet</code> objects generated by this <code>Statement</code>
|
1061 |
* object.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1062 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1063 |
* @return one of <code>ResultSet.TYPE_FORWARD_ONLY</code>, <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1064 |
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1065 |
* @throws java.sql.SQLException if a database access error occurs or this method is called on a closed
|
1066 |
* <code>Statement</code>
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1067 |
* @since 1.2
|
1068 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1069 |
public int getResultSetType() throws SQLException { |
23
by Marcus Eriksson
ResultSet work |
1070 |
// TODO: this will change when the async protocol is implemented
|
1071 |
return ResultSet.TYPE_SCROLL_INSENSITIVE; |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1072 |
}
|
1073 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
1074 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1075 |
* Adds the given SQL command to the current list of commmands for this <code>Statement</code> object. The commands
|
1076 |
* in this list can be executed as a batch by calling the method <code>executeBatch</code>.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1077 |
* <p/>
|
1078 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1079 |
* @param sql typically this is a SQL <code>INSERT</code> or <code>UPDATE</code> statement
|
1080 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
1081 |
* <code>Statement</code> or the driver does not support batch updates
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1082 |
* @see #executeBatch
|
1083 |
* @see java.sql.DatabaseMetaData#supportsBatchUpdates
|
|
1084 |
* @since 1.2
|
|
1085 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1086 |
public void addBatch(final String sql) throws SQLException { |
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
1087 |
if (batchQueries == null) { |
1088 |
batchQueries = new ArrayList<String>(); |
|
1089 |
}
|
|
1090 |
batchQueries.add(sql); |
|
518
by Massimo Siani
Change TimezoneDaylightSavingTimeTest |
1091 |
isInsertRewriteable(sql); |
1092 |
}
|
|
1093 |
||
1094 |
/**
|
|
1095 |
* Parses the sql string to understand whether it is compatible with rewritten batches.
|
|
1096 |
* @param sql the sql string
|
|
1097 |
*/
|
|
1098 |
private void isInsertRewriteable(String sql) { |
|
1099 |
if (!isRewriteable) { |
|
1100 |
return; |
|
1101 |
}
|
|
1102 |
int index = getInsertIncipit(sql); |
|
1103 |
if (index == -1) { |
|
1104 |
isRewriteable = false; |
|
1105 |
return; |
|
1106 |
}
|
|
1107 |
if (firstRewrite == null) { |
|
1108 |
firstRewrite = sql.substring(0, index); |
|
1109 |
}
|
|
1110 |
boolean isRewrite = sql.startsWith(firstRewrite); |
|
1111 |
if (isRewrite) { |
|
1112 |
isRewriteable = isRewriteable && true; |
|
1113 |
}
|
|
1114 |
}
|
|
1115 |
||
1116 |
/**
|
|
1117 |
* Parses the input string to understand if it is an INSERT statement.
|
|
1118 |
* Returns the position of the round bracket after the VALUE(S) SQL keyword,
|
|
1119 |
* or -1 if it cannot understand it is an INSERT statement.
|
|
1120 |
* Multiple statements cannot be parsed.
|
|
1121 |
* @param sql the input SQL statement
|
|
1122 |
* @return the position of the round bracket after the VALUE(S) SQL keyword,
|
|
1123 |
* or -1 if it cannot be parsed as an INSERT statement
|
|
1124 |
*/
|
|
1125 |
protected int getInsertIncipit(String sql) { |
|
1126 |
String sqlUpper = sql.toUpperCase(); |
|
1127 |
if (! sqlUpper.startsWith("INSERT") |
|
1128 |
|| sqlUpper.indexOf(";") != -1) { |
|
1129 |
return -1; |
|
1130 |
}
|
|
1131 |
int idx = sqlUpper.indexOf(" VALUE"); |
|
1132 |
int index = sqlUpper.indexOf("(", idx); |
|
1133 |
return index; |
|
1134 |
}
|
|
1135 |
||
1136 |
/**
|
|
1137 |
* If the batch array contains only rewriteable sql strings, returns the rewritten statement.
|
|
1138 |
* @return the rewritten statement
|
|
1139 |
*/
|
|
1140 |
private String rewrittenBatch() { |
|
1141 |
StringBuilder result = null; |
|
1142 |
if(isRewriteable) { |
|
1143 |
result = new StringBuilder(""); |
|
1144 |
result.append(firstRewrite); |
|
1145 |
for (String query : batchQueries) { |
|
1146 |
result.append(query.substring(getInsertIncipit(query))); |
|
1147 |
result.append(","); |
|
1148 |
}
|
|
1149 |
result.deleteCharAt(result.length() - 1); |
|
1150 |
}
|
|
1151 |
return (result == null ? null : result.toString()); |
|
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
1152 |
}
|
1153 |
||
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1154 |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1155 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1156 |
* Empties this <code>Statement</code> object's current list of SQL commands.
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1157 |
* <p/>
|
1158 |
*
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1159 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
1160 |
* <code>Statement</code> or the driver does not support batch updates
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1161 |
* @see #addBatch
|
1162 |
* @see java.sql.DatabaseMetaData#supportsBatchUpdates
|
|
1163 |
* @since 1.2
|
|
1164 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1165 |
public void clearBatch() throws SQLException { |
492
by Georg Richter
Bugfix for CONC-74: executeBatch Nullpointer exception if batchlist is empty |
1166 |
if (batchQueries != null) { |
1167 |
batchQueries.clear(); |
|
1168 |
}
|
|
518
by Massimo Siani
Change TimezoneDaylightSavingTimeTest |
1169 |
firstRewrite = null; |
1170 |
isRewriteable = true; |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1171 |
}
|
1172 |
||
16
by Marcus Eriksson
initial transaction support and some restructuring |
1173 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1174 |
* Submits a batch of commands to the database for execution and if all commands execute successfully, returns an
|
1175 |
* array of update counts. The <code>int</code> elements of the array that is returned are ordered to correspond to
|
|
1176 |
* the commands in the batch, which are ordered according to the order in which they were added to the batch. The
|
|
1177 |
* elements in the array returned by the method <code>executeBatch</code> may be one of the following: <OL> <LI>A
|
|
1178 |
* number greater than or equal to zero -- indicates that the command was processed successfully and is an update
|
|
1179 |
* count giving the number of rows in the database that were affected by the command's execution <LI>A value of
|
|
1180 |
* <code>SUCCESS_NO_INFO</code> -- indicates that the command was processed successfully but that the number of rows
|
|
1181 |
* affected is unknown
|
|
1182 |
* <p/>
|
|
1183 |
* If one of the commands in a batch update fails to execute properly, this method throws a
|
|
1184 |
* <code>BatchUpdateException</code>, and a JDBC driver may or may not continue to process the remaining commands in
|
|
1185 |
* the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to
|
|
1186 |
* process commands or never continuing to process commands. If the driver continues processing after a failure,
|
|
1187 |
* the array returned by the method <code>BatchUpdateException.getUpdateCounts</code> will contain as many elements
|
|
1188 |
* as there are commands in the batch, and at least one of the elements will be the following:
|
|
1189 |
* <p/>
|
|
1190 |
* <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed to execute successfully and
|
|
1191 |
* occurs only if a driver continues to process commands after a command fails </OL>
|
|
1192 |
* <p/>
|
|
1193 |
* The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version
|
|
1194 |
* 1.3 to accommodate the option of continuing to proccess commands in a batch update after a
|
|
1195 |
* <code>BatchUpdateException</code> obejct has been thrown.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1196 |
*
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1197 |
* @return an array of update counts containing one element for each command in the batch. The elements of the
|
1198 |
* array are ordered according to the order in which commands were added to the batch.
|
|
1199 |
* @throws java.sql.SQLException if a database access error occurs, this method is called on a closed
|
|
1200 |
* <code>Statement</code> or the driver does not support batch statements. Throws
|
|
1201 |
* {@link java.sql.BatchUpdateException} (a subclass of <code>SQLException</code>) if
|
|
1202 |
* one of the commands sent to the database fails to execute properly or attempts to
|
|
1203 |
* return a result set.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1204 |
* @see #addBatch
|
1205 |
* @see java.sql.DatabaseMetaData#supportsBatchUpdates
|
|
1206 |
* @since 1.3
|
|
1207 |
*/
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1208 |
public int[] executeBatch() throws SQLException { |
482
by Vladislav Vaintroub
CONJ-62 : Avoid NullPointerException in Statement.executeBatch, in case batch is empty (does not contain any statement yet). |
1209 |
if (batchQueries == null) |
1210 |
return new int[0]; |
|
1211 |
||
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
1212 |
int[] ret = new int[batchQueries.size()]; |
1213 |
int i = 0; |
|
28
by Marcus Eriksson
added non-working batch queries, and resultsetmetadata |
1214 |
try { |
518
by Massimo Siani
Change TimezoneDaylightSavingTimeTest |
1215 |
synchronized (this.protocol) { |
1216 |
if (getProtocol().getInfo().getProperty("rewriteBatchedStatements") != null |
|
1217 |
&& "true".equalsIgnoreCase(getProtocol().getInfo().getProperty("rewriteBatchedStatements"))) { |
|
1218 |
ret = executeBatchAsMultiQueries(); |
|
1219 |
} else { |
|
1220 |
for(; i < batchQueries.size(); i++) { |
|
1221 |
execute(batchQueries.get(i)); |
|
1222 |
int updateCount = getUpdateCount(); |
|
1223 |
if (updateCount == -1) { |
|
1224 |
ret[i] = SUCCESS_NO_INFO; |
|
1225 |
} else { |
|
1226 |
ret[i] = updateCount; |
|
1227 |
}
|
|
1228 |
}
|
|
1229 |
}
|
|
1230 |
}
|
|
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
1231 |
} catch (SQLException sqle) { |
1232 |
throw new BatchUpdateException(sqle.getMessage(), sqle.getSQLState(),Arrays.copyOf(ret, i), sqle); |
|
1233 |
} finally { |
|
1234 |
clearBatch(); |
|
23
by Marcus Eriksson
ResultSet work |
1235 |
}
|
448
by Vladislav Vaintroub
CONJ-47 : Fix executeBatch() methods to throw BatchUpdateException(), as per documentation. |
1236 |
return ret; |
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1237 |
}
|
518
by Massimo Siani
Change TimezoneDaylightSavingTimeTest |
1238 |
|
1239 |
/**
|
|
1240 |
* Builds a new statement which contains the batched Statements and executes it.
|
|
1241 |
* @return an array of update counts containing one element for each command in the batch.
|
|
1242 |
* The elements of the array are ordered according to the order in which commands were added to the batch.
|
|
1243 |
* @throws SQLException
|
|
1244 |
*/
|
|
1245 |
private int[] executeBatchAsMultiQueries() throws SQLException { |
|
1246 |
int i = 0; |
|
1247 |
StringBuilder stringBuilder = new StringBuilder(); |
|
1248 |
String rewrite = rewrittenBatch(); |
|
1249 |
if (rewrite != null) { |
|
1250 |
stringBuilder.append(rewrite); |
|
1251 |
i++; |
|
1252 |
} else { |
|
1253 |
for (; i < batchQueries.size(); i++) { |
|
1254 |
stringBuilder.append(batchQueries.get(i) + ";"); |
|
1255 |
}
|
|
1256 |
}
|
|
1257 |
Statement ps = connection.createStatement(); |
|
1258 |
ps.execute(stringBuilder.toString()); |
|
1259 |
return getUpdateCounts(ps, i); |
|
1260 |
}
|
|
1261 |
/**
|
|
1262 |
* Retrieves the update counts for the batched statements rewritten as
|
|
1263 |
* a multi query. The rewritten statement must have been executed already.
|
|
1264 |
* @param statement the rewritten statement
|
|
1265 |
* @return an array of update counts containing one element for each command in the batch.
|
|
1266 |
* The elements of the array are ordered according to the order in which commands were added to the batch.
|
|
1267 |
* @throws SQLException
|
|
1268 |
*/
|
|
1269 |
protected int[] getUpdateCounts(Statement statement, int size) throws SQLException { |
|
1270 |
int[] result = new int[size]; |
|
1271 |
int updateCount; |
|
1272 |
for (int count=0; count<size; count++) { |
|
1273 |
updateCount = statement.getUpdateCount(); |
|
1274 |
if (updateCount == -1) { |
|
1275 |
result[count] = SUCCESS_NO_INFO; |
|
1276 |
} else { |
|
1277 |
result[count] = updateCount; |
|
1278 |
}
|
|
1279 |
statement.getMoreResults(); |
|
1280 |
}
|
|
1281 |
return result; |
|
1282 |
}
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1283 |
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1284 |
/**
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1285 |
* Returns an object that implements the given interface to allow access to non-standard methods, or standard
|
1286 |
* methods not exposed by the proxy.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1287 |
* <p/>
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1288 |
* If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the
|
1289 |
* receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a
|
|
1290 |
* proxy for the wrapped object. Otherwise return the the result of calling <code>unwrap</code> recursively on the
|
|
1291 |
* wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface,
|
|
1292 |
* then an <code>SQLException</code> is thrown.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1293 |
*
|
1294 |
* @param iface A Class defining an interface that the result must implement.
|
|
1295 |
* @return an object that implements the interface. May be a proxy for the actual implementing object.
|
|
1296 |
* @throws java.sql.SQLException If no object found that implements the interface
|
|
1297 |
* @since 1.6
|
|
1298 |
*/
|
|
502.2.1
by Massimo Siani
Add unwrap and isWrapperFor |
1299 |
@SuppressWarnings("unchecked") |
1300 |
public <T> T unwrap(final Class<T> iface) throws SQLException { |
|
1301 |
try { |
|
1302 |
if (isWrapperFor(iface)) { |
|
1303 |
return (T)this; |
|
1304 |
} else { |
|
1305 |
throw new SQLException("The receiver is not a wrapper and does not implement the interface"); |
|
1306 |
}
|
|
1307 |
} catch (Exception e) { |
|
1308 |
throw new SQLException("The receiver is not a wrapper and does not implement the interface"); |
|
1309 |
}
|
|
1310 |
}
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1311 |
|
1312 |
/**
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1313 |
* Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an
|
1314 |
* object that does. Returns false otherwise. If this implements the interface then return true, else if this is a
|
|
1315 |
* wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped object. If this
|
|
1316 |
* does not implement the interface and is not a wrapper, return false. This method should be implemented as a
|
|
1317 |
* low-cost operation compared to <code>unwrap</code> so that callers can use this method to avoid expensive
|
|
1318 |
* <code>unwrap</code> calls that may fail. If this method returns true then calling <code>unwrap</code> with the
|
|
1319 |
* same argument should succeed.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1320 |
*
|
502.2.2
by Massimo Siani
Javadoc update |
1321 |
* @param interfaceOrWrapper a Class defining an interface.
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1322 |
* @return true if this implements the interface or directly or indirectly wraps an object that does.
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1323 |
* @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper for an object with
|
1324 |
* the given interface.
|
|
16
by Marcus Eriksson
initial transaction support and some restructuring |
1325 |
* @since 1.6
|
1326 |
*/
|
|
502.2.1
by Massimo Siani
Add unwrap and isWrapperFor |
1327 |
public boolean isWrapperFor(final Class<?> interfaceOrWrapper) throws SQLException { |
1328 |
return interfaceOrWrapper.isInstance(this); |
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1329 |
}
|
25
by Marcus Eriksson
reworked parameterized queries (still lots to do...) |
1330 |
|
273
by Vladislav Vaintroub
Cache the full server response in non-streaming mode. |
1331 |
|
111
by Marcus Eriksson
start fixing checkstyle errors |
1332 |
/**
|
1333 |
* returns the query result.
|
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
1334 |
*
|
111
by Marcus Eriksson
start fixing checkstyle errors |
1335 |
* @return the queryresult
|
1336 |
*/
|
|
1337 |
protected QueryResult getQueryResult() { |
|
1338 |
return queryResult; |
|
112
by Marcus Eriksson
merge trond and do some minor cleanups in prepared statement |
1339 |
}
|
1340 |
||
1341 |
/**
|
|
1342 |
* sets the current query result
|
|
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
1343 |
*
|
112
by Marcus Eriksson
merge trond and do some minor cleanups in prepared statement |
1344 |
* @param result
|
1345 |
*/
|
|
155.1.5
by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff |
1346 |
protected void setQueryResult(final QueryResult result) { |
113
by Marcus Eriksson
start using checkstyle and remove ugly code |
1347 |
this.queryResult = result; |
112
by Marcus Eriksson
merge trond and do some minor cleanups in prepared statement |
1348 |
}
|
343
by Vladislav Vaintroub
Add dummy implementation for new JDBC methods in Java7 |
1349 |
|
1350 |
public void closeOnCompletion() throws SQLException { |
|
1351 |
// TODO Auto-generated method stub
|
|
1352 |
||
1353 |
}
|
|
1354 |
||
1355 |
public boolean isCloseOnCompletion() throws SQLException { |
|
1356 |
// TODO Auto-generated method stub
|
|
1357 |
return false; |
|
1358 |
}
|
|
477
by Vladislav Vaintroub
CONJ-61 - provide public method to cleanup after driver unload, to workaround Tomcat's classloading issues. |
1359 |
|
1360 |
public static void unloadDriver() { |
|
1361 |
if (timer != null) |
|
1362 |
timer.cancel(); |
|
1363 |
}
|
|
9
by Marcus Eriksson
add first stmt classes - does not work yet |
1364 |
}
|