~maria-captains/mariadb-java-client/trunk

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;
2 by Marcus Eriksson
add tests and some classes
51
346 by Vladislav Vaintroub
rebranding to mariadb driver
52
import org.mariadb.jdbc.internal.SQLExceptionMapper;
53
import org.mariadb.jdbc.internal.common.*;
54
import org.mariadb.jdbc.internal.common.packet.RawPacket;
55
import org.mariadb.jdbc.internal.common.query.QueryFactory;
56
import org.mariadb.jdbc.internal.mysql.MySQLProtocol;
16 by Marcus Eriksson
initial transaction support and some restructuring
57
257 by Vladislav Vaintroub
implement getWarnings(), clearWarnings()
58
import java.sql.*;
313 by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource)
59
import java.util.List;
60
import java.util.Map;
61
import java.util.Properties;
343 by Vladislav Vaintroub
Add dummy implementation for new JDBC methods in Java7
62
import java.util.concurrent.Executor;
2 by Marcus Eriksson
add tests and some classes
63
353 by Vladislav Vaintroub
Remove comments, mostly IDE generated, but also wrong and trivial ones
64
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
65
public final class MySQLConnection
113 by Marcus Eriksson
start using checkstyle and remove ugly code
66
        implements Connection, ReplicationConnection {
67
    /**
68
     * the protocol to communicate with.
69
     */
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)
70
    private final MySQLProtocol protocol;
113 by Marcus Eriksson
start using checkstyle and remove ugly code
71
    /**
72
     * save point count - to generate good names for the savepoints.
73
     */
17 by Marcus Eriksson
properly handle transactions, add savepoint support and add tests for savepoints
74
    private int savepointCount = 0;
113 by Marcus Eriksson
start using checkstyle and remove ugly code
75
    /**
76
     * the properties for the client.
77
     */
39 by Marcus Eriksson
minimize mutability
78
    private final Properties clientInfoProperties;
113 by Marcus Eriksson
start using checkstyle and remove ugly code
79
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
80
     * a query factory.
113 by Marcus Eriksson
start using checkstyle and remove ugly code
81
     */
40 by Marcus Eriksson
refactor, now the jdbc layer is working 100% against interfaces against the internals
82
    private final QueryFactory queryFactory;
16 by Marcus Eriksson
initial transaction support and some restructuring
83
119 by Marcus Eriksson
findbugs fixes, better api for pluggable batch handlers, remove unsafe publication in asyncpacketfetcher
84
    private ParameterizedBatchHandlerFactory parameterizedBatchHandlerFactory;
116 by Marcus Eriksson
pluggable batch handler - possible to swap out the batch query handler for your own implementation
85
313 by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource)
86
    public MySQLPooledConnection pooledConnection;
87
88
257 by Vladislav Vaintroub
implement getWarnings(), clearWarnings()
89
    private boolean warningsCleared;
290 by Vladislav Vaintroub
Rework NO_BACKSLASH_ESCAPES - instead of changing sql_mode to remove this option,
90
    boolean noBackslashEscapes;
303 by Mark Riddoch
Addition of the NoSchemaPattern to emulate the MySQL Conenctor/J behaviour of getTables and getColumns
91
    boolean noSchemaPattern = false;
257 by Vladislav Vaintroub
implement getWarnings(), clearWarnings()
92
244 by Marcus Eriksson
move executor thread pool to connection - have one timer thread per connection instead of one per statement
93
94
    /**
113 by Marcus Eriksson
start using checkstyle and remove ugly code
95
     * Creates a new connection with a given protocol and query factory.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
96
     *
97
     * @param protocol     the protocol to use.
113 by Marcus Eriksson
start using checkstyle and remove ugly code
98
     * @param queryFactory the query factory to use.
99
     */
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)
100
    private MySQLConnection( MySQLProtocol protocol, QueryFactory queryFactory) {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
101
        this.protocol = protocol;
102
        clientInfoProperties = new Properties();
103
        this.queryFactory = queryFactory;
313 by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource)
104
270 by Vladislav Vaintroub
Prepare for streaming results sets. Also extend column name to id mapping to allow table.column format
105
    }
106
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)
107
    public static MySQLConnection newConnection(MySQLProtocol protocol, QueryFactory queryFactory) throws SQLException {
282 by Vladislav Vaintroub
- Fix error if NO_BACKSLASH_ESCAPES sql_mode is set. Check sql_mode after connecting, and remove NO_BACKSLASH_ESCAPES from it
108
        MySQLConnection connection = new MySQLConnection(protocol, queryFactory);
303 by Mark Riddoch
Addition of the NoSchemaPattern to emulate the MySQL Conenctor/J behaviour of getTables and getColumns
109
        
110
        String value;
111
        if ((value = protocol.getInfo().getProperty("NoSchemaPattern")) != null
370 by Vladislav Vaintroub
support sessionVariables connection URL parameter
112
        		&& value.equalsIgnoreCase("true")) {
303 by Mark Riddoch
Addition of the NoSchemaPattern to emulate the MySQL Conenctor/J behaviour of getTables and getColumns
113
        	connection.noSchemaPattern = true;
114
        }
115
        
370 by Vladislav Vaintroub
support sessionVariables connection URL parameter
116
        boolean fastConnect =  protocol.getInfo().get("fastConnect") != null ;
117
        String sessionVariables = protocol.getInfo().getProperty("sessionVariables");
118
        
119
        if (fastConnect && (sessionVariables == null))
120
        	return connection;
121
        
282 by Vladislav Vaintroub
- Fix error if NO_BACKSLASH_ESCAPES sql_mode is set. Check sql_mode after connecting, and remove NO_BACKSLASH_ESCAPES from it
122
        Statement st = null;
123
        try {
370 by Vladislav Vaintroub
support sessionVariables connection URL parameter
124
    		st = connection.createStatement();        		
125
        	if (sessionVariables != null) {
126
        	  st.executeUpdate("set session " + sessionVariables);
127
        	}
128
        	if (!fastConnect) {
129
        		ResultSet rs = st.executeQuery("select @@sql_mode");
130
        		rs.next();
131
        		String sqlMode = rs.getString(1);
132
        		if (sqlMode.contains("NO_BACKSLASH_ESCAPES")) {
133
        			connection.noBackslashEscapes = true;
134
        		}
135
        	}
282 by Vladislav Vaintroub
- Fix error if NO_BACKSLASH_ESCAPES sql_mode is set. Check sql_mode after connecting, and remove NO_BACKSLASH_ESCAPES from it
136
        } finally {
137
            if (st != null)
138
                st.close();
139
        }
140
        return connection;
141
    }
259 by Vladislav Vaintroub
implement working Blob/Clob
142
313 by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource)
143
113 by Marcus Eriksson
start using checkstyle and remove ugly code
144
    /**
145
     * creates a new statement.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
146
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
147
     * @return a statement
148
     * @throws SQLException if we cannot create the statement.
149
     */
2 by Marcus Eriksson
add tests and some classes
150
    public Statement createStatement() throws SQLException {
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
151
        return new MySQLStatement(protocol, this, queryFactory);
2 by Marcus Eriksson
add tests and some classes
152
    }
153
113 by Marcus Eriksson
start using checkstyle and remove ugly code
154
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
155
     * creates a new prepared statement. Only client side prepared statement emulation right now.
156
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
157
     * @param sql the query.
158
     * @return a prepared statement.
159
     * @throws SQLException if there is a problem preparing the statement.
160
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
161
    public PreparedStatement prepareStatement(final String sql) throws SQLException {
162
        if (parameterizedBatchHandlerFactory == null) {
119 by Marcus Eriksson
findbugs fixes, better api for pluggable batch handlers, remove unsafe publication in asyncpacketfetcher
163
            this.parameterizedBatchHandlerFactory = new DefaultParameterizedBatchHandlerFactory();
164
        }
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
165
        return new MySQLPreparedStatement(protocol,
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
166
                this,
361 by Vladislav Vaintroub
test refactoring, do not strip comments from prepared statements
167
                sql,
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
168
                queryFactory,
361 by Vladislav Vaintroub
test refactoring, do not strip comments from prepared statements
169
                parameterizedBatchHandlerFactory.get(sql, protocol));
2 by Marcus Eriksson
add tests and some classes
170
    }
171
339 by Vladislav Vaintroub
Implement XA interfaces
172
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
173
    public CallableStatement prepareCall(final String sql) throws SQLException {
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
174
       return new MySQLCallableStatement(this, sql);
2 by Marcus Eriksson
add tests and some classes
175
    }
176
361 by Vladislav Vaintroub
test refactoring, do not strip comments from prepared statements
177
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
178
    public String nativeSQL(final String sql) throws SQLException {
290 by Vladislav Vaintroub
Rework NO_BACKSLASH_ESCAPES - instead of changing sql_mode to remove this option,
179
        return Utils.nativeSQL(sql,noBackslashEscapes);
2 by Marcus Eriksson
add tests and some classes
180
    }
181
113 by Marcus Eriksson
start using checkstyle and remove ugly code
182
    /**
183
     * Sets whether this connection is auto commited.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
184
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
185
     * @param autoCommit if it should be auto commited.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
186
     * @throws SQLException if something goes wrong talking to the server.
113 by Marcus Eriksson
start using checkstyle and remove ugly code
187
     */
361 by Vladislav Vaintroub
test refactoring, do not strip comments from prepared statements
188
    public void setAutoCommit(boolean autoCommit) throws SQLException {
174 by Marcus Eriksson
fix for autocommit bug
189
        Statement stmt = createStatement();
361 by Vladislav Vaintroub
test refactoring, do not strip comments from prepared statements
190
        try {
191
            stmt.executeUpdate("set autocommit="+((autoCommit)?"1":"0"));
192
        } finally {
193
            stmt.close();
17 by Marcus Eriksson
properly handle transactions, add savepoint support and add tests for savepoints
194
        }
2 by Marcus Eriksson
add tests and some classes
195
    }
