Connection.java
14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/*
Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
The MySQL Connector/J is licensed under the terms of the GPLv2
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
There are special exceptions to the terms and conditions of the GPLv2 as it is applied to
this software, see the FOSS License Exception
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; version 2
of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this
program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth
Floor, Boston, MA 02110-1301 USA
*/
package com.mysql.jdbc;
import java.sql.SQLException;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.Executor;
import com.mysql.jdbc.log.Log;
/**
* This interface contains methods that are considered the "vendor extension" to the JDBC API for MySQL's implementation of java.sql.Connection.
*
* For those looking further into the driver implementation, it is not an API that is used for plugability of implementations inside our driver
* (which is why there are still references to ConnectionImpl throughout the code).
*/
public interface Connection extends java.sql.Connection, ConnectionProperties {
/**
* Changes the user on this connection by performing a re-authentication. If
* authentication fails, the connection will remain under the context of the
* current user.
*
* @param userName
* the username to authenticate with
* @param newPassword
* the password to authenticate with
* @throws SQLException
* if authentication fails, or some other error occurs while
* performing the command.
*/
public abstract void changeUser(String userName, String newPassword) throws SQLException;
@Deprecated
public abstract void clearHasTriedMaster();
/**
* Prepares a statement on the client, using client-side emulation
* (irregardless of the configuration property 'useServerPrepStmts')
* with the same semantics as the java.sql.Connection.prepareStatement()
* method with the same argument types.
*
* @see java.sql.Connection#prepareStatement(String)
*/
public abstract java.sql.PreparedStatement clientPrepareStatement(String sql) throws SQLException;
/**
* Prepares a statement on the client, using client-side emulation
* (irregardless of the configuration property 'useServerPrepStmts')
* with the same semantics as the java.sql.Connection.prepareStatement()
* method with the same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int)
*/
public abstract java.sql.PreparedStatement clientPrepareStatement(String sql, int autoGenKeyIndex) throws SQLException;
/**
* Prepares a statement on the client, using client-side emulation
* (irregardless of the configuration property 'useServerPrepStmts')
* with the same semantics as the java.sql.Connection.prepareStatement()
* method with the same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int, int)
*/
public abstract java.sql.PreparedStatement clientPrepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException;
/**
* Prepares a statement on the client, using client-side emulation
* (irregardless of the configuration property 'useServerPrepStmts')
* with the same semantics as the java.sql.Connection.prepareStatement()
* method with the same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int[])
*/
public abstract java.sql.PreparedStatement clientPrepareStatement(String sql, int[] autoGenKeyIndexes) throws SQLException;
/**
* Prepares a statement on the client, using client-side emulation
* (irregardless of the configuration property 'useServerPrepStmts')
* with the same semantics as the java.sql.Connection.prepareStatement()
* method with the same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int, int, int)
*/
public abstract java.sql.PreparedStatement clientPrepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException;
/**
* Prepares a statement on the client, using client-side emulation
* (irregardless of the configuration property 'useServerPrepStmts')
* with the same semantics as the java.sql.Connection.prepareStatement()
* method with the same argument types.
*
* @see java.sql.Connection#prepareStatement(String, String[])
*/
public abstract java.sql.PreparedStatement clientPrepareStatement(String sql, String[] autoGenKeyColNames) throws SQLException;
/**
* Returns the number of statements active on this connection, which
* haven't been .close()d.
*/
public abstract int getActiveStatementCount();
/**
* Reports how long this connection has been idle.
* This time (reported in milliseconds) is updated once a query has
* completed.
*
* @return number of ms that this connection has been idle, 0 if the driver
* is busy retrieving results.
*/
public abstract long getIdleFor();
/**
* Returns the log mechanism that should be used to log information from/for
* this Connection.
*
* @return the Log instance to use for logging messages.
* @throws SQLException
* if an error occurs
*/
public abstract Log getLog() throws SQLException;
/**
* Returns the server's character set
*
* @return the server's character set.
* @deprecated replaced by <code>Connection.getServerCharset()</code>
*/
@Deprecated
public abstract String getServerCharacterEncoding();
/**
* Returns the server's character set
*
* @return the server's character set.
*/
public abstract String getServerCharset();
/**
* Returns the TimeZone that represents the configured
* timezone for the server.
*/
public abstract TimeZone getServerTimezoneTZ();
/**
* Returns the comment that will be prepended to all statements
* sent to the server.
*
* @return the comment that will be prepended to all statements
* sent to the server.
*/
public abstract String getStatementComment();
/**
* Has this connection tried to execute a query on the "master"
* server (first host in a multiple host list).
*/
@Deprecated
public abstract boolean hasTriedMaster();
/**
* Is this connection currently a participant in an XA transaction?
*/
public abstract boolean isInGlobalTx();
/**
* Set the state of being in a global (XA) transaction.
*
* @param flag
*/
public void setInGlobalTx(boolean flag);
/**
* Is this connection connected to the first host in the list if
* there is a list of servers in the URL?
*
* @return true if this connection is connected to the first in
* the list.
*/
public abstract boolean isMasterConnection();
/**
* Is the server in a sql_mode that doesn't allow us to use \\ to escape
* things?
*
* @return Returns the noBackslashEscapes.
*/
public abstract boolean isNoBackslashEscapesSet();
/**
* Does this connection have the same resource name as the given
* connection (for XA)?
*
* @param c
*/
public abstract boolean isSameResource(Connection c);
/**
* Is the server configured to use lower-case table names only?
*
* @return true if lower_case_table_names is 'on'
*/
public abstract boolean lowerCaseTableNames();
/**
* Does the server this connection is connected to
* support unicode?
*/
public abstract boolean parserKnowsUnicode();
/**
* Detect if the connection is still good by sending a ping command
* to the server.
*
* @throws SQLException
* if the ping fails
*/
public abstract void ping() throws SQLException;
/**
* Resets the server-side state of this connection. Doesn't work for MySQL
* versions older than 4.0.6 or if isParanoid() is set (it will become a
* no-op in these cases). Usually only used from connection pooling code.
*
* @throws SQLException
* if the operation fails while resetting server state.
*/
public abstract void resetServerState() throws SQLException;
/**
* Prepares a statement on the server (irregardless of the
* configuration property 'useServerPrepStmts') with the same semantics
* as the java.sql.Connection.prepareStatement() method with the
* same argument types.
*
* @see java.sql.Connection#prepareStatement(String)
*/
public abstract java.sql.PreparedStatement serverPrepareStatement(String sql) throws SQLException;
/**
* Prepares a statement on the server (irregardless of the
* configuration property 'useServerPrepStmts') with the same semantics
* as the java.sql.Connection.prepareStatement() method with the
* same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int)
*/
public abstract java.sql.PreparedStatement serverPrepareStatement(String sql, int autoGenKeyIndex) throws SQLException;
/**
* Prepares a statement on the server (irregardless of the
* configuration property 'useServerPrepStmts') with the same semantics
* as the java.sql.Connection.prepareStatement() method with the
* same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int, int)
*/
public abstract java.sql.PreparedStatement serverPrepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException;
/**
* Prepares a statement on the server (irregardless of the
* configuration property 'useServerPrepStmts') with the same semantics
* as the java.sql.Connection.prepareStatement() method with the
* same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int, int, int)
*/
public abstract java.sql.PreparedStatement serverPrepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException;
/**
* Prepares a statement on the server (irregardless of the
* configuration property 'useServerPrepStmts') with the same semantics
* as the java.sql.Connection.prepareStatement() method with the
* same argument types.
*
* @see java.sql.Connection#prepareStatement(String, int[])
*/
public abstract java.sql.PreparedStatement serverPrepareStatement(String sql, int[] autoGenKeyIndexes) throws SQLException;
/**
* Prepares a statement on the server (irregardless of the
* configuration property 'useServerPrepStmts') with the same semantics
* as the java.sql.Connection.prepareStatement() method with the
* same argument types.
*
* @see java.sql.Connection#prepareStatement(String, String[])
*/
public abstract java.sql.PreparedStatement serverPrepareStatement(String sql, String[] autoGenKeyColNames) throws SQLException;
/**
* @param failedOver
* The failedOver to set.
*/
public abstract void setFailedOver(boolean flag);
/**
* @param preferSlaveDuringFailover
* The preferSlaveDuringFailover to set.
*/
@Deprecated
public abstract void setPreferSlaveDuringFailover(boolean flag);
/**
* Sets the comment that will be prepended to all statements
* sent to the server. Do not use slash-star or star-slash tokens
* in the comment as these will be added by the driver itself.
*
* @param comment
* the comment that will be prepended to all statements
* sent to the server.
*/
public abstract void setStatementComment(String comment);
/**
* Used by MiniAdmin to shutdown a MySQL server
*
* @throws SQLException
* if the command can not be issued.
*/
public abstract void shutdownServer() throws SQLException;
/**
* Does the server this connection is connected to
* support isolation levels?
*/
public abstract boolean supportsIsolationLevel();
/**
* Does the server this connection is connected to
* support quoted identifiers?
*/
public abstract boolean supportsQuotedIdentifiers();
/**
* Does the server this connection is connected to
* support transactions?
*/
public abstract boolean supportsTransactions();
/**
* Does the server this connection is connected to
* meet or exceed the given version?
*/
public abstract boolean versionMeetsMinimum(int major, int minor, int subminor) throws SQLException;
public abstract void reportQueryTime(long millisOrNanos);
public abstract boolean isAbonormallyLongQuery(long millisOrNanos);
public abstract void initializeExtension(Extension ex) throws SQLException;
/**
* Returns the -session- value of 'auto_increment_increment' from the server if it exists,
* or '1' if not.
*/
public abstract int getAutoIncrementIncrement();
/**
* Does this connection have the same properties as another?
*/
public boolean hasSameProperties(Connection c);
/**
* Returns the parsed and passed in properties for this connection.
*/
public Properties getProperties();
public String getHost();
public void setProxy(MySQLConnection proxy);
/**
* Is the server this connection is connected to "local" (i.e. same host) as the application?
*/
public boolean isServerLocal() throws SQLException;
int getSessionMaxRows();
void setSessionMaxRows(int max) throws SQLException;
// JDBC-4.1
// until we flip catalog/schema, this is a no-op
void setSchema(String schema) throws SQLException;
String getSchema() throws SQLException;
// JDBC-4.1
void abort(Executor executor) throws SQLException;
// JDBC-4.1
void setNetworkTimeout(Executor executor, final int milliseconds) throws SQLException;
int getNetworkTimeout() throws SQLException;
// **************************
// moved from MySQLConnection
// **************************
void abortInternal() throws SQLException;
void checkClosed() throws SQLException;
Object getConnectionMutex();
}