196
113 by Marcus Eriksson
start using checkstyle and remove ugly code
197
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
198
     * returns true if statements on this connection are auto commited.
199
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
200
     * @return true if auto commit is on.
201
     * @throws SQLException
202
     */
2 by Marcus Eriksson
add tests and some classes
203
    public boolean getAutoCommit() throws SQLException {
174 by Marcus Eriksson
fix for autocommit bug
204
        Statement stmt = createStatement();
205
        ResultSet rs = stmt.executeQuery("select @@autocommit");
206
        rs.next();
207
        boolean autocommit = rs.getBoolean(1);
208
        rs.close();
209
        stmt.close();
210
        return autocommit;
2 by Marcus Eriksson
add tests and some classes
211
    }
212
113 by Marcus Eriksson
start using checkstyle and remove ugly code
213
    /**
214
     * sends commit to the server.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
215
     *
216
     * @throws SQLException if there is an error commiting.
113 by Marcus Eriksson
start using checkstyle and remove ugly code
217
     */
2 by Marcus Eriksson
add tests and some classes
218
    public void commit() throws SQLException {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
219
        Statement st = createStatement();
16 by Marcus Eriksson
initial transaction support and some restructuring
220
        try {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
221
            st.execute("COMMIT");
222
        } finally {
223
            st.close();
16 by Marcus Eriksson
initial transaction support and some restructuring
224
        }
2 by Marcus Eriksson
add tests and some classes
225
    }
226
113 by Marcus Eriksson
start using checkstyle and remove ugly code
227
    /**
228
     * rolls back a transaction.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
229
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
230
     * @throws SQLException if there is an error rolling back.
231
     */
2 by Marcus Eriksson
add tests and some classes
232
    public void rollback() throws SQLException {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
233
        Statement st = createStatement();
16 by Marcus Eriksson
initial transaction support and some restructuring
234
        try {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
235
            st.execute("ROLLBACK");
236
        } finally {
237
            st.close();
16 by Marcus Eriksson
initial transaction support and some restructuring
238
        }
2 by Marcus Eriksson
add tests and some classes
239
    }
240
113 by Marcus Eriksson
start using checkstyle and remove ugly code
241
    /**
242
     * close the connection.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
243
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
244
     * @throws SQLException if there is a problem talking to the server.
245
     */
2 by Marcus Eriksson
add tests and some classes
246
    public void close() throws SQLException {
337 by Vladislav Vaintroub
implement failover during query and failback to master
247
        if (pooledConnection != null) {
316 by Vladislav Vaintroub
Rollback current transaction prior to returning physical connection to the pool
248
            if (protocol != null && protocol.inTransaction()) {
249
                /* Rollback transaction prior to returning physical connection to the pool */
250
                rollback();
251
            }
314 by Vladislav Vaintroub
After rereading the spec, fix PooledConnection to avoid closing physical connection on Connection.close()
252
            pooledConnection.fireConnectionClosed();
253
            return;
4 by Marcus Eriksson
work
254
        }
337 by Vladislav Vaintroub
implement failover during query and failback to master
255
        protocol.close();
2 by Marcus Eriksson
add tests and some classes
256
    }
257
4 by Marcus Eriksson
work
258
    /**
113 by Marcus Eriksson
start using checkstyle and remove ugly code
259
     * checks if the connection is closed.
260
     *
4 by Marcus Eriksson
work
261
     * @return true if the connection is closed
262
     * @throws SQLException if the connection cannot be closed.
263
     */
2 by Marcus Eriksson
add tests and some classes
264
    public boolean isClosed() throws SQLException {
4 by Marcus Eriksson
work
265
        return protocol.isClosed();
2 by Marcus Eriksson
add tests and some classes
266
    }
267
113 by Marcus Eriksson
start using checkstyle and remove ugly code
268
    /**
269
     * returns the meta data about the database.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
270
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
271
     * @return meta data about the db.
272
     * @throws SQLException if there is a problem creating the meta data.
273
     */
2 by Marcus Eriksson
add tests and some classes
274
    public DatabaseMetaData getMetaData() throws SQLException {
381 by Vladislav Vaintroub
remove common database metadata. move methods to MySQLDatabaseMetaData. This abstraction was only useful to support drizzle server, and now got obsolete
275
        return new MySQLDatabaseMetaData(this,protocol.getUsername(),
276
        		"jdbc:mysql://" + protocol.getHost()  + ":" + protocol.getPort() + "/" + protocol.getDatabase());
2 by Marcus Eriksson
add tests and some classes
277
    }
278
113 by Marcus Eriksson
start using checkstyle and remove ugly code
279
    /**
280
     * Sets whether this connection is read only.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
281
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
282
     * @param readOnly true if it should be read only.
283
     * @throws SQLException if there is a problem
284
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
285
    public void setReadOnly(final boolean readOnly) throws SQLException {
15 by Marcus Eriksson
tests and fixes for update, prepared statements etc
286
        protocol.setReadonly(readOnly);
2 by Marcus Eriksson
add tests and some classes
287
    }
288
16 by Marcus Eriksson
initial transaction support and some restructuring
289
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
290
     * Retrieves whether this <code>Connection</code> object is in read-only mode.
16 by Marcus Eriksson
initial transaction support and some restructuring
291
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
292
     * @return <code>true</code> if this <code>Connection</code> object is read-only; <code>false</code> otherwise
293
     * @throws java.sql.SQLException SQLException if a database access error occurs or this method is called on a closed
294
     *                               connection
16 by Marcus Eriksson
initial transaction support and some restructuring
295
     */
2 by Marcus Eriksson
add tests and some classes
296
    public boolean isReadOnly() throws SQLException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
297
        return false;
2 by Marcus Eriksson
add tests and some classes
298
    }
299
308 by Vladislav Vaintroub
Correct MySQLconnection.setCatalog() implementation w.r.t quoted identifiers. Use
300
    public static String quoteIdentifier(String s) {
301
      return "`" + s.replaceAll("`","``") + "`";
302
    }
16 by Marcus Eriksson
initial transaction support and some restructuring
303
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
304
     * Sets the given catalog name in order to select a subspace of this <code>Connection</code> object's database in
305
     * which to work.
16 by Marcus Eriksson
initial transaction support and some restructuring
306
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
307
     * If the driver does not support catalogs, it will silently ignore this request.
299 by Mark Riddoch
Add implementation of setCatalog/getCatalog
308
     * 
309
     * MySQL treats catalogs and databases as equivalent
16 by Marcus Eriksson
initial transaction support and some restructuring
310
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
311
     * @param catalog the name of a catalog (subspace in this <code>Connection</code> object's database) in which to
312
     *                work
313
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
314
     * @see #getCatalog
315
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
316
    public void setCatalog(final String catalog) throws SQLException {
308 by Vladislav Vaintroub
Correct MySQLconnection.setCatalog() implementation w.r.t quoted identifiers. Use
317
    	if (catalog == null){
299 by Mark Riddoch
Add implementation of setCatalog/getCatalog
318
    		throw new SQLException("The catalog name may not be null", "XAE05");
319
    	}
308 by Vladislav Vaintroub
Correct MySQLconnection.setCatalog() implementation w.r.t quoted identifiers. Use
320
        Statement st = createStatement();
321
        try {
322
            /* Quote modifiers correctly, with backtick char */
323
            st.execute("USE "+ quoteIdentifier(catalog) );
324
            st.close();
325
        } finally {
326
            st.close();
299 by Mark Riddoch
Add implementation of setCatalog/getCatalog
327
        }
2 by Marcus Eriksson
add tests and some classes
328
    }
329
16 by Marcus Eriksson
initial transaction support and some restructuring
330
    /**
331
     * Retrieves this <code>Connection</code> object's current catalog name.
113 by Marcus Eriksson
start using checkstyle and remove ugly code
332
     * <p/>
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
333
     * catalogs are not supported in drizzle
113 by Marcus Eriksson
start using checkstyle and remove ugly code
334
     * <p/>
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
335
     * TODO: Explain the wrapper interface to be able to change database
336
     *
16 by Marcus Eriksson
initial transaction support and some restructuring
337
     * @return the current catalog name or <code>null</code> if there is none
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
338
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
339
     * @see #setCatalog
340
     */
2 by Marcus Eriksson
add tests and some classes
341
    public String getCatalog() throws SQLException {
299 by Mark Riddoch
Add implementation of setCatalog/getCatalog
342
    	String catalog = null;
343
        Statement st = null;
344
        try {
345
            st = createStatement();
346
            ResultSet rs = st.executeQuery("select database()");
347
            rs.next();
348
            catalog = rs.getString(1);
349
        } finally {
350
            if (st != null)
351
                st.close();
352
        }
353
        return catalog;
2 by Marcus Eriksson
add tests and some classes
354
    }
355
16 by Marcus Eriksson
initial transaction support and some restructuring
356
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
357
     * Attempts to change the transaction isolation level for this <code>Connection</code> object to the one given. The
358
     * constants defined in the interface <code>Connection</code> are the possible transaction isolation levels.
16 by Marcus Eriksson
initial transaction support and some restructuring
359
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
360
     * <B>Note:</B> If this method is called during a transaction, the result is implementation-defined.
16 by Marcus Eriksson
initial transaction support and some restructuring
361
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
362
     * @param level one of the following <code>Connection</code> constants: <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
363
     *              <code>Connection.TRANSACTION_READ_COMMITTED</code>, <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
364
     *              or <code>Connection.TRANSACTION_SERIALIZABLE</code>. (Note that <code>Connection.TRANSACTION_NONE</code>
365
     *              cannot be used because it specifies that transactions are not supported.)
366
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
367
     *                               the given parameter is not one of the <code>Connection</code> constants
16 by Marcus Eriksson
initial transaction support and some restructuring
368
     * @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel
369
     * @see #getTransactionIsolation
370
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
371
    public void setTransactionIsolation(final int level) throws SQLException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
372
        String query = "SET SESSION TRANSACTION ISOLATION LEVEL";
113 by Marcus Eriksson
start using checkstyle and remove ugly code
373
        switch (level) {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
374
            case Connection.TRANSACTION_READ_UNCOMMITTED:
113 by Marcus Eriksson
start using checkstyle and remove ugly code
375
                query += " READ UNCOMMITTED";
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
376
                break;
377
            case Connection.TRANSACTION_READ_COMMITTED:
113 by Marcus Eriksson
start using checkstyle and remove ugly code
378
                query += " READ COMMITTED";
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
379
                break;
380
            case Connection.TRANSACTION_REPEATABLE_READ:
113 by Marcus Eriksson
start using checkstyle and remove ugly code
381
                query += " REPEATABLE READ";
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
382
                break;
383
            case Connection.TRANSACTION_SERIALIZABLE:
113 by Marcus Eriksson
start using checkstyle and remove ugly code
384
                query += " SERIALIZABLE";
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
385
                break;
386
            default:
219 by Marcus Eriksson
initial java5 support by Christian Peter
387
                throw SQLExceptionMapper.getSQLException("Unsupported transaction isolation level");
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
388
        }
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
389
390
        Statement st = createStatement();
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
391
        try {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
392
            st.execute(query);
393
        } finally {
394
            st.close();
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
395
        }
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
396
2 by Marcus Eriksson
add tests and some classes
397
    }
398
16 by Marcus Eriksson
initial transaction support and some restructuring
399
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
400
     * Retrieves this <code>Connection</code> object's current transaction isolation level.
16 by Marcus Eriksson
initial transaction support and some restructuring
401
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
402
     * @return the current transaction isolation level, which will be one of the following constants:
403
     *         <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>, <code>Connection.TRANSACTION_READ_COMMITTED</code>,
404
     *         <code>Connection.TRANSACTION_REPEATABLE_READ</code>, <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
16 by Marcus Eriksson
initial transaction support and some restructuring
405
     *         <code>Connection.TRANSACTION_NONE</code>.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
406
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
407
     * @see #setTransactionIsolation
408
     */
2 by Marcus Eriksson
add tests and some classes
409
    public int getTransactionIsolation() throws SQLException {
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
410
        final Statement stmt = createStatement();
119 by Marcus Eriksson
findbugs fixes, better api for pluggable batch handlers, remove unsafe publication in asyncpacketfetcher
411
        try {
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
412
            final ResultSet rs = stmt.executeQuery("SELECT @@tx_isolation");
119 by Marcus Eriksson
findbugs fixes, better api for pluggable batch handlers, remove unsafe publication in asyncpacketfetcher
413
            rs.next();
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
414
            final String response = rs.getString(1);
119 by Marcus Eriksson
findbugs fixes, better api for pluggable batch handlers, remove unsafe publication in asyncpacketfetcher
415
            if (response.equals("REPEATABLE-READ")) {
416
                return Connection.TRANSACTION_REPEATABLE_READ;
417
            }
418
            if (response.equals("READ-UNCOMMITTED")) {
419
                return Connection.TRANSACTION_READ_UNCOMMITTED;
420
            }
421
            if (response.equals("READ-COMMITTED")) {
422
                return Connection.TRANSACTION_READ_COMMITTED;
423
            }
424
            if (response.equals("SERIALIZABLE")) {
425
                return Connection.TRANSACTION_SERIALIZABLE;
426
            }
427
        } finally {
428
            stmt.close();
429
        }
219 by Marcus Eriksson
initial java5 support by Christian Peter
430
        throw SQLExceptionMapper.getSQLException("Could not get transaction isolation level");
2 by Marcus Eriksson
add tests and some classes
431
    }
432
16 by Marcus Eriksson
initial transaction support and some restructuring
433
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
434
     * Not yet implemented: Protocol needs to store any warnings related to connections
435
     * <p/>
436
     * <p/>
437
     * Retrieves the first warning reported by calls on this <code>Connection</code> object.  If there is more than one
438
     * warning, subsequent warnings will be chained to the first one and can be retrieved by calling the method
439
     * <code>SQLWarning.getNextWarning</code> on the warning that was retrieved previously.
440
     * <p/>
441
     * This method may not be called on a closed connection; doing so will cause an <code>SQLException</code> to be
442
     * thrown.
443
     * <p/>
444
     * <P><B>Note:</B> Subsequent warnings will be chained to this SQLWarning.
16 by Marcus Eriksson
initial transaction support and some restructuring
445
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
446
     * @return the first <code>SQLWarning</code> object or <code>null</code> if there are none
447
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
448
     * @see java.sql.SQLWarning
449
     */
2 by Marcus Eriksson
add tests and some classes
450
    public SQLWarning getWarnings() throws SQLException {
383 by Vladislav Vaintroub
Fix asserton that is thrown if Connection.getWarnings() called after connection is closed.
451
        if (warningsCleared || isClosed()) {
257 by Vladislav Vaintroub
implement getWarnings(), clearWarnings()
452
            return null;
383 by Vladislav Vaintroub
Fix asserton that is thrown if Connection.getWarnings() called after connection is closed.
453
        }
257 by Vladislav Vaintroub
implement getWarnings(), clearWarnings()
454
        Statement st = null;
455
        ResultSet rs = null;
456
        SQLWarning last = null;
457
        SQLWarning first = null;
458
        try {
459
           st = this.createStatement();
460
           rs = st.executeQuery("show warnings");
461
           // returned result set has 'level', 'code' and 'message' columns, in this order.
462
           while(rs.next()) {
463
               int code = rs.getInt(2);
464
               String message = rs.getString(3);
465
               SQLWarning w = new SQLWarning(message, SQLExceptionMapper.mapMySQLCodeToSQLState(code), code);
466
               if (first == null) {
467
                   first = w;
468
                   last = w;
469
               }
470
               else {
471
                   last.setNextWarning(w);
472
                   last = w;
473
               }
474
           }
475
        }
476
        finally {
477
           if (rs != null)
478
               rs.close();
479
            if(st != null)
480
                st.close();
481
        }
482
        return first;
2 by Marcus Eriksson
add tests and some classes
483
    }
484
16 by Marcus Eriksson
initial transaction support and some restructuring
485
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
486
     * Clears all warnings reported for this <code>Connection</code> object. After a call to this method, the method
487
     * <code>getWarnings</code> returns <code>null</code> until a new warning is reported for this
488
     * <code>Connection</code> object.
16 by Marcus Eriksson
initial transaction support and some restructuring
489
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
490
     * @throws java.sql.SQLException SQLException if a database access error occurs or this method is called on a closed
491
     *                               connection
16 by Marcus Eriksson
initial transaction support and some restructuring
492
     */
2 by Marcus Eriksson
add tests and some classes
493
    public void clearWarnings() throws SQLException {
257 by Vladislav Vaintroub
implement getWarnings(), clearWarnings()
494
        warningsCleared = true;
495
    }
496
497
    /**
498
     * Reenable warnings, when next statement is executed
499
     */
500
    public void reenableWarnings() {
501
        warningsCleared = false;
2 by Marcus Eriksson
add tests and some classes
502
    }
503
16 by Marcus Eriksson
initial transaction support and some restructuring
504
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
505
     * Creates a <code>Statement</code> object that will generate <code>ResultSet</code> objects with the given type and
506
     * concurrency. This method is the same as the <code>createStatement</code> method above, but it allows the default
507
     * result set type and concurrency to be overridden. The holdability of the created result sets can be determined by
16 by Marcus Eriksson
initial transaction support and some restructuring
508
     * calling {@link #getHoldability}.
509
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
510
     * @param resultSetType        a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
511
     *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
512
     * @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
16 by Marcus Eriksson
initial transaction support and some restructuring
513
     *                             <code>ResultSet.CONCUR_UPDATABLE</code>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
514
     * @return a new <code>Statement</code> object that will generate <code>ResultSet</code> objects with the given type
515
     *         and concurrency
516
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
517
     *                               the given parameters are not <code>ResultSet</code> constants indicating type and
518
     *                               concurrency
16 by Marcus Eriksson
initial transaction support and some restructuring
519
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
520
    public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException {
50 by Marcus Eriksson
fixes, test additions
521
        // for now resultSetType and resultSetConcurrency are ignored
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
522
        // TODO: fix
523
        return createStatement();
2 by Marcus Eriksson
add tests and some classes
524
    }
525
16 by Marcus Eriksson
initial transaction support and some restructuring
526
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
527
     * Creates a <code>PreparedStatement</code> object that will generate <code>ResultSet</code> objects with the given
528
     * type and concurrency. This method is the same as the <code>prepareStatement</code> method above, but it allows
529
     * the default result set type and concurrency to be overridden. The holdability of the created result sets can be
530
     * determined by calling {@link #getHoldability}.
16 by Marcus Eriksson
initial transaction support and some restructuring
531
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
532
     * @param sql                  a <code>String</code> object that is the SQL statement to be sent to the database;
533
     *                             may contain one or more '?' IN parameters
534
     * @param resultSetType        a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
535
     *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
536
     * @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
16 by Marcus Eriksson
initial transaction support and some restructuring
537
     *                             <code>ResultSet.CONCUR_UPDATABLE</code>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
538
     * @return a new PreparedStatement object containing the pre-compiled SQL statement that will produce
539
     *         <code>ResultSet</code> objects with the given type and concurrency
540
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
541
     *                               the given parameters are not <code>ResultSet</code> constants indicating type and
542
     *                               concurrency
16 by Marcus Eriksson
initial transaction support and some restructuring
543
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
544
    public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
545
            throws SQLException {
50 by Marcus Eriksson
fixes, test additions
546
        // for now resultSetType and resultSetConcurrency are ignored
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
547
        // TODO: fix
548
        return prepareStatement(sql);
2 by Marcus Eriksson
add tests and some classes
549
    }
550
16 by Marcus Eriksson
initial transaction support and some restructuring
551
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
552
     * Creates a <code>CallableStatement</code> object that will generate <code>ResultSet</code> objects with the given
553
     * type and concurrency. This method is the same as the <code>prepareCall</code> method above, but it allows the
554
     * default result set type and concurrency to be overridden. The holdability of the created result sets can be
555
     * determined by calling {@link #getHoldability}.
16 by Marcus Eriksson
initial transaction support and some restructuring
556
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
557
     * @param sql                  a <code>String</code> object that is the SQL statement to be sent to the database;
558
     *                             may contain on or more '?' parameters
559
     * @param resultSetType        a result set type; one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
560
     *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
561
     * @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code> or
16 by Marcus Eriksson
initial transaction support and some restructuring
562
     *                             <code>ResultSet.CONCUR_UPDATABLE</code>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
563
     * @return a new <code>CallableStatement</code> object containing the pre-compiled SQL statement that will produce
564
     *         <code>ResultSet</code> objects with the given type and concurrency
565
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
566
     *                               the given parameters are not <code>ResultSet</code> constants indicating type and
567
     *                               concurrency
16 by Marcus Eriksson
initial transaction support and some restructuring
568
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
569
     *                               if the JDBC driver does not support this method or this method is not supported for
570
     *                               the specified result set type and result set concurrency.
16 by Marcus Eriksson
initial transaction support and some restructuring
571
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
572
    public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException {
287 by Vladislav Vaintroub
- Fix bogus "stored procedures not supported" exception
573
        return new MySQLCallableStatement(this,sql);
2 by Marcus Eriksson
add tests and some classes
574
    }
575
16 by Marcus Eriksson
initial transaction support and some restructuring
576
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
577
     * Retrieves the <code>Map</code> object associated with this <code>Connection</code> object. Unless the application
578
     * has added an entry, the type map returned will be empty.
16 by Marcus Eriksson
initial transaction support and some restructuring
579
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
580
     * @return the <code>java.util.Map</code> object associated with this <code>Connection</code> object
581
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
582
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
583
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
584
     * @see #setTypeMap
585
     * @since 1.2
586
     */
2 by Marcus Eriksson
add tests and some classes
587
    public Map<String, Class<?>> getTypeMap() throws SQLException {
287 by Vladislav Vaintroub
- Fix bogus "stored procedures not supported" exception
588
        return  null;
2 by Marcus Eriksson
add tests and some classes
589
    }
590
16 by Marcus Eriksson
initial transaction support and some restructuring
591
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
592
     * Installs the given <code>TypeMap</code> object as the type map for this <code>Connection</code> object.  The type
593
     * map will be used for the custom mapping of SQL structured types and distinct types.
16 by Marcus Eriksson
initial transaction support and some restructuring
594
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
595
     * @param map the <code>java.util.Map</code> object to install as the replacement for this <code>Connection</code>
16 by Marcus Eriksson
initial transaction support and some restructuring
596
     *            object's default type map
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
597
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
598
     *                               the given parameter is not a <code>java.util.Map</code> object
16 by Marcus Eriksson
initial transaction support and some restructuring
599
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
600
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
601
     * @see #getTypeMap
602
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
603
    public void setTypeMap(final Map<String, Class<?>> map) throws SQLException {
219 by Marcus Eriksson
initial java5 support by Christian Peter
604
        throw SQLExceptionMapper.getFeatureNotSupportedException("Not yet supported");
2 by Marcus Eriksson
add tests and some classes
605
    }
606
16 by Marcus Eriksson
initial transaction support and some restructuring
607
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
608
     * Changes the default holdability of <code>ResultSet</code> objects created using this <code>Connection</code>
609
     * object to the given holdability.  The default holdability of <code>ResultSet</code> objects can be be determined
610
     * by invoking {@link java.sql.DatabaseMetaData#getResultSetHoldability}.
16 by Marcus Eriksson
initial transaction support and some restructuring
611
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
612
     * @param holdability a <code>ResultSet</code> holdability constant; one of <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code>
613
     *                    or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
614
     * @throws java.sql.SQLException if a database access occurs, this method is called on a closed connection, or the
615
     *                               given parameter is not a <code>ResultSet</code> constant indicating holdability
16 by Marcus Eriksson
initial transaction support and some restructuring
616
     * @throws java.sql.SQLFeatureNotSupportedException
617
     *                               if the given holdability is not supported
618
     * @see #getHoldability
619
     * @see java.sql.DatabaseMetaData#getResultSetHoldability
620
     * @see java.sql.ResultSet
621
     * @since 1.4
622
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
623
    public void setHoldability(final int holdability) throws SQLException {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
624
        if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
219 by Marcus Eriksson
initial java5 support by Christian Peter
625
            throw SQLExceptionMapper.getFeatureNotSupportedException("Only holding cursors over commit is supported");
113 by Marcus Eriksson
start using checkstyle and remove ugly code
626
        }
2 by Marcus Eriksson
add tests and some classes
627
    }
628
16 by Marcus Eriksson
initial transaction support and some restructuring
629
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
630
     * Retrieves the current holdability of <code>ResultSet</code> objects created using this <code>Connection</code>
631
     * object.
16 by Marcus Eriksson
initial transaction support and some restructuring
632
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
633
     * @return the holdability, one of <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
16 by Marcus Eriksson
initial transaction support and some restructuring
634
     *         <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
635
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
636
     * @see #setHoldability
637
     * @see java.sql.DatabaseMetaData#getResultSetHoldability
638
     * @see java.sql.ResultSet
639
     * @since 1.4
640
     */
2 by Marcus Eriksson
add tests and some classes
641
    public int getHoldability() throws SQLException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
642
        return ResultSet.HOLD_CURSORS_OVER_COMMIT;
2 by Marcus Eriksson
add tests and some classes
643
    }
644
16 by Marcus Eriksson
initial transaction support and some restructuring
645
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
646
     * Creates an unnamed savepoint in the current transaction and returns the new <code>Savepoint</code> object that
647
     * represents it.
16 by Marcus Eriksson
initial transaction support and some restructuring
648
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
649
     * <p> if setSavepoint is invoked outside of an active transaction, a transaction will be started at this newly
650
     * created savepoint.
16 by Marcus Eriksson
initial transaction support and some restructuring
651
     *
652
     * @return the new <code>Savepoint</code> object
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
653
     * @throws java.sql.SQLException if a database access error occurs, this method is called while participating in a
654
     *                               distributed transaction, this method is called on a closed connection or this
655
     *                               <code>Connection</code> object is currently in auto-commit mode
16 by Marcus Eriksson
initial transaction support and some restructuring
656
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
657
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
658
     * @see java.sql.Savepoint
659
     * @since 1.4
660
     */
2 by Marcus Eriksson
add tests and some classes
661
    public Savepoint setSavepoint() throws SQLException {
17 by Marcus Eriksson
properly handle transactions, add savepoint support and add tests for savepoints
662
        return setSavepoint("unnamed");
2 by Marcus Eriksson
add tests and some classes
663
    }
664
16 by Marcus Eriksson
initial transaction support and some restructuring
665
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
666
     * Creates a savepoint with the given name in the current transaction and returns the new <code>Savepoint</code>
667
     * object that represents it.
16 by Marcus Eriksson
initial transaction support and some restructuring
668
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
669
     * <p> if setSavepoint is invoked outside of an active transaction, a transaction will be started at this newly
670
     * created savepoint.
16 by Marcus Eriksson
initial transaction support and some restructuring
671
     *
672
     * @param name a <code>String</code> containing the name of the savepoint
673
     * @return the new <code>Savepoint</code> object
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
674
     * @throws java.sql.SQLException if a database access error occurs, this method is called while participating in a
675
     *                               distributed transaction, this method is called on a closed connection or this
676
     *                               <code>Connection</code> object is currently in auto-commit mode
16 by Marcus Eriksson
initial transaction support and some restructuring
677
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
678
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
679
     * @see java.sql.Savepoint
680
     * @since 1.4
681
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
682
    public Savepoint setSavepoint(final String name) throws SQLException {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
683
        Savepoint savepoint = new MySQLSavepoint(name, savepointCount++);
684
        Statement st = createStatement();
685
        st.execute("SAVEPOINT " + savepoint.toString());
686
        return savepoint;
17 by Marcus Eriksson
properly handle transactions, add savepoint support and add tests for savepoints
687
2 by Marcus Eriksson
add tests and some classes
688
    }
689
16 by Marcus Eriksson
initial transaction support and some restructuring
690
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
691
     * Undoes all changes made after the given <code>Savepoint</code> object was set.
16 by Marcus Eriksson
initial transaction support and some restructuring
692
     * <p/>
693
     * This method should be used only when auto-commit has been disabled.
694
     *
695
     * @param savepoint the <code>Savepoint</code> object to roll back to
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
696
     * @throws java.sql.SQLException if a database access error occurs, this method is called while participating in a
697
     *                               distributed transaction, this method is called on a closed connection, the
698
     *                               <code>Savepoint</code> object is no longer valid, or this <code>Connection</code>
699
     *                               object is currently in auto-commit mode
16 by Marcus Eriksson
initial transaction support and some restructuring
700
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
701
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
702
     * @see java.sql.Savepoint
703
     * @see #rollback
704
     * @since 1.4
705
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
706
    public void rollback(final Savepoint savepoint) throws SQLException {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
707
       Statement st = createStatement();
708
       st.execute("ROLLBACK TO SAVEPOINT " + savepoint.toString());
709
       st.close();
2 by Marcus Eriksson
add tests and some classes
710
    }
711
16 by Marcus Eriksson
initial transaction support and some restructuring
712
    /**
713
     * Removes the specified <code>Savepoint</code>  and subsequent <code>Savepoint</code> objects from the current
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
714
     * transaction. Any reference to the savepoint after it have been removed will cause an <code>SQLException</code> to
715
     * be thrown.
16 by Marcus Eriksson
initial transaction support and some restructuring
716
     *
717
     * @param savepoint the <code>Savepoint</code> object to be removed
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
718
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
719
     *                               the given <code>Savepoint</code> object is not a valid savepoint in the current
720
     *                               transaction
16 by Marcus Eriksson
initial transaction support and some restructuring
721
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
722
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
723
     * @since 1.4
724
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
725
    public void releaseSavepoint(final Savepoint savepoint) throws SQLException {
309 by Vladislav Vaintroub
removed bunch of Protocol methods (commit/rollback etc), and replaced them with Statement.execute(). Also, fix test suite to work with max_allowed_packet less than 16MB
726
       Statement st = createStatement();
727
       st.execute("RELEASE SAVEPOINT " + savepoint.toString());
728
       st.close();
2 by Marcus Eriksson
add tests and some classes
729
    }
730
16 by Marcus Eriksson
initial transaction support and some restructuring
731
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
732
     * Creates a <code>Statement</code> object that will generate <code>ResultSet</code> objects with the given type,
733
     * concurrency, and holdability. This method is the same as the <code>createStatement</code> method above, but it
734
     * allows the default result set type, concurrency, and holdability to be overridden.
16 by Marcus Eriksson
initial transaction support and some restructuring
735
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
736
     * @param resultSetType        one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
737
     *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
738
     * @param resultSetConcurrency one of the following <code>ResultSet</code> constants: <code>ResultSet.CONCUR_READ_ONLY</code>
739
     *                             or <code>ResultSet.CONCUR_UPDATABLE</code>
740
     * @param resultSetHoldability one of the following <code>ResultSet</code> constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code>
741
     *                             or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
742
     * @return a new <code>Statement</code> object that will generate <code>ResultSet</code> objects with the given
743
     *         type, concurrency, and holdability
744
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
745
     *                               the given parameters are not <code>ResultSet</code> constants indicating type,
746
     *                               concurrency, and holdability
16 by Marcus Eriksson
initial transaction support and some restructuring
747
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
748
     *                               if the JDBC driver does not support this method or this method is not supported for
749
     *                               the specified result set type, result set holdability and result set concurrency.
16 by Marcus Eriksson
initial transaction support and some restructuring
750
     * @see java.sql.ResultSet
751
     * @since 1.4
752
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
753
    public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
754
            throws SQLException {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
755
        if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
219 by Marcus Eriksson
initial java5 support by Christian Peter
756
            throw SQLExceptionMapper.getFeatureNotSupportedException("Only read-only result sets allowed");
113 by Marcus Eriksson
start using checkstyle and remove ugly code
757
        }
758
        if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
219 by Marcus Eriksson
initial java5 support by Christian Peter
759
            throw SQLExceptionMapper.getFeatureNotSupportedException(
760
                        "Cursors are always kept when sending commit (they are only client-side)");
113 by Marcus Eriksson
start using checkstyle and remove ugly code
761
        }
18 by Marcus Eriksson
rework some exception handling and an initial impl of DataSource
762
        return createStatement();
2 by Marcus Eriksson
add tests and some classes
763
    }
764
16 by Marcus Eriksson
initial transaction support and some restructuring
765
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
766
     * Creates a <code>PreparedStatement</code> object that will generate <code>ResultSet</code> objects with the given
767
     * type, concurrency, and holdability.
16 by Marcus Eriksson
initial transaction support and some restructuring
768
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
769
     * This method is the same as the <code>prepareStatement</code> method above, but it allows the default result set
16 by Marcus Eriksson
initial transaction support and some restructuring
770
     * type, concurrency, and holdability to be overridden.
771
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
772
     * @param sql                  a <code>String</code> object that is the SQL statement to be sent to the database;
773
     *                             may contain one or more '?' IN parameters
774
     * @param resultSetType        one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
775
     *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
776
     * @param resultSetConcurrency one of the following <code>ResultSet</code> constants: <code>ResultSet.CONCUR_READ_ONLY</code>
777
     *                             or <code>ResultSet.CONCUR_UPDATABLE</code>
778
     * @param resultSetHoldability one of the following <code>ResultSet</code> constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code>
779
     *                             or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
780
     * @return a new <code>PreparedStatement</code> object, containing the pre-compiled SQL statement, that will
781
     *         generate <code>ResultSet</code> objects with the given type, concurrency, and holdability
782
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
783
     *                               the given parameters are not <code>ResultSet</code> constants indicating type,
784
     *                               concurrency, and holdability
16 by Marcus Eriksson
initial transaction support and some restructuring
785
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
786
     *                               if the JDBC driver does not support this method or this method is not supported for
787
     *                               the specified result set type, result set holdability and result set concurrency.
16 by Marcus Eriksson
initial transaction support and some restructuring
788
     * @see java.sql.ResultSet
789
     * @since 1.4
790
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
791
    public PreparedStatement prepareStatement(final String sql,
792
                                              final int resultSetType,
793
                                              final int resultSetConcurrency,
794
                                              final int resultSetHoldability) throws SQLException {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
795
        if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
219 by Marcus Eriksson
initial java5 support by Christian Peter
796
            throw SQLExceptionMapper.getFeatureNotSupportedException("Only read-only result sets allowed");
113 by Marcus Eriksson
start using checkstyle and remove ugly code
797
        }
798
        if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
219 by Marcus Eriksson
initial java5 support by Christian Peter
799
            throw SQLExceptionMapper.getFeatureNotSupportedException(
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
800
                    "Cursors are always kept when sending commit (they are only client-side)");
113 by Marcus Eriksson
start using checkstyle and remove ugly code
801
        }
18 by Marcus Eriksson
rework some exception handling and an initial impl of DataSource
802
        // resultSetType is ignored since we always are scroll insensitive
803
        return prepareStatement(sql);
2 by Marcus Eriksson
add tests and some classes
804
    }
805
16 by Marcus Eriksson
initial transaction support and some restructuring
806
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
807
     * Creates a <code>CallableStatement</code> object that will generate <code>ResultSet</code> objects with the given
808
     * type and concurrency. This method is the same as the <code>prepareCall</code> method above, but it allows the
809
     * default result set type, result set concurrency type and holdability to be overridden.
16 by Marcus Eriksson
initial transaction support and some restructuring
810
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
811
     * @param sql                  a <code>String</code> object that is the SQL statement to be sent to the database;
812
     *                             may contain on or more '?' parameters
813
     * @param resultSetType        one of the following <code>ResultSet</code> constants: <code>ResultSet.TYPE_FORWARD_ONLY</code>,
814
     *                             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
815
     * @param resultSetConcurrency one of the following <code>ResultSet</code> constants: <code>ResultSet.CONCUR_READ_ONLY</code>
816
     *                             or <code>ResultSet.CONCUR_UPDATABLE</code>
817
     * @param resultSetHoldability one of the following <code>ResultSet</code> constants: <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code>
818
     *                             or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
819
     * @return a new <code>CallableStatement</code> object, containing the pre-compiled SQL statement, that will
820
     *         generate <code>ResultSet</code> objects with the given type, concurrency, and holdability
821
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
822
     *                               the given parameters are not <code>ResultSet</code> constants indicating type,
823
     *                               concurrency, and holdability
16 by Marcus Eriksson
initial transaction support and some restructuring
824
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
825
     *                               if the JDBC driver does not support this method or this method is not supported for
826
     *                               the specified result set type, result set holdability and result set concurrency.
16 by Marcus Eriksson
initial transaction support and some restructuring
827
     * @see java.sql.ResultSet
828
     * @since 1.4
829
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
830
    public CallableStatement prepareCall(final String sql,
831
                                         final int resultSetType,
832
                                         final int resultSetConcurrency,
833
                                         final int resultSetHoldability) throws SQLException {
305 by Vladislav Vaintroub
- Remove checks from prepareStatement(String autogeneratedKeyNames[]), since some people running into exception here when trying to use correct column name
834
        return prepareCall(sql);
2 by Marcus Eriksson
add tests and some classes
835
    }
836
16 by Marcus Eriksson
initial transaction support and some restructuring
837
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
838
     * Creates a default <code>PreparedStatement</code> object that has the capability to retrieve auto-generated keys.
839
     * The given constant tells the driver whether it should make auto-generated keys available for retrieval.  This
840
     * parameter is ignored if the SQL statement is not an <code>INSERT</code> statement, or an SQL statement able to
841
     * return auto-generated keys (the list of such statements is vendor-specific).
842
     * <p/>
843
     * <B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If
844
     * the driver supports precompilation, the method <code>prepareStatement</code> will send the statement to the
845
     * database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be
846
     * sent to the database until the <code>PreparedStatement</code> object is executed.  This has no direct effect on
847
     * users; however, it does affect which methods throw certain SQLExceptions.
848
     * <p/>
849
     * Result sets created using the returned <code>PreparedStatement</code> object will by default be type
850
     * <code>TYPE_FORWARD_ONLY</code> and have a concurrency level of <code>CONCUR_READ_ONLY</code>. The holdability of
851
     * the created result sets can be determined by calling {@link #getHoldability}.
16 by Marcus Eriksson
initial transaction support and some restructuring
852
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
853
     * @param sql               an SQL statement that may contain one or more '?' IN parameter placeholders
854
     * @param autoGeneratedKeys a flag indicating whether auto-generated keys should be returned; one of
855
     *                          <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>
856
     * @return a new <code>PreparedStatement</code> object, containing the pre-compiled SQL statement, that will have
857
     *         the capability of returning auto-generated keys
858
     * @throws java.sql.SQLException if a database access error occurs, this method is called on a closed connection or
859
     *                               the given parameter is not a <code>Statement</code> constant indicating whether
860
     *                               auto-generated keys should be returned
16 by Marcus Eriksson
initial transaction support and some restructuring
861
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
862
     *                               if the JDBC driver does not support this method with a constant of
863
     *                               Statement.RETURN_GENERATED_KEYS
16 by Marcus Eriksson
initial transaction support and some restructuring
864
     * @since 1.4
865
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
866
    public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
18 by Marcus Eriksson
rework some exception handling and an initial impl of DataSource
867
        return prepareStatement(sql);
2 by Marcus Eriksson
add tests and some classes
868
    }
869
16 by Marcus Eriksson
initial transaction support and some restructuring
870
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
871
     * Creates a default <code>PreparedStatement</code> object capable of returning the auto-generated keys designated
872
     * by the given array. This array contains the indexes of the columns in the target table that contain the
873
     * auto-generated keys that should be made available.  The driver will ignore the array if the SQL statement is not
874
     * an <code>INSERT</code> statement, or an SQL statement able to return auto-generated keys (the list of such
875
     * statements is vendor-specific).
876
     * <p/>
877
     * An SQL statement with or without IN parameters can be pre-compiled and stored in a <code>PreparedStatement</code>
878
     * object. This object can then be used to efficiently execute this statement multiple times.
879
     * <p/>
880
     * <B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If
881
     * the driver supports precompilation, the method <code>prepareStatement</code> will send the statement to the
882
     * database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be
883
     * sent to the database until the <code>PreparedStatement</code> object is executed.  This has no direct effect on
884
     * users; however, it does affect which methods throw certain SQLExceptions.
885
     * <p/>
886
     * Result sets created using the returned <code>PreparedStatement</code> object will by default be type
887
     * <code>TYPE_FORWARD_ONLY</code> and have a concurrency level of <code>CONCUR_READ_ONLY</code>. The holdability of
888
     * the created result sets can be determined by calling {@link #getHoldability}.
16 by Marcus Eriksson
initial transaction support and some restructuring
889
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
890
     * @param sql           an SQL statement that may contain one or more '?' IN parameter placeholders
891
     * @param columnIndexes an array of column indexes indicating the columns that should be returned from the inserted
892
     *                      row or rows
893
     * @return a new <code>PreparedStatement</code> object, containing the pre-compiled statement, that is capable of
894
     *         returning the auto-generated keys designated by the given array of column indexes
895
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
896
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
897
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
898
     * @since 1.4
899
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
900
    public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) throws SQLException {
305 by Vladislav Vaintroub
- Remove checks from prepareStatement(String autogeneratedKeyNames[]), since some people running into exception here when trying to use correct column name
901
        return prepareStatement(sql);
2 by Marcus Eriksson
add tests and some classes
902
    }
903
16 by Marcus Eriksson
initial transaction support and some restructuring
904
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
905
     * Creates a default <code>PreparedStatement</code> object capable of returning the auto-generated keys designated
906
     * by the given array. This array contains the names of the columns in the target table that contain the
907
     * auto-generated keys that should be returned. The driver will ignore the array if the SQL statement is not an
908
     * <code>INSERT</code> statement, or an SQL statement able to return auto-generated keys (the list of such
909
     * statements is vendor-specific).
910
     * <p/>
911
     * An SQL statement with or without IN parameters can be pre-compiled and stored in a <code>PreparedStatement</code>
912
     * object. This object can then be used to efficiently execute this statement multiple times.
913
     * <p/>
914
     * <B>Note:</B> This method is optimized for handling parametric SQL statements that benefit from precompilation. If
915
     * the driver supports precompilation, the method <code>prepareStatement</code> will send the statement to the
916
     * database for precompilation. Some drivers may not support precompilation. In this case, the statement may not be
917
     * sent to the database until the <code>PreparedStatement</code> object is executed.  This has no direct effect on
918
     * users; however, it does affect which methods throw certain SQLExceptions.
919
     * <p/>
920
     * Result sets created using the returned <code>PreparedStatement</code> object will by default be type
921
     * <code>TYPE_FORWARD_ONLY</code> and have a concurrency level of <code>CONCUR_READ_ONLY</code>. The holdability of
922
     * the created result sets can be determined by calling {@link #getHoldability}.
16 by Marcus Eriksson
initial transaction support and some restructuring
923
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
924
     * @param sql         an SQL statement that may contain one or more '?' IN parameter placeholders
925
     * @param columnNames an array of column names indicating the columns that should be returned from the inserted row
926
     *                    or rows
927
     * @return a new <code>PreparedStatement</code> object, containing the pre-compiled statement, that is capable of
928
     *         returning the auto-generated keys designated by the given array of column names
929
     * @throws java.sql.SQLException if a database access error occurs or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
930
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
931
     *                               if the JDBC driver does not support this method
16 by Marcus Eriksson
initial transaction support and some restructuring
932
     * @since 1.4
933
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
934
    public PreparedStatement prepareStatement(final String sql, final String[] columnNames) throws SQLException {
306 by Vladislav Vaintroub
Remove checks and exception from prepareStatement(final String sql, final String[] columnNames), really now
935
        return prepareStatement(sql);
2 by Marcus Eriksson
add tests and some classes
936
    }
5 by Marcus Eriksson
handle greeting packet from drizzled
937
16 by Marcus Eriksson
initial transaction support and some restructuring
938
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
939
     * Constructs an object that implements the <code>Clob</code> interface. The object returned initially contains no
940
     * data.  The <code>setAsciiStream</code>, <code>setCharacterStream</code> and <code>setString</code> methods of the
941
     * <code>Clob</code> interface may be used to add data to the <code>Clob</code>.
16 by Marcus Eriksson
initial transaction support and some restructuring
942
     *
943
     * @return An object that implements the <code>Clob</code> interface
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
944
     * @throws java.sql.SQLException if an object that implements the <code>Clob</code> interface can not be
945
     *                               constructed, this method is called on a closed connection or a database access
946
     *                               error occurs.
16 by Marcus Eriksson
initial transaction support and some restructuring
947
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
948
     *                               if the JDBC driver does not support this data type
16 by Marcus Eriksson
initial transaction support and some restructuring
949
     * @since 1.6
950
     */
5 by Marcus Eriksson
handle greeting packet from drizzled
951
    public Clob createClob() throws SQLException {
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
952
        return new MySQLClob();
5 by Marcus Eriksson
handle greeting packet from drizzled
953
    }
954
16 by Marcus Eriksson
initial transaction support and some restructuring
955
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
956
     * Constructs an object that implements the <code>Blob</code> interface. The object returned initially contains no
957
     * data.  The <code>setBinaryStream</code> and <code>setBytes</code> methods of the <code>Blob</code> interface may
958
     * be used to add data to the <code>Blob</code>.
16 by Marcus Eriksson
initial transaction support and some restructuring
959
     *
960
     * @return An object that implements the <code>Blob</code> interface
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
961
     * @throws java.sql.SQLException if an object that implements the <code>Blob</code> interface can not be
962
     *                               constructed, this method is called on a closed connection or a database access
963
     *                               error occurs.
16 by Marcus Eriksson
initial transaction support and some restructuring
964
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
965
     *                               if the JDBC driver does not support this data type
16 by Marcus Eriksson
initial transaction support and some restructuring
966
     * @since 1.6
967
     */
5 by Marcus Eriksson
handle greeting packet from drizzled
968
    public Blob createBlob() throws SQLException {
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
969
        return new MySQLBlob();
5 by Marcus Eriksson
handle greeting packet from drizzled
970
    }
971
16 by Marcus Eriksson
initial transaction support and some restructuring
972
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
973
     * Constructs an object that implements the <code>NClob</code> interface. The object returned initially contains no
974
     * data.  The <code>setAsciiStream</code>, <code>setCharacterStream</code> and <code>setString</code> methods of the
975
     * <code>NClob</code> interface may be used to add data to the <code>NClob</code>.
16 by Marcus Eriksson
initial transaction support and some restructuring
976
     *
977
     * @return An object that implements the <code>NClob</code> interface
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
978
     * @throws java.sql.SQLException if an object that implements the <code>NClob</code> interface can not be
979
     *                               constructed, this method is called on a closed connection or a database access
980
     *                               error occurs.
16 by Marcus Eriksson
initial transaction support and some restructuring
981
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
982
     *                               if the JDBC driver does not support this data type
16 by Marcus Eriksson
initial transaction support and some restructuring
983
     * @since 1.6
984
     */
219 by Marcus Eriksson
initial java5 support by Christian Peter
985
    public java.sql.NClob createNClob() throws SQLException {
263 by Vladislav Vaintroub
Branding : rename package to have have skysql instead of drizzle, rename classes from DrizzleXXX to MySQLXXX
986
        return new MySQLClob();
5 by Marcus Eriksson
handle greeting packet from drizzled
987
    }
988
16 by Marcus Eriksson
initial transaction support and some restructuring
989
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
990
     * Constructs an object that implements the <code>SQLXML</code> interface. The object returned initially contains no
991
     * data. The <code>createXmlStreamWriter</code> object and <code>setString</code> method of the <code>SQLXML</code>
992
     * interface may be used to add data to the <code>SQLXML</code> object.
16 by Marcus Eriksson
initial transaction support and some restructuring
993
     *
994
     * @return An object that implements the <code>SQLXML</code> interface
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
995
     * @throws java.sql.SQLException if an object that implements the <code>SQLXML</code> interface can not be
996
     *                               constructed, this method is called on a closed connection or a database access
997
     *                               error occurs.
16 by Marcus Eriksson
initial transaction support and some restructuring
998
     * @throws java.sql.SQLFeatureNotSupportedException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
999
     *                               if the JDBC driver does not support this data type
16 by Marcus Eriksson
initial transaction support and some restructuring
1000
     * @since 1.6
1001
     */
219 by Marcus Eriksson
initial java5 support by Christian Peter
1002
    public java.sql.SQLXML createSQLXML() throws SQLException {
1003
        throw SQLExceptionMapper.getFeatureNotSupportedException("Not supported");
5 by Marcus Eriksson
handle greeting packet from drizzled
1004
    }
1005
16 by Marcus Eriksson
initial transaction support and some restructuring
1006
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1007
     * Returns true if the connection has not been closed and is still valid. The driver shall submit a query on the
1008
     * connection or use some other mechanism that positively verifies the connection is still valid when this method is
1009
     * called.
16 by Marcus Eriksson
initial transaction support and some restructuring
1010
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1011
     * The query submitted by the driver to validate the connection shall be executed in the context of the current
1012
     * transaction.
16 by Marcus Eriksson
initial transaction support and some restructuring
1013
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1014
     * @param timeout -             The time in seconds to wait for the database operation used to validate the
1015
     *                connection to complete.  If the timeout period expires before the operation completes, this method
1016
     *                returns false.  A value of 0 indicates a timeout is not applied to the database operation.
16 by Marcus Eriksson
initial transaction support and some restructuring
1017
     *                <p/>
1018
     * @return true if the connection is valid, false otherwise
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1019
     * @throws java.sql.SQLException if the value supplied for <code>timeout</code> is less then 0
16 by Marcus Eriksson
initial transaction support and some restructuring
1020
     * @see java.sql.DatabaseMetaData#getClientInfoProperties
1021
     * @since 1.6
1022
     *        <p/>
1023
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1024
    public boolean isValid(final int timeout) throws SQLException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1025
        try {
1026
            return protocol.ping();
1027
        } catch (QueryException e) {
313 by Vladislav Vaintroub
implement PooledConnection and ConnectionPoolDataSource (implemented in MySQLDataSource)
1028
            SQLExceptionMapper.throwException(e, this, null);
1029
            return false;
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1030
        }
5 by Marcus Eriksson
handle greeting packet from drizzled
1031
    }
1032
16 by Marcus Eriksson
initial transaction support and some restructuring
1033
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1034
     * Sets the value of the client info property specified by name to the value specified by value.
1035
     * <p/>
1036
     * Applications may use the <code>DatabaseMetaData.getClientInfoProperties</code> method to determine the client
1037
     * info properties supported by the driver and the maximum length that may be specified for each property.
1038
     * <p/>
1039
     * The driver stores the value specified in a suitable location in the database.  For example in a special register,
1040
     * session parameter, or system table column.  For efficiency the driver may defer setting the value in the database
1041
     * until the next time a statement is executed or prepared.  Other than storing the client information in the
1042
     * appropriate place in the database, these methods shall not alter the behavior of the connection in anyway.  The
1043
     * values supplied to these methods are used for accounting, diagnostics and debugging purposes only.
1044
     * <p/>
1045
     * The driver shall generate a warning if the client info name specified is not recognized by the driver.
1046
     * <p/>
1047
     * If the value specified to this method is greater than the maximum length for the property the driver may either
1048
     * truncate the value and generate a warning or generate a <code>SQLClientInfoException</code>.  If the driver
1049
     * generates a <code>SQLClientInfoException</code>, the value specified was not set on the connection.
1050
     * <p/>
1051
     * The following are standard client info properties.  Drivers are not required to support these properties however
1052
     * if the driver supports a client info property that can be described by one of the standard properties, the
1053
     * standard property name should be used.
1054
     * <p/>
1055
     * <ul> <li>ApplicationName  -       The name of the application currently utilizing the connection</li>
1056
     * <li>ClientUser               -       The name of the user that the application using the connection is performing
1057
     * work for.  This may not be the same as the user name that was used in establishing the connection.</li>
1058
     * <li>ClientHostname   -       The hostname of the computer the application using the connection is running
1059
     * on.</li> </ul>
16 by Marcus Eriksson
initial transaction support and some restructuring
1060
     * <p/>
1061
     *
1062
     * @param name  The name of the client info property to set
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1063
     * @param value The value to set the client info property to.  If the value is null, the current value of the
1064
     *              specified property is cleared.
16 by Marcus Eriksson
initial transaction support and some restructuring
1065
     *              <p/>
1066
     * @throws java.sql.SQLClientInfoException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1067
     *          if the database server returns an error while setting the client info value on the database server or
1068
     *          this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
1069
     *          <p/>
1070
     * @since 1.6
1071
     */
219 by Marcus Eriksson
initial java5 support by Christian Peter
1072
    public void setClientInfo(final String name, final String value) throws java.sql.SQLClientInfoException {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1073
        this.clientInfoProperties.setProperty(name, value);
5 by Marcus Eriksson
handle greeting packet from drizzled
1074
    }
1075
16 by Marcus Eriksson
initial transaction support and some restructuring
1076
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1077
     * Sets the value of the connection's client info properties.  The <code>Properties</code> object contains the names
1078
     * and values of the client info properties to be set.  The set of client info properties contained in the
1079
     * properties list replaces the current set of client info properties on the connection.  If a property that is
1080
     * currently set on the connection is not present in the properties list, that property is cleared.  Specifying an
1081
     * empty properties list will clear all of the properties on the connection.  See <code>setClientInfo (String,
1082
     * String)</code> for more information.
16 by Marcus Eriksson
initial transaction support and some restructuring
1083
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1084
     * If an error occurs in setting any of the client info properties, a <code>SQLClientInfoException</code> is thrown.
1085
     * The <code>SQLClientInfoException</code> contains information indicating which client info properties were not
1086
     * set. The state of the client information is unknown because some databases do not allow multiple client info
1087
     * properties to be set atomically.  For those databases, one or more properties may have been set before the error
1088
     * occurred.
16 by Marcus Eriksson
initial transaction support and some restructuring
1089
     * <p/>
1090
     *
1091
     * @param properties the list of client info properties to set
1092
     *                   <p/>
1093
     * @throws java.sql.SQLClientInfoException
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1094
     *          if the database server returns an error while setting the clientInfo values on the database server or
1095
     *          this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
1096
     *          <p/>
1097
     * @see java.sql.Connection#setClientInfo(String, String) setClientInfo(String, String)
1098
     * @since 1.6
1099
     *        <p/>
1100
     */
219 by Marcus Eriksson
initial java5 support by Christian Peter
1101
    public void setClientInfo(final Properties properties) throws java.sql.SQLClientInfoException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1102
        // TODO: actually use these!
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1103
        for (final String key : properties.stringPropertyNames()) {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1104
            this.clientInfoProperties.setProperty(key, properties.getProperty(key));
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1105
        }
5 by Marcus Eriksson
handle greeting packet from drizzled
1106
    }
1107
16 by Marcus Eriksson
initial transaction support and some restructuring
1108
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1109
     * Returns the value of the client info property specified by name.  This method may return null if the specified
1110
     * client info property has not been set and does not have a default value.  This method will also return null if
1111
     * the specified client info property name is not supported by the driver.
16 by Marcus Eriksson
initial transaction support and some restructuring
1112
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1113
     * Applications may use the <code>DatabaseMetaData.getClientInfoProperties</code> method to determine the client
1114
     * info properties supported by the driver.
16 by Marcus Eriksson
initial transaction support and some restructuring
1115
     * <p/>
1116
     *
1117
     * @param name The name of the client info property to retrieve
1118
     *             <p/>
1119
     * @return The value of the client info property specified
1120
     *         <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1121
     * @throws java.sql.SQLException if the database server returns an error when fetching the client info value from
1122
     *                               the database or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
1123
     *                               <p/>
1124
     * @see java.sql.DatabaseMetaData#getClientInfoProperties
1125
     * @since 1.6
1126
     *        <p/>
1127
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1128
    public String getClientInfo(final String name) throws SQLException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1129
        return clientInfoProperties.getProperty(name);
5 by Marcus Eriksson
handle greeting packet from drizzled
1130
    }
1131
16 by Marcus Eriksson
initial transaction support and some restructuring
1132
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1133
     * Returns a list containing the name and current value of each client info property supported by the driver.  The
1134
     * value of a client info property may be null if the property has not been set and does not have a default value.
16 by Marcus Eriksson
initial transaction support and some restructuring
1135
     * <p/>
1136
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1137
     * @return A <code>Properties</code> object that contains the name and current value of each of the client info
1138
     *         properties supported by the driver.
16 by Marcus Eriksson
initial transaction support and some restructuring
1139
     *         <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1140
     * @throws java.sql.SQLException if the database server returns an error when fetching the client info values from
1141
     *                               the database or this method is called on a closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
1142
     *                               <p/>
1143
     * @since 1.6
1144
     */
5 by Marcus Eriksson
handle greeting packet from drizzled
1145
    public Properties getClientInfo() throws SQLException {
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1146
        return clientInfoProperties;
5 by Marcus Eriksson
handle greeting packet from drizzled
1147
    }
1148
16 by Marcus Eriksson
initial transaction support and some restructuring
1149
    /**
1150
     * Factory method for creating Array objects.
1151
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1152
     * <b>Note: </b>When <code>createArrayOf</code> is used to create an array object that maps to a primitive data
1153
     * type, then it is implementation-defined whether the <code>Array</code> object is an array of that primitive data
1154
     * type or an array of <code>Object</code>.
16 by Marcus Eriksson
initial transaction support and some restructuring
1155
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1156
     * <b>Note: </b>The JDBC driver is responsible for mapping the elements <code>Object</code> array to the default
1157
     * JDBC SQL type defined in java.sql.Types for the given class of <code>Object</code>. The default mapping is
1158
     * specified in Appendix B of the JDBC specification.  If the resulting JDBC type is not the appropriate type for
1159
     * the given typeName then it is implementation defined whether an <code>SQLException</code> is thrown or the driver
1160
     * supports the resulting conversion.
16 by Marcus Eriksson
initial transaction support and some restructuring
1161
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1162
     * @param typeName the SQL name of the type the elements of the array map to. The typeName is a database-specific
1163
     *                 name which may be the name of a built-in type, a user-defined type or a standard  SQL type
1164
     *                 supported by this database. This is the value returned by <code>Array.getBaseTypeName</code>
16 by Marcus Eriksson
initial transaction support and some restructuring
1165
     * @param elements the elements that populate the returned object
1166
     * @return an Array object whose elements map to the specified SQL type
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1167
     * @throws java.sql.SQLException if a database error occurs, the JDBC type is not appropriate for the typeName and
1168
     *                               the conversion is not supported, the typeName is null or this method is called on a
1169
     *                               closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
1170
     * @throws java.sql.SQLFeatureNotSupportedException
1171
     *                               if the JDBC driver does not support this data type
1172
     * @since 1.6
1173
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1174
    public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException {
219 by Marcus Eriksson
initial java5 support by Christian Peter
1175
        throw SQLExceptionMapper.getFeatureNotSupportedException("Not yet supported");
16 by Marcus Eriksson
initial transaction support and some restructuring
1176
    }
1177
1178
    /**
1179
     * Factory method for creating Struct objects.
1180
     *
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1181
     * @param typeName   the SQL type name of the SQL structured type that this <code>Struct</code> object maps to. The
1182
     *                   typeName is the name of  a user-defined type that has been defined for this database. It is the
1183
     *                   value returned by <code>Struct.getSQLTypeName</code>.
16 by Marcus Eriksson
initial transaction support and some restructuring
1184
     * @param attributes the attributes that populate the returned object
1185
     * @return a Struct object that maps to the given SQL type and is populated with the given attributes
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1186
     * @throws java.sql.SQLException if a database error occurs, the typeName is null or this method is called on a
1187
     *                               closed connection
16 by Marcus Eriksson
initial transaction support and some restructuring
1188
     * @throws java.sql.SQLFeatureNotSupportedException
1189
     *                               if the JDBC driver does not support this data type
1190
     * @since 1.6
1191
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1192
    public Struct createStruct(final String typeName, final Object[] attributes) throws SQLException {
219 by Marcus Eriksson
initial java5 support by Christian Peter
1193
        throw SQLExceptionMapper.getFeatureNotSupportedException("Not yet supported");
16 by Marcus Eriksson
initial transaction support and some restructuring
1194
    }
1195
1196
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1197
     * Returns an object that implements the given interface to allow access to non-standard methods, or standard
1198
     * methods not exposed by the proxy.
16 by Marcus Eriksson
initial transaction support and some restructuring
1199
     * <p/>
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1200
     * If the receiver implements the interface then the result is the receiver or a proxy for the receiver. If the
1201
     * receiver is a wrapper and the wrapped object implements the interface then the result is the wrapped object or a
1202
     * proxy for the wrapped object. Otherwise return the the result of calling <code>unwrap</code> recursively on the
1203
     * wrapped object or a proxy for that result. If the receiver is not a wrapper and does not implement the interface,
1204
     * then an <code>SQLException</code> is thrown.
16 by Marcus Eriksson
initial transaction support and some restructuring
1205
     *
1206
     * @param iface A Class defining an interface that the result must implement.
1207
     * @return an object that implements the interface. May be a proxy for the actual implementing object.
1208
     * @throws java.sql.SQLException If no object found that implements the interface
1209
     * @since 1.6
1210
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1211
    public <T> T unwrap(final Class<T> iface) throws SQLException {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1212
        return iface.cast(this);
16 by Marcus Eriksson
initial transaction support and some restructuring
1213
    }
1214
1215
    /**
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1216
     * Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an
1217
     * object that does. Returns false otherwise. If this implements the interface then return true, else if this is a
1218
     * wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped object. If this
1219
     * does not implement the interface and is not a wrapper, return false. This method should be implemented as a
1220
     * low-cost operation compared to <code>unwrap</code> so that callers can use this method to avoid expensive
1221
     * <code>unwrap</code> calls that may fail. If this method returns true then calling <code>unwrap</code> with the
1222
     * same argument should succeed.
16 by Marcus Eriksson
initial transaction support and some restructuring
1223
     *
1224
     * @param iface a Class defining an interface.
1225
     * @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
1226
     * @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper for an object with
1227
     *                               the given interface.
16 by Marcus Eriksson
initial transaction support and some restructuring
1228
     * @since 1.6
1229
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1230
    public boolean isWrapperFor(final Class<?> iface) throws SQLException {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1231
        return iface.isInstance(this);
5 by Marcus Eriksson
handle greeting packet from drizzled
1232
    }
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1233
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1234
    /**
1235
     * returns the username for the connection.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1236
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1237
     * @return the username.
1238
     */
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1239
    public String getUsername() {
1240
        return protocol.getUsername();
1241
    }
1242
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1243
    /**
1244
     * returns the password for the connection.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1245
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1246
     * @return the password.
1247
     */
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1248
    public String getPassword() {
1249
        return protocol.getPassword();
1250
    }
1251
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1252
    /**
1253
     * returns the hostname for the connection.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1254
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1255
     * @return the hostname.
1256
     */
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1257
    public String getHostname() {
1258
        return protocol.getHost();
1259
    }
1260
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1261
    /**
1262
     * returns the port for the connection.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1263
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1264
     * @return the port
1265
     */
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1266
    public int getPort() {
1267
        return protocol.getPort();
1268
    }
1269
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1270
    /**
1271
     * returns the database.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1272
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1273
     * @return the database
1274
     */
22 by Marcus Eriksson
connection almost complete, connection string parsing reworked
1275
    public String getDatabase() {
1276
        return protocol.getDatabase();
1277
    }
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1278
1279
    /**
1280
     * returns a list of binlog entries.
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1281
     *
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1282
     * @param position the position to start at
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1283
     * @param logfile  the log file to use
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1284
     * @return a list of rawpackets from the server
1285
     * @throws SQLException if there is a problem talking to the server.
1286
     */
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1287
    public List<RawPacket> startBinlogDump(final int position, final String logfile) throws SQLException {
52 by Marcus Eriksson
mysql support, fixes, replication
1288
        try {
113 by Marcus Eriksson
start using checkstyle and remove ugly code
1289
            return this.protocol.startBinlogDump(position, logfile);
52 by Marcus Eriksson
mysql support, fixes, replication
1290
        } catch (BinlogDumpException e) {
219 by Marcus Eriksson
initial java5 support by Christian Peter
1291
            throw SQLExceptionMapper.getSQLException("Could not dump binlog", e);
52 by Marcus Eriksson
mysql support, fixes, replication
1292
        }
1293
    }
116 by Marcus Eriksson
pluggable batch handler - possible to swap out the batch query handler for your own implementation
1294
155.1.5 by Marcus Eriksson
cleanups, checkstyle and intellij refactor stuff
1295
    public void setBatchQueryHandlerFactory(final ParameterizedBatchHandlerFactory batchHandlerFactory) {
119 by Marcus Eriksson
findbugs fixes, better api for pluggable batch handlers, remove unsafe publication in asyncpacketfetcher
1296
        this.parameterizedBatchHandlerFactory = batchHandlerFactory;
116 by Marcus Eriksson
pluggable batch handler - possible to swap out the batch query handler for your own implementation
1297
    }
244 by Marcus Eriksson
move executor thread pool to connection - have one timer thread per connection instead of one per statement
1298
373 by Vladislav Vaintroub
simplify Statement.close
1299
   
337 by Vladislav Vaintroub
implement failover during query and failback to master
1300
    public void setHostFailed() {
1301
        protocol.setHostFailed();
1302
    }
343 by Vladislav Vaintroub
Add dummy implementation for new JDBC methods in Java7
1303
1304
	public void abort(Executor arg0) throws SQLException {
1305
		// TODO Auto-generated method stub
1306
		
1307
	}
1308
1309
	public int getNetworkTimeout() throws SQLException {
1310
		// TODO Auto-generated method stub
1311
		return 0;
1312
	}
1313
1314
	public String getSchema() throws SQLException {
1315
		// TODO Auto-generated method stub
1316
		return null;
1317
	}
1318
1319
	public void setNetworkTimeout(Executor arg0, int arg1) throws SQLException {
1320
		// TODO Auto-generated method stub
1321
		
1322
	}
1323
1324
	public void setSchema(String arg0) throws SQLException {
1325
		// TODO Auto-generated method stub
1326
		
1327
	}
2 by Marcus Eriksson
add tests and some classes
1328
}