KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > Connection


1 /*
2    Copyright (C) 2002 MySQL AB
3
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8
9       This program is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12       GNU General Public License for more details.
13
14       You should have received a copy of the GNU General Public License
15       along with this program; if not, write to the Free Software
16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18  */

19 package com.mysql.jdbc;
20
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.Reader JavaDoc;
24 import java.io.UnsupportedEncodingException JavaDoc;
25
26 import java.math.BigDecimal JavaDoc;
27
28 import java.net.URL JavaDoc;
29
30 import java.sql.Clob JavaDoc;
31 import java.sql.Date JavaDoc;
32 import java.sql.ParameterMetaData JavaDoc;
33 import java.sql.Ref JavaDoc;
34 import java.sql.SQLException JavaDoc;
35 import java.sql.Savepoint JavaDoc;
36 import java.sql.Time JavaDoc;
37 import java.sql.Timestamp JavaDoc;
38
39 import java.util.ArrayList JavaDoc;
40 import java.util.Calendar JavaDoc;
41 import java.util.HashMap JavaDoc;
42 import java.util.Iterator JavaDoc;
43 import java.util.List JavaDoc;
44 import java.util.Map JavaDoc;
45 import java.util.Properties JavaDoc;
46 import java.util.TimeZone JavaDoc;
47
48
49 /**
50  * A Connection represents a session with a specific database. Within the
51  * context of a Connection, SQL statements are executed and results are
52  * returned.
53  *
54  * <P>
55  * A Connection's database is able to provide information describing its
56  * tables, its supported SQL grammar, its stored procedures, the capabilities
57  * of this connection, etc. This information is obtained with the getMetaData
58  * method.
59  * </p>
60  *
61  * @author Mark Matthews
62  * @version $Id: Connection.java,v 1.31.2.55 2004/02/13 22:33:50 mmatthew Exp $
63  *
64  * @see java.sql.Connection
65  */

66 public class Connection implements java.sql.Connection JavaDoc {
67     // The command used to "ping" the database.
68
// Newer versions of MySQL server have a ping() command,
69
// but this works for everything
70
private static final String JavaDoc PING_COMMAND = "SELECT 1";
71
72     /**
73      * Map mysql transaction isolation level name to
74      * java.sql.Connection.TRANSACTION_XXX
75      */

76     private static Map JavaDoc mapTransIsolationName2Value = null;
77
78     /**
79      * The mapping between MySQL charset names and Java charset names.
80      * Initialized by loadCharacterSetMapping()
81      */

82     private static Map JavaDoc charsetMap;
83
84     /** Table of multi-byte charsets. Initialized by loadCharacterSetMapping() */
85     private static Map JavaDoc multibyteCharsetsMap;
86
87     /** Default socket factory classname */
88     private static final String JavaDoc DEFAULT_SOCKET_FACTORY = StandardSocketFactory.class
89         .getName();
90
91     static {
92         loadCharacterSetMapping();
93         mapTransIsolationName2Value = new HashMap JavaDoc(8);
94         mapTransIsolationName2Value.put("READ-UNCOMMITED",
95             new Integer JavaDoc(TRANSACTION_READ_UNCOMMITTED));
96         mapTransIsolationName2Value.put("READ-UNCOMMITTED",
97             new Integer JavaDoc(TRANSACTION_READ_UNCOMMITTED));
98         mapTransIsolationName2Value.put("READ-COMMITTED",
99             new Integer JavaDoc(TRANSACTION_READ_COMMITTED));
100         mapTransIsolationName2Value.put("REPEATABLE-READ",
101             new Integer JavaDoc(TRANSACTION_REPEATABLE_READ));
102         mapTransIsolationName2Value.put("SERIALIZABLE",
103             new Integer JavaDoc(TRANSACTION_SERIALIZABLE));
104     }
105
106     /**
107      * Marker for character set converter not being available (not written,
108      * multibyte, etc) Used to prevent multiple instantiation requests.
109      */

110     private final static Object JavaDoc CHARSET_CONVERTER_NOT_AVAILABLE_MARKER = new Object JavaDoc();
111
112     /** Internal DBMD to use for various database-version specific features */
113     private DatabaseMetaData dbmd = null;
114
115     /** The list of host(s) to try and connect to */
116     private List JavaDoc hostList = null;
117
118     /** A map of SQL to parsed prepared statement parameters. */
119     private Map JavaDoc cachedPreparedStatementParams;
120
121     /**
122      * Holds cached mappings to charset converters to avoid static
123      * synchronization and at the same time save memory (each charset
124      * converter takes approx 65K of static data).
125      */

126     private Map JavaDoc charsetConverterMap = new HashMap JavaDoc(CharsetMapping.JAVA_TO_MYSQL_CHARSET_MAP
127             .size());
128
129     /** A map of statements that have had setMaxRows() called on them */
130     private Map JavaDoc statementsUsingMaxRows;
131
132     /**
133      * The type map for UDTs (not implemented, but used by some third-party
134      * vendors, most notably IBM WebSphere)
135      */

136     private Map JavaDoc typeMap;
137
138     /** The I/O abstraction interface (network conn to MySQL server */
139     private MysqlIO io = null;
140
141     /** Mutex */
142     private final Object JavaDoc mutex = new Object JavaDoc();
143
144     /** The map of server variables that we retrieve at connection init. */
145     private Map JavaDoc serverVariables = null;
146
147     /** The driver instance that created us */
148     private NonRegisteringDriver myDriver;
149
150     /** Properties for this connection specified by user */
151     private Properties JavaDoc props = null;
152
153     /** The database we're currently using (called Catalog in JDBC terms). */
154     private String JavaDoc database = null;
155
156     /** If we're doing unicode character conversions, what encoding do we use? */
157     private String JavaDoc encoding = null;
158
159     /** The hostname we're connected to */
160     private String JavaDoc host = null;
161
162     /** The JDBC URL we're using */
163     private String JavaDoc myURL = null;
164
165     /** What does MySQL call this encoding? */
166     private String JavaDoc mysqlEncodingName = null;
167     private String JavaDoc negativeInfinityRep = MysqlDefs.MIN_DOUBLE_VAL_STRING;
168     private String JavaDoc notANumberRep = MysqlDefs.NAN_VAL_STRING;
169
170     /** The password we used */
171     private String JavaDoc password = null;
172     private String JavaDoc positiveInfinityRep = MysqlDefs.MAX_DOUBLE_VAL_STRING;
173
174     /** Classname for socket factory */
175     private String JavaDoc socketFactoryClassName = null;
176
177     /** The user we're connected as */
178     private String JavaDoc user = null;
179
180     /** Where was the connection _explicitly_ closed by the application? */
181     private Throwable JavaDoc explicitCloseLocation;
182
183     /** If the connection was forced closed, why was it forced closed? */
184     private Throwable JavaDoc forcedCloseReason;
185     private TimeZone JavaDoc defaultTimeZone;
186
187     /** The timezone of the server */
188     private TimeZone JavaDoc serverTimezone = null;
189
190     /** Allow LOAD LOCAL INFILE (defaults to true) */
191     private boolean allowLoadLocalInfile = true;
192
193     /** Should we clear the input stream each query? */
194     private boolean alwaysClearStream = false;
195
196     /** Are we in autoCommit mode? */
197     private boolean autoCommit = true;
198
199     /** SHould we cache the parsing of prepared statements? */
200     private boolean cachePreparedStatements = false;
201
202     /** Should we capitalize mysql types */
203     private boolean capitalizeDBMDTypes = false;
204
205     /** Should we clobber streaming results on new queries, or issue an error? */
206     private boolean clobberStreamingResults = false;
207
208     /**
209      * Should we continue processing batch commands if one fails. The JDBC spec
210      * allows either way, so we let the user choose
211      */

212     private boolean continueBatchOnError = true;
213
214     /** Should we do unicode character conversions? */
215     private boolean doUnicode = false;
216
217     /** Are we failed-over to a non-master host */
218     private boolean failedOver = false;
219
220     /** Does the server suuport isolation levels? */
221     private boolean hasIsolationLevels = false;
222
223     /** Does this version of MySQL support quoted identifiers? */
224     private boolean hasQuotedIdentifiers = false;
225
226     //
227
// This is for the high availability :) routines
228
//
229
private boolean highAvailability = false;
230
231     /** Ignore non-transactional table warning for rollback? */
232     private boolean ignoreNonTxTables = false;
233
234     /** Has this connection been closed? */
235     private boolean isClosed = true;
236
237     /** Should we tell MySQL that we're an interactive client? */
238     private boolean isInteractiveClient = false;
239
240     /** Is the server configured to use lower-case table names only? */
241     private boolean lowerCaseTableNames = false;
242
243     /** Has the max-rows setting been changed from the default? */
244     private boolean maxRowsChanged = false;
245     private boolean negativeInfinityRepIsClipped = true;
246     private boolean notANumberRepIsClipped = true;
247
248     /** Do we expose sensitive information in exception and error messages? */
249     private boolean paranoid = false;
250
251     /** Should we do 'extra' sanity checks? */
252     private boolean pedantic = false;
253     private boolean positiveInfinityRepIsClipped = true;
254
255     /** Should we retrieve 'info' messages from the server? */
256     private boolean readInfoMsg = false;
257
258     /** Are we in read-only mode? */
259     private boolean readOnly = false;
260
261     /**
262      * If autoReconnect == true, should we attempt to reconnect at transaction
263      * boundaries?
264      */

265     private boolean reconnectAtTxEnd = false;
266
267     /** Do we relax the autoCommit semantics? (For enhydra, for example) */
268     private boolean relaxAutoCommit = false;
269
270     /** Do we need to correct endpoint rounding errors */
271     private boolean strictFloatingPoint = false;
272
273     /** Do we check all keys for updatable result sets? */
274     private boolean strictUpdates = true;
275
276     /** Are transactions supported by the MySQL server we are connected to? */
277     private boolean transactionsSupported = false;
278
279     /** Has ANSI_QUOTES been enabled on the server? */
280     private boolean useAnsiQuotes = false;
281
282     /** Should we use compression? */
283     private boolean useCompression = false;
284
285     /** Can we use the "ping" command rather than a query? */
286     private boolean useFastPing = false;
287
288     /** Should we tack on hostname in DBMD.getTable/ColumnPrivileges()? */
289     private boolean useHostsInPrivileges = true;
290
291     /** Should we use SSL? */
292     private boolean useSSL = false;
293
294     /**
295      * Should we use stream lengths in prepared statements? (true by default ==
296      * JDBC compliant)
297      */

298     private boolean useStreamLengthsInPrepStmts = true;
299
300     /** Should we use timezone information? */
301     private boolean useTimezone = false;
302
303     /** Should we return PreparedStatements for UltraDev's stupid bug? */
304     private boolean useUltraDevWorkAround = false;
305     private boolean useUnbufferedInput = true;
306     private double initialTimeout = 2.0D;
307
308     /** How many hosts are in the host list? */
309     private int hostListSize = 0;
310
311     /** isolation level */
312     private int isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED;
313
314     /**
315      * The largest packet we can send (changed once we know what the server
316      * supports, we get this at connection init).
317      */

318     private int maxAllowedPacket = 65536;
319     private int maxReconnects = 3;
320
321     /**
322      * The max rows that a result set can contain. Defaults to -1, which
323      * according to the JDBC spec means "all".
324      */

325     private int maxRows = -1;
326     private int netBufferLength = 16384;
327
328     /** The port number we're connected to (defaults to 3306) */
329     private int port = 3306;
330
331     /**
332      * If prepared statement caching is enabled, what should the threshold
333      * length of the SQL to prepare should be in order to _not_ cache?
334      */

335     private int preparedStatementCacheMaxSqlSize = 256;
336
337     /** If prepared statement caching is enabled, how many should we cache? */
338     private int preparedStatementCacheSize = 25;
339
340     /**
341      * How many queries should we wait before we try to re-connect to the
342      * master, when we are failing over to replicated hosts Defaults to 50
343      */

344     private int queriesBeforeRetryMaster = 50;
345
346     /** What should we set the socket timeout to? */
347     private int socketTimeout = 0; // infinite
348

349     /** When did the last query finish? */
350     private long lastQueryFinishedTime = 0;
351
352     /** When did the master fail? */
353     private long masterFailTimeMillis = 0L;
354
355     /** Number of queries we've issued since the master failed */
356     private long queriesIssuedFailedOver = 0;
357
358     /**
359      * How many seconds should we wait before retrying to connect to the master
360      * if failed over? We fall back when either queriesBeforeRetryMaster or
361      * secondsBeforeRetryMaster is reached.
362      */

363     private long secondsBeforeRetryMaster = 30L;
364
365     /**
366      * Creates a connection to a MySQL Server.
367      *
368      * @param host the hostname of the database server
369      * @param port the port number the server is listening on
370      * @param info a Properties[] list holding the user and password
371      * @param database the database to connect to
372      * @param url the URL of the connection
373      * @param d the Driver instantation of the connection
374      *
375      * @exception java.sql.SQLException if a database access error occurs
376      * @throws SQLException DOCUMENT ME!
377      */

378     Connection(String JavaDoc host, int port, Properties JavaDoc info, String JavaDoc database,
379         String JavaDoc url, NonRegisteringDriver d) throws java.sql.SQLException JavaDoc {
380         if (Driver.TRACE) {
381             Object JavaDoc[] args = { host, new Integer JavaDoc(port), info, database, url, d };
382             Debug.methodCall(this, "constructor", args);
383         }
384
385         this.defaultTimeZone = TimeZone.getDefault();
386
387         this.serverVariables = new HashMap JavaDoc();
388
389         if (host == null) {
390             this.host = "localhost";
391             hostList = new ArrayList JavaDoc();
392             hostList.add(this.host);
393         } else if (host.indexOf(",") != -1) {
394             // multiple hosts separated by commas (failover)
395
hostList = StringUtils.split(host, ",", true);
396         } else {
397             this.host = host;
398             hostList = new ArrayList JavaDoc();
399             hostList.add(this.host);
400         }
401
402         hostListSize = hostList.size();
403         this.port = port;
404
405         if (database == null) {
406             throw new SQLException JavaDoc("Malformed URL '" + url + "'.",
407                 SQLError.SQL_STATE_GENERAL_ERROR);
408         }
409
410         this.database = database;
411         this.myURL = url;
412         this.myDriver = d;
413         this.user = info.getProperty("user");
414         this.password = info.getProperty("password");
415
416         if ((this.user == null) || this.user.equals("")) {
417             this.user = "nobody";
418         }
419
420         if (this.password == null) {
421             this.password = "";
422         }
423
424         this.props = info;
425         initializeDriverProperties(info);
426
427         if (Driver.DEBUG) {
428             System.out.println("Connect: " + this.user + " to " + this.database);
429         }
430
431         try {
432             createNewIO(false);
433             this.dbmd = new DatabaseMetaData(this, this.database);
434         } catch (java.sql.SQLException JavaDoc ex) {
435             cleanup(ex);
436
437             // don't clobber SQL exceptions
438
throw ex;
439         } catch (Exception JavaDoc ex) {
440             cleanup(ex);
441
442             StringBuffer JavaDoc mesg = new StringBuffer JavaDoc();
443
444             if (!useParanoidErrorMessages()) {
445                 mesg.append("Cannot connect to MySQL server on ");
446                 mesg.append(this.host);
447                 mesg.append(":");
448                 mesg.append(this.port);
449                 mesg.append(".\n\n");
450                 mesg.append("Make sure that there is a MySQL server ");
451                 mesg.append("running on the machine/port you are trying ");
452                 mesg.append(
453                     "to connect to and that the machine this software is "
454                     + "running on ");
455                 mesg.append("is able to connect to this host/port "
456                     + "(i.e. not firewalled). ");
457                 mesg.append(
458                     "Also make sure that the server has not been started "
459                     + "with the --skip-networking ");
460                 mesg.append("flag.\n\n");
461             } else {
462                 mesg.append("Unable to connect to database.");
463             }
464
465             mesg.append("Underlying exception: \n\n");
466             mesg.append(ex.getClass().getName());
467             throw new java.sql.SQLException JavaDoc(mesg.toString(),
468                 SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE);
469         }
470     }
471
472     /**
473      * If a connection is in auto-commit mode, than all its SQL statements will
474      * be executed and committed as individual transactions. Otherwise, its
475      * SQL statements are grouped into transactions that are terminated by
476      * either commit() or rollback(). By default, new connections are in
477      * auto- commit mode. The commit occurs when the statement completes or
478      * the next execute occurs, whichever comes first. In the case of
479      * statements returning a ResultSet, the statement completes when the last
480      * row of the ResultSet has been retrieved or the ResultSet has been
481      * closed. In advanced cases, a single statement may return multiple
482      * results as well as output parameter values. Here the commit occurs
483      * when all results and output param values have been retrieved.
484      *
485      * <p>
486      * <b>Note:</b> MySQL does not support transactions, so this method is a
487      * no-op.
488      * </p>
489      *
490      * @param autoCommit - true enables auto-commit; false disables it
491      *
492      * @exception java.sql.SQLException if a database access error occurs
493      * @throws SQLException DOCUMENT ME!
494      */

495     public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException JavaDoc {
496         if (Driver.TRACE) {
497             Object JavaDoc[] args = { new Boolean JavaDoc(autoCommit) };
498             Debug.methodCall(this, "setAutoCommit", args);
499         }
500
501         checkClosed();
502
503         if (this.transactionsSupported) {
504             // this internal value must be set first as failover depends on it
505
// being set to true to fail over (which is done by most
506
// app servers and connection pools at the end of
507
// a transaction), and the driver issues an implicit set
508
// based on this value when it (re)-connects to a server
509
// so the value holds across connections
510
//
511
this.autoCommit = autoCommit;
512
513             //
514
// This is to catch the 'edge' case of
515
// autoCommit going from true -> false
516
//
517
if ((this.highAvailability || this.failedOver) && !this.autoCommit) {
518                 pingAndReconnect(true);
519             }
520
521             String JavaDoc sql = "SET autocommit=" + (autoCommit ? "1" : "0");
522             execSQL(sql, -1, this.database);
523         } else {
524             if ((autoCommit == false) && (this.relaxAutoCommit == false)) {
525                 throw new SQLException JavaDoc("MySQL Versions Older than 3.23.15 "
526                     + "do not support transactions",
527                     SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);
528             } else {
529                 this.autoCommit = autoCommit;
530             }
531         }
532
533         return;
534     }
535
536     /**
537      * gets the current auto-commit state
538      *
539      * @return Current state of the auto-commit mode
540      *
541      * @exception java.sql.SQLException (why?)
542      *
543      * @see setAutoCommit
544      */

545     public boolean getAutoCommit() throws java.sql.SQLException JavaDoc {
546         if (Driver.TRACE) {
547             Object JavaDoc[] args = new Object JavaDoc[0];
548             Debug.methodCall(this, "getAutoCommit", args);
549             Debug.returnValue(this, "getAutoCommit",
550                 new Boolean JavaDoc(this.autoCommit));
551         }
552
553         return this.autoCommit;
554     }
555
556     /**
557      * A sub-space of this Connection's database may be selected by setting a
558      * catalog name. If the driver does not support catalogs, it will
559      * silently ignore this request
560      *
561      * <p>
562      * <b>Note:</b> MySQL's notion of catalogs are individual databases.
563      * </p>
564      *
565      * @param catalog the database for this connection to use
566      *
567      * @throws java.sql.SQLException if a database access error occurs
568      */

569     public void setCatalog(String JavaDoc catalog) throws java.sql.SQLException JavaDoc {
570         if (Driver.TRACE) {
571             Object JavaDoc[] args = { catalog };
572             Debug.methodCall(this, "setCatalog", args);
573         }
574
575         checkClosed();
576
577         String JavaDoc quotedId = this.dbmd.getIdentifierQuoteString();
578
579         if ((quotedId == null) || quotedId.equals(" ")) {
580             quotedId = "";
581         }
582
583         StringBuffer JavaDoc query = new StringBuffer JavaDoc("USE ");
584         query.append(quotedId);
585         query.append(catalog);
586         query.append(quotedId);
587
588         execSQL(query.toString(), -1, catalog);
589         this.database = catalog;
590     }
591
592     /**
593      * Return the connections current catalog name, or null if no catalog name
594      * is set, or we dont support catalogs.
595      *
596      * <p>
597      * <b>Note:</b> MySQL's notion of catalogs are individual databases.
598      * </p>
599      *
600      * @return the current catalog name or null
601      *
602      * @exception java.sql.SQLException if a database access error occurs
603      */

604     public String JavaDoc getCatalog() throws java.sql.SQLException JavaDoc {
605         if (Driver.TRACE) {
606             Object JavaDoc[] args = new Object JavaDoc[0];
607             Debug.methodCall(this, "getCatalog", args);
608             Debug.returnValue(this, "getCatalog", this.database);
609         }
610
611         return this.database;
612     }
613
614     /**
615      * Returns whether we clobber streaming results on new queries, or issue an
616      * error?
617      *
618      * @return true if we should implicitly close streaming result sets upon
619      * receiving a new query
620      */

621     public boolean getClobberStreamingResults() {
622         return this.clobberStreamingResults;
623     }
624
625     /**
626      * DOCUMENT ME!
627      *
628      * @return DOCUMENT ME!
629      */

630     public boolean isClosed() {
631         if (Driver.TRACE) {
632             Object JavaDoc[] args = new Object JavaDoc[0];
633             Debug.methodCall(this, "isClosed", args);
634             Debug.returnValue(this, "isClosed", new Boolean JavaDoc(this.isClosed));
635         }
636
637         return this.isClosed;
638     }
639
640     /**
641      * Returns the character encoding for this Connection
642      *
643      * @return the character encoding for this connection.
644      */

645     public String JavaDoc getEncoding() {
646         return this.encoding;
647     }
648
649     /**
650      * @see Connection#setHoldability(int)
651      */

652     public void setHoldability(int arg0) throws SQLException JavaDoc {
653         // do nothing
654
}
655
656     /**
657      * @see Connection#getHoldability()
658      */

659     public int getHoldability() throws SQLException JavaDoc {
660         return ResultSet.CLOSE_CURSORS_AT_COMMIT;
661     }
662
663     /**
664      * NOT JDBC-Compliant, but clients can use this method to determine how
665      * long this connection has been idle. This time (reported in
666      * milliseconds) is updated once a query has completed.
667      *
668      * @return number of ms that this connection has been idle, 0 if the driver
669      * is busy retrieving results.
670      */

671     public long getIdleFor() {
672         if (this.lastQueryFinishedTime == 0) {
673             return 0;
674         } else {
675             long now = System.currentTimeMillis();
676             long idleTime = now - this.lastQueryFinishedTime;
677
678             return idleTime;
679         }
680     }
681
682     /**
683      * Should we tell MySQL that we're an interactive client
684      *
685      * @return true if isInteractiveClient was set to true.
686      */

687     public boolean isInteractiveClient() {
688         return isInteractiveClient;
689     }
690
691     /**
692      * A connection's database is able to provide information describing its
693      * tables, its supported SQL grammar, its stored procedures, the
694      * capabilities of this connection, etc. This information is made
695      * available through a DatabaseMetaData object.
696      *
697      * @return a DatabaseMetaData object for this connection
698      *
699      * @exception java.sql.SQLException if a database access error occurs
700      */

701     public java.sql.DatabaseMetaData JavaDoc getMetaData() throws java.sql.SQLException JavaDoc {
702         checkClosed();
703
704         return new DatabaseMetaData(this, this.database);
705     }
706
707     /**
708      * DOCUMENT ME!
709      *
710      * @return
711      */

712     public String JavaDoc getNegativeInfinityRep() {
713         return negativeInfinityRep;
714     }
715
716     /**
717      * DOCUMENT ME!
718      *
719      * @return
720      */

721     public boolean isNegativeInfinityRepIsClipped() {
722         return negativeInfinityRepIsClipped;
723     }
724
725     /**
726      * DOCUMENT ME!
727      *
728      * @return
729      */

730     public String JavaDoc getNotANumberRep() {
731         return notANumberRep;
732     }
733
734     /**
735      * DOCUMENT ME!
736      *
737      * @return
738      */

739     public boolean isNotANumberRepIsClipped() {
740         return notANumberRepIsClipped;
741     }
742
743     /**
744      * DOCUMENT ME!
745      *
746      * @return
747      */

748     public String JavaDoc getPositiveInfinityRep() {
749         return positiveInfinityRep;
750     }
751
752     /**
753      * DOCUMENT ME!
754      *
755      * @return
756      */

757     public boolean isPositiveInfinityRepIsClipped() {
758         return positiveInfinityRepIsClipped;
759     }
760
761     /**
762      * Should the driver do profiling?
763      *
764      * @param flag set to true to enable profiling.
765      *
766      * @throws SQLException if the connection is closed.
767      */

768     public void setProfileSql(boolean flag) throws SQLException JavaDoc {
769         // For re-connection
770
this.props.setProperty("profileSql", String.valueOf(flag));
771         getIO().setProfileSql(flag);
772     }
773
774     /**
775      * You can put a connection in read-only mode as a hint to enable database
776      * optimizations <B>Note:</B> setReadOnly cannot be called while in the
777      * middle of a transaction
778      *
779      * @param readOnly - true enables read-only mode; false disables it
780      *
781      * @exception java.sql.SQLException if a database access error occurs
782      */

783     public void setReadOnly(boolean readOnly) throws java.sql.SQLException JavaDoc {
784         if (Driver.TRACE) {
785             Object JavaDoc[] args = { new Boolean JavaDoc(readOnly) };
786             Debug.methodCall(this, "setReadOnly", args);
787             Debug.returnValue(this, "setReadOnly", new Boolean JavaDoc(readOnly));
788         }
789
790         checkClosed();
791         this.readOnly = readOnly;
792     }
793
794     /**
795      * Tests to see if the connection is in Read Only Mode. Note that we
796      * cannot really put the database in read only mode, but we pretend we can
797      * by returning the value of the readOnly flag
798      *
799      * @return true if the connection is read only
800      *
801      * @exception java.sql.SQLException if a database access error occurs
802      */

803     public boolean isReadOnly() throws java.sql.SQLException JavaDoc {
804         if (Driver.TRACE) {
805             Object JavaDoc[] args = new Object JavaDoc[0];
806             Debug.methodCall(this, "isReadOnly", args);
807             Debug.returnValue(this, "isReadOnly", new Boolean JavaDoc(this.readOnly));
808         }
809
810         return this.readOnly;
811     }
812
813     /**
814      * @see Connection#setSavepoint()
815      */

816     public java.sql.Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
817         throw new NotImplemented();
818     }
819
820     /**
821      * @see Connection#setSavepoint(String)
822      */

823     public java.sql.Savepoint JavaDoc setSavepoint(String JavaDoc arg0)
824         throws SQLException JavaDoc {
825         throw new NotImplemented();
826     }
827
828     /**
829      * DOCUMENT ME!
830      *
831      * @return DOCUMENT ME!
832      */

833     public TimeZone JavaDoc getServerTimezone() {
834         return this.serverTimezone;
835     }
836
837     /**
838      * DOCUMENT ME!
839      *
840      * @param level DOCUMENT ME!
841      *
842      * @throws java.sql.SQLException DOCUMENT ME!
843      * @throws SQLException DOCUMENT ME!
844      */

845     public void setTransactionIsolation(int level) throws java.sql.SQLException JavaDoc {
846         if (Driver.TRACE) {
847             Object JavaDoc[] args = { new Integer JavaDoc(level) };
848             Debug.methodCall(this, "setTransactionIsolation", args);
849         }
850
851         checkClosed();
852
853         if (this.hasIsolationLevels) {
854             StringBuffer JavaDoc sql = new StringBuffer JavaDoc(
855                     "SET SESSION TRANSACTION ISOLATION LEVEL ");
856
857             switch (level) {
858             case java.sql.Connection.TRANSACTION_NONE:
859                 throw new SQLException JavaDoc("Transaction isolation level "
860                     + "NONE not supported by MySQL");
861
862             case java.sql.Connection.TRANSACTION_READ_COMMITTED:
863                 sql.append("READ COMMITTED");
864
865                 break;
866
867             case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:
868                 sql.append("READ UNCOMMITTED");
869
870                 break;
871
872             case java.sql.Connection.TRANSACTION_REPEATABLE_READ:
873                 sql.append("REPEATABLE READ");
874
875                 break;
876
877             case java.sql.Connection.TRANSACTION_SERIALIZABLE:
878                 sql.append("SERIALIZABLE");
879
880                 break;
881
882             default:
883                 throw new SQLException JavaDoc("Unsupported transaction "
884                     + "isolation level '" + level + "'", "S1C00");
885             }
886
887             execSQL(sql.toString(), -1, this.database);
888             isolationLevel = level;
889         } else {
890             throw new java.sql.SQLException JavaDoc("Transaction Isolation Levels are "
891                 + "not supported on MySQL versions older than 3.23.36.", "S1C00");
892         }
893     }
894
895     /**
896      * Get this Connection's current transaction isolation mode.
897      *
898      * @return the current TRANSACTION_ mode value
899      *
900      * @exception java.sql.SQLException if a database access error occurs
901      * @throws SQLException DOCUMENT ME!
902      */

903     public int getTransactionIsolation() throws java.sql.SQLException JavaDoc {
904         if (Driver.TRACE) {
905             Object JavaDoc[] args = new Object JavaDoc[0];
906             Debug.methodCall(this, "getTransactionIsolation", args);
907             Debug.returnValue(this, "getTransactionIsolation",
908                 new Integer JavaDoc(isolationLevel));
909         }
910
911         if (this.hasIsolationLevels) {
912             java.sql.Statement JavaDoc stmt = null;
913             java.sql.ResultSet JavaDoc rs = null;
914
915             try {
916                 stmt = this.createStatement();
917
918                 if (stmt.getMaxRows() != 0) {
919                     stmt.setMaxRows(0);
920                 }
921
922                 String JavaDoc query = null;
923
924                 if (this.io.versionMeetsMinimum(4, 0, 3)) {
925                     query = "SHOW VARIABLES LIKE 'tx_isolation'";
926                 } else {
927                     query = "SHOW VARIABLES LIKE 'transaction_isolation'";
928                 }
929
930                 rs = stmt.executeQuery(query);
931
932                 if (rs.next()) {
933                     String JavaDoc s = rs.getString(2);
934
935                     if (s != null) {
936                         Integer JavaDoc intTI = (Integer JavaDoc) mapTransIsolationName2Value
937                             .get(s);
938
939                         if (intTI != null) {
940                             return intTI.intValue();
941                         }
942                     }
943
944                     throw new SQLException JavaDoc(
945                         "Could not map transaction isolation '" + s
946                         + " to a valid JDBC level.",
947                         SQLError.SQL_STATE_GENERAL_ERROR);
948                 } else {
949                     throw new SQLException JavaDoc("Could not retrieve transaction isolation level from server",
950                         SQLError.SQL_STATE_GENERAL_ERROR);
951                 }
952             } finally {
953                 if (rs != null) {
954                     try {
955                         rs.close();
956                     } catch (Exception JavaDoc ex) {
957                         // ignore
958
}
959
960                     rs = null;
961                 }
962
963                 if (stmt != null) {
964                     try {
965                         stmt.close();
966                     } catch (Exception JavaDoc ex) {
967                         // ignore
968
}
969
970                     stmt = null;
971                 }
972             }
973         }
974
975         return isolationLevel;
976     }
977
978     /**
979      * JDBC 2.0 Install a type-map object as the default type-map for this
980      * connection
981      *
982      * @param map the type mapping
983      *
984      * @throws SQLException if a database error occurs.
985      */

986     public void setTypeMap(java.util.Map JavaDoc map) throws SQLException JavaDoc {
987         this.typeMap = map;
988     }
989
990     /**
991      * JDBC 2.0 Get the type-map object associated with this connection. By
992      * default, the map returned is empty.
993      *
994      * @return the type map
995      *
996      * @throws SQLException if a database error occurs
997      */

998     public synchronized java.util.Map JavaDoc getTypeMap() throws SQLException JavaDoc {
999         if (this.typeMap == null) {
1000            this.typeMap = new HashMap JavaDoc();
1001        }
1002
1003        return this.typeMap;
1004    }
1005
1006    /**
1007     * The first warning reported by calls on this Connection is returned.
1008     * <B>Note:</B> Sebsequent warnings will be changed to this
1009     * java.sql.SQLWarning
1010     *
1011     * @return the first java.sql.SQLWarning or null
1012     *
1013     * @exception java.sql.SQLException if a database access error occurs
1014     */

1015    public java.sql.SQLWarning JavaDoc getWarnings() throws java.sql.SQLException JavaDoc {
1016        if (Driver.TRACE) {
1017            Object JavaDoc[] args = new Object JavaDoc[0];
1018            Debug.methodCall(this, "getWarnings", args);
1019            Debug.returnValue(this, "getWarnings", null);
1020        }
1021
1022        return null;
1023    }
1024
1025    /**
1026     * Allow use of LOAD LOCAL INFILE?
1027     *
1028     * @return true if allowLoadLocalInfile was set to true.
1029     */

1030    public boolean allowLoadLocalInfile() {
1031        return this.allowLoadLocalInfile;
1032    }
1033
1034    /**
1035     * DOCUMENT ME!
1036     *
1037     * @return DOCUMENT ME!
1038     */

1039    public boolean capitalizeDBMDTypes() {
1040        return this.capitalizeDBMDTypes;
1041    }
1042
1043    /**
1044     * After this call, getWarnings returns null until a new warning is
1045     * reported for this connection.
1046     *
1047     * @exception java.sql.SQLException if a database access error occurs
1048     */

1049    public void clearWarnings() throws java.sql.SQLException JavaDoc {
1050        if (Driver.TRACE) {
1051            Object JavaDoc[] args = new Object JavaDoc[0];
1052            Debug.methodCall(this, "clearWarnings", args);
1053        }
1054
1055        // firstWarning = null;
1056
}
1057
1058    /**
1059     * In some cases, it is desirable to immediately release a Connection's
1060     * database and JDBC resources instead of waiting for them to be
1061     * automatically released (cant think why off the top of my head)
1062     * <B>Note:</B> A Connection is automatically closed when it is garbage
1063     * collected. Certain fatal errors also result in a closed connection.
1064     *
1065     * @exception java.sql.SQLException if a database access error occurs
1066     */

1067    public void close() throws java.sql.SQLException JavaDoc {
1068        if (this.explicitCloseLocation == null) {
1069            this.explicitCloseLocation = new Throwable JavaDoc();
1070        }
1071
1072        realClose(true, true);
1073    }
1074
1075    /**
1076     * The method commit() makes all changes made since the previous
1077     * commit/rollback permanent and releases any database locks currently
1078     * held by the Connection. This method should only be used when
1079     * auto-commit has been disabled.
1080     *
1081     * <p>
1082     * <b>Note:</b> MySQL does not support transactions, so this method is a
1083     * no-op.
1084     * </p>
1085     *
1086     * @exception java.sql.SQLException if a database access error occurs
1087     * @throws SQLException DOCUMENT ME!
1088     *
1089     * @see setAutoCommit
1090     */

1091    public void commit() throws java.sql.SQLException JavaDoc {
1092        if (Driver.TRACE) {
1093            Object JavaDoc[] args = new Object JavaDoc[0];
1094            Debug.methodCall(this, "commit", args);
1095        }
1096
1097        checkClosed();
1098
1099        try {
1100            // no-op if _relaxAutoCommit == true
1101
if (this.autoCommit && !this.relaxAutoCommit) {
1102                throw new SQLException JavaDoc("Can't call commit when autocommit=true",
1103                    SQLError.SQL_STATE_GENERAL_ERROR);
1104            } else if (this.transactionsSupported) {
1105                execSQL("commit", -1, this.database);
1106            }
1107        } finally {
1108            if (this.reconnectAtTxEnd) {
1109                pingAndReconnect(true);
1110            }
1111        }
1112
1113        return;
1114    }
1115
1116    //--------------------------JDBC 2.0-----------------------------
1117

1118    /**
1119     * JDBC 2.0 Same as createStatement() above, but allows the default result
1120     * set type and result set concurrency type to be overridden.
1121     *
1122     * @param resultSetType a result set type, see ResultSet.TYPE_XXX
1123     * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX
1124     *
1125     * @return a new Statement object
1126     *
1127     * @exception SQLException if a database-access error occurs.
1128     */

1129    public java.sql.Statement JavaDoc createStatement(int resultSetType,
1130        int resultSetConcurrency) throws SQLException JavaDoc {
1131        checkClosed();
1132
1133        Statement stmt = new com.mysql.jdbc.Statement(this, this.database);
1134        stmt.setResultSetType(resultSetType);
1135        stmt.setResultSetConcurrency(resultSetConcurrency);
1136
1137        return stmt;
1138    }
1139
1140    /**
1141     * SQL statements without parameters are normally executed using Statement
1142     * objects. If the same SQL statement is executed many times, it is more
1143     * efficient to use a PreparedStatement
1144     *
1145     * @return a new Statement object
1146     *
1147     * @throws SQLException passed through from the constructor
1148     */

1149    public java.sql.Statement JavaDoc createStatement() throws SQLException JavaDoc {
1150        return createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
1151            java.sql.ResultSet.CONCUR_READ_ONLY);
1152    }
1153
1154    /**
1155     * @see Connection#createStatement(int, int, int)
1156     */

1157    public java.sql.Statement JavaDoc createStatement(int resultSetType,
1158        int resultSetConcurrency, int resultSetHoldability)
1159        throws SQLException JavaDoc {
1160        if (this.pedantic) {
1161            if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
1162                throw new SQLException JavaDoc("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level",
1163                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1164            }
1165        }
1166
1167        return createStatement(resultSetType, resultSetConcurrency);
1168    }
1169
1170    /**
1171     * DOCUMENT ME!
1172     *
1173     * @throws Throwable DOCUMENT ME!
1174     */

1175    public void finalize() throws Throwable JavaDoc {
1176        cleanup(null);
1177    }
1178
1179    /**
1180     * Is the server configured to use lower-case table names only?
1181     *
1182     * @return true if lower_case_table_names is 'on'
1183     */

1184    public boolean lowerCaseTableNames() {
1185        return this.lowerCaseTableNames;
1186    }
1187
1188    /**
1189     * A driver may convert the JDBC sql grammar into its system's native SQL
1190     * grammar prior to sending it; nativeSQL returns the native form of the
1191     * statement that the driver would have sent.
1192     *
1193     * @param sql a SQL statement that may contain one or more '?' parameter
1194     * placeholders
1195     *
1196     * @return the native form of this statement
1197     *
1198     * @exception java.sql.SQLException if a database access error occurs
1199     */

1200    public String JavaDoc nativeSQL(String JavaDoc sql) throws java.sql.SQLException JavaDoc {
1201        if (Driver.TRACE) {
1202            Object JavaDoc[] args = { sql };
1203            Debug.methodCall(this, "nativeSQL", args);
1204            Debug.returnValue(this, "nativeSQL", sql);
1205        }
1206
1207        return EscapeProcessor.escapeSQL(sql,
1208            getIO().versionMeetsMinimum(4, 0, 2));
1209    }
1210
1211    /**
1212     * DOCUMENT ME!
1213     *
1214     * @param sql DOCUMENT ME!
1215     *
1216     * @return DOCUMENT ME!
1217     *
1218     * @throws java.sql.SQLException DOCUMENT ME!
1219     */

1220    public java.sql.CallableStatement JavaDoc prepareCall(String JavaDoc sql)
1221        throws java.sql.SQLException JavaDoc {
1222        if (this.getUseUltraDevWorkAround()) {
1223            return new UltraDevWorkAround(prepareStatement(sql));
1224        } else {
1225            throw new java.sql.SQLException JavaDoc("Callable statments not "
1226                + "supported.", "S1C00");
1227        }
1228    }
1229
1230    /**
1231     * JDBC 2.0 Same as prepareCall() above, but allows the default result set
1232     * type and result set concurrency type to be overridden.
1233     *
1234     * @param sql the SQL representing the callable statement
1235     * @param resultSetType a result set type, see ResultSet.TYPE_XXX
1236     * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX
1237     *
1238     * @return a new CallableStatement object containing the pre-compiled SQL
1239     * statement
1240     *
1241     * @exception SQLException if a database-access error occurs.
1242     */

1243    public java.sql.CallableStatement JavaDoc prepareCall(String JavaDoc sql,
1244        int resultSetType, int resultSetConcurrency) throws SQLException JavaDoc {
1245        return prepareCall(sql);
1246    }
1247
1248    /**
1249     * @see Connection#prepareCall(String, int, int, int)
1250     */

1251    public java.sql.CallableStatement JavaDoc prepareCall(String JavaDoc sql,
1252        int resultSetType, int resultSetConcurrency, int resultSetHoldability)
1253        throws SQLException JavaDoc {
1254        if (this.pedantic) {
1255            if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
1256                throw new SQLException JavaDoc("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level",
1257                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1258            }
1259        }
1260
1261        throw new NotImplemented();
1262    }
1263
1264    /**
1265     * A SQL statement with or without IN parameters can be pre-compiled and
1266     * stored in a PreparedStatement object. This object can then be used to
1267     * efficiently execute this statement multiple times.
1268     *
1269     * <p>
1270     * <B>Note:</B> This method is optimized for handling parametric SQL
1271     * statements that benefit from precompilation if the driver supports
1272     * precompilation. In this case, the statement is not sent to the database
1273     * until the PreparedStatement is executed. This has no direct effect on
1274     * users; however it does affect which method throws certain
1275     * java.sql.SQLExceptions
1276     * </p>
1277     *
1278     * <p>
1279     * MySQL does not support precompilation of statements, so they are handled
1280     * by the driver.
1281     * </p>
1282     *
1283     * @param sql a SQL statement that may contain one or more '?' IN parameter
1284     * placeholders
1285     *
1286     * @return a new PreparedStatement object containing the pre-compiled
1287     * statement.
1288     *
1289     * @exception java.sql.SQLException if a database access error occurs.
1290     */

1291    public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql)
1292        throws java.sql.SQLException JavaDoc {
1293        return prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY,
1294            java.sql.ResultSet.CONCUR_READ_ONLY);
1295    }
1296
1297    /**
1298     * JDBC 2.0 Same as prepareStatement() above, but allows the default result
1299     * set type and result set concurrency type to be overridden.
1300     *
1301     * @param sql the SQL query containing place holders
1302     * @param resultSetType a result set type, see ResultSet.TYPE_XXX
1303     * @param resultSetConcurrency a concurrency type, see ResultSet.CONCUR_XXX
1304     *
1305     * @return a new PreparedStatement object containing the pre-compiled SQL
1306     * statement
1307     *
1308     * @exception SQLException if a database-access error occurs.
1309     */

1310    public synchronized java.sql.PreparedStatement JavaDoc prepareStatement(
1311        String JavaDoc sql, int resultSetType, int resultSetConcurrency)
1312        throws SQLException JavaDoc {
1313        checkClosed();
1314
1315        PreparedStatement pStmt = null;
1316
1317        if (this.cachePreparedStatements) {
1318            PreparedStatement.ParseInfo pStmtInfo = (PreparedStatement.ParseInfo) cachedPreparedStatementParams
1319                .get(sql);
1320
1321            if (pStmtInfo == null) {
1322                pStmt = new com.mysql.jdbc.PreparedStatement(this, sql,
1323                        this.database);
1324
1325                PreparedStatement.ParseInfo parseInfo = pStmt.getParseInfo();
1326
1327                if (parseInfo.statementLength < this.preparedStatementCacheMaxSqlSize) {
1328                    if (this.cachedPreparedStatementParams.size() >= 25) {
1329                        Iterator JavaDoc oldestIter = this.cachedPreparedStatementParams.keySet()
1330                                                                                .iterator();
1331                        long lruTime = Long.MAX_VALUE;
1332                        String JavaDoc oldestSql = null;
1333
1334                        while (oldestIter.hasNext()) {
1335                            String JavaDoc sqlKey = (String JavaDoc) oldestIter.next();
1336                            PreparedStatement.ParseInfo lruInfo = (PreparedStatement.ParseInfo) this.cachedPreparedStatementParams
1337                                .get(sqlKey);
1338
1339                            if (lruInfo.lastUsed < lruTime) {
1340                                lruTime = lruInfo.lastUsed;
1341                                oldestSql = sqlKey;
1342                            }
1343                        }
1344
1345                        if (oldestSql != null) {
1346                            this.cachedPreparedStatementParams.remove(oldestSql);
1347                        }
1348                    }
1349
1350                    cachedPreparedStatementParams.put(sql, pStmt.getParseInfo());
1351                }
1352            } else {
1353                pStmtInfo.lastUsed = System.currentTimeMillis();
1354                pStmt = new com.mysql.jdbc.PreparedStatement(this, sql,
1355                        this.database, pStmtInfo);
1356            }
1357        } else {
1358            pStmt = new com.mysql.jdbc.PreparedStatement(this, sql,
1359                    this.database);
1360        }
1361
1362        //
1363
// FIXME: Create warnings if can't create results of the given
1364
// type or concurrency
1365
//
1366
pStmt.setResultSetType(resultSetType);
1367        pStmt.setResultSetConcurrency(resultSetConcurrency);
1368
1369        return pStmt;
1370    }
1371
1372    /**
1373     * @see Connection#prepareStatement(String, int, int, int)
1374     */

1375    public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
1376        int resultSetType, int resultSetConcurrency, int resultSetHoldability)
1377        throws SQLException JavaDoc {
1378        if (this.pedantic) {
1379            if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
1380                throw new SQLException JavaDoc("HOLD_CUSRORS_OVER_COMMIT is only supported holdability level",
1381                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1382            }
1383        }
1384
1385        return prepareStatement(sql, resultSetType, resultSetConcurrency);
1386    }
1387
1388    /**
1389     * @see Connection#prepareStatement(String, int)
1390     */

1391    public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
1392        int autoGenKeyIndex) throws SQLException JavaDoc {
1393        java.sql.PreparedStatement JavaDoc pStmt = prepareStatement(sql);
1394
1395        ((com.mysql.jdbc.PreparedStatement) pStmt).setRetrieveGeneratedKeys(autoGenKeyIndex == Statement.RETURN_GENERATED_KEYS);
1396
1397        return pStmt;
1398    }
1399
1400    /**
1401     * @see Connection#prepareStatement(String, int[])
1402     */

1403    public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
1404        int[] autoGenKeyIndexes) throws SQLException JavaDoc {
1405        java.sql.PreparedStatement JavaDoc pStmt = prepareStatement(sql);
1406
1407        ((com.mysql.jdbc.PreparedStatement) pStmt).setRetrieveGeneratedKeys((autoGenKeyIndexes != null)
1408            && (autoGenKeyIndexes.length > 0));
1409
1410        return pStmt;
1411    }
1412
1413    /**
1414     * @see Connection#prepareStatement(String, String[])
1415     */

1416    public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
1417        String JavaDoc[] autoGenKeyColNames) throws SQLException JavaDoc {
1418        java.sql.PreparedStatement JavaDoc pStmt = prepareStatement(sql);
1419
1420        ((com.mysql.jdbc.PreparedStatement) pStmt).setRetrieveGeneratedKeys((autoGenKeyColNames != null)
1421            && (autoGenKeyColNames.length > 0));
1422
1423        return pStmt;
1424    }
1425
1426    /**
1427     * @see Connection#releaseSavepoint(Savepoint)
1428     */

1429    public void releaseSavepoint(Savepoint JavaDoc arg0) throws SQLException JavaDoc {
1430        throw new NotImplemented();
1431    }
1432
1433    /**
1434     * The method rollback() drops all changes made since the previous
1435     * commit/rollback and releases any database locks currently held by the
1436     * Connection.
1437     *
1438     * @exception java.sql.SQLException if a database access error occurs
1439     * @throws SQLException DOCUMENT ME!
1440     *
1441     * @see commit
1442     */

1443    public void rollback() throws java.sql.SQLException JavaDoc {
1444        if (Driver.TRACE) {
1445            Object JavaDoc[] args = new Object JavaDoc[0];
1446            Debug.methodCall(this, "rollback", args);
1447        }
1448
1449        checkClosed();
1450
1451        try {
1452            // no-op if _relaxAutoCommit == true
1453
if (this.autoCommit && !this.relaxAutoCommit) {
1454                throw new SQLException JavaDoc("Can't call rollback when autocommit=true",
1455                    SQLError.SQL_STATE_GENERAL_ERROR);
1456            } else if (this.transactionsSupported) {
1457                try {
1458                    rollbackNoChecks();
1459                } catch (SQLException JavaDoc sqlEx) {
1460                    // We ignore non-transactional tables if told to do so
1461
if (this.ignoreNonTxTables
1462                            && (sqlEx.getErrorCode() != MysqlDefs.ER_WARNING_NOT_COMPLETE_ROLLBACK)) {
1463                        throw sqlEx;
1464                    }
1465                }
1466            }
1467        } finally {
1468            if (this.reconnectAtTxEnd) {
1469                pingAndReconnect(true);
1470            }
1471        }
1472    }
1473
1474    /**
1475     * @see Connection#rollback(Savepoint)
1476     */

1477    public void rollback(Savepoint JavaDoc arg0) throws SQLException JavaDoc {
1478        throw new NotImplemented();
1479    }
1480
1481    /**
1482     * Used by MiniAdmin to shutdown a MySQL server
1483     *
1484     * @throws SQLException if the command can not be issued.
1485     */

1486    public void shutdownServer() throws SQLException JavaDoc {
1487        try {
1488            this.io.sendCommand(MysqlDefs.SHUTDOWN, null, null);
1489        } catch (Exception JavaDoc ex) {
1490            throw new SQLException JavaDoc("Unhandled exception '" + ex.toString()
1491                + "'", SQLError.SQL_STATE_GENERAL_ERROR);
1492        }
1493    }
1494
1495    /**
1496     * DOCUMENT ME!
1497     *
1498     * @return DOCUMENT ME!
1499     */

1500    public boolean supportsIsolationLevel() {
1501        return this.hasIsolationLevels;
1502    }
1503
1504    /**
1505     * DOCUMENT ME!
1506     *
1507     * @return DOCUMENT ME!
1508     */

1509    public boolean supportsQuotedIdentifiers() {
1510        return this.hasQuotedIdentifiers;
1511    }
1512
1513    /**
1514     * DOCUMENT ME!
1515     *
1516     * @return DOCUMENT ME!
1517     */

1518    public boolean supportsTransactions() {
1519        return this.transactionsSupported;
1520    }
1521
1522    /**
1523     * Should we use compression?
1524     *
1525     * @return should we use compression to communicate with the server?
1526     */

1527    public boolean useCompression() {
1528        return this.useCompression;
1529    }
1530
1531    /**
1532     * Returns the paranoidErrorMessages.
1533     *
1534     * @return boolean if we should be paranoid about error messages.
1535     */

1536    public boolean useParanoidErrorMessages() {
1537        return paranoid;
1538    }
1539
1540    /**
1541     * Should we use SSL?
1542     *
1543     * @return should we use SSL to communicate with the server?
1544     */

1545    public boolean useSSL() {
1546        return this.useSSL;
1547    }
1548
1549    /**
1550     * Should we enable work-arounds for floating point rounding errors in the
1551     * server?
1552     *
1553     * @return should we use floating point work-arounds?
1554     */

1555    public boolean useStrictFloatingPoint() {
1556        return this.strictFloatingPoint;
1557    }
1558
1559    /**
1560     * Returns the strictUpdates value.
1561     *
1562     * @return boolean
1563     */

1564    public boolean useStrictUpdates() {
1565        return strictUpdates;
1566    }
1567
1568    /**
1569     * DOCUMENT ME!
1570     *
1571     * @return DOCUMENT ME!
1572     */

1573    public boolean useTimezone() {
1574        return this.useTimezone;
1575    }
1576
1577    /**
1578     * Should unicode character mapping be used ?
1579     *
1580     * @return should we use Unicode character mapping?
1581     */

1582    public boolean useUnicode() {
1583        return this.doUnicode;
1584    }
1585
1586    /**
1587     * DOCUMENT ME!
1588     *
1589     * @return Returns the defaultTimeZone.
1590     */

1591    protected TimeZone JavaDoc getDefaultTimeZone() {
1592        return defaultTimeZone;
1593    }
1594
1595    /**
1596     * Returns the IO channel to the server
1597     *
1598     * @return the IO channel to the server
1599     *
1600     * @throws SQLException if the connection is closed.
1601     */

1602    protected MysqlIO getIO() throws SQLException JavaDoc {
1603        if ((this.io == null) || this.isClosed) {
1604            throw new SQLException JavaDoc("Operation not allowed on closed connection",
1605                "08003");
1606        }
1607
1608        return this.io;
1609    }
1610
1611    protected int getNetWriteTimeout() {
1612        String JavaDoc netWriteTimeoutStr = (String JavaDoc) this.serverVariables.get(
1613                "net_write_timeout");
1614
1615        if (netWriteTimeoutStr != null) {
1616            try {
1617                return Integer.parseInt(netWriteTimeoutStr);
1618            } catch (NumberFormatException JavaDoc nfe) {
1619                return Integer.MAX_VALUE;
1620            }
1621        } else {
1622            return Integer.MAX_VALUE;
1623        }
1624    }
1625
1626    /**
1627     * Is this connection using unbuffered input?
1628     *
1629     * @return whether or not to use buffered input streams
1630     */

1631    protected boolean isUsingUnbufferedInput() {
1632        return this.useUnbufferedInput;
1633    }
1634
1635    /**
1636     * Creates an IO channel to the server
1637     *
1638     * @param isForReconnect is this request for a re-connect
1639     *
1640     * @return a new MysqlIO instance connected to a server
1641     *
1642     * @throws SQLException if a database access error occurs
1643     */

1644    protected com.mysql.jdbc.MysqlIO createNewIO(boolean isForReconnect)
1645        throws SQLException JavaDoc {
1646        MysqlIO newIo = null;
1647
1648        if (!highAvailability && !this.failedOver) {
1649            for (int hostIndex = 0; hostIndex < hostListSize; hostIndex++) {
1650                try {
1651                    this.io = new MysqlIO(this.hostList.get(hostIndex).toString(),
1652                            this.port, this.socketFactoryClassName, this.props,
1653                            this, this.socketTimeout);
1654                    this.io.doHandshake(this.user, this.password, this.database);
1655                    this.isClosed = false;
1656
1657                    if (this.database.length() != 0) {
1658                        this.io.sendCommand(MysqlDefs.INIT_DB, this.database,
1659                            null);
1660                    }
1661
1662                    // save state from old connection
1663
boolean autoCommit = getAutoCommit();
1664                    int oldIsolationLevel = getTransactionIsolation();
1665                    boolean oldReadOnly = isReadOnly();
1666                    String JavaDoc oldCatalog = getCatalog();
1667
1668                    // Server properties might be different
1669
// from previous connection, so initialize
1670
// again...
1671
initializePropsFromServer(this.props);
1672
1673                    if (isForReconnect) {
1674                        // Restore state from old connection
1675
setAutoCommit(autoCommit);
1676
1677                        if (this.hasIsolationLevels) {
1678                            setTransactionIsolation(oldIsolationLevel);
1679                        }
1680
1681                        setCatalog(oldCatalog);
1682                    }
1683
1684                    if (hostIndex != 0) {
1685                        setFailedOverState();
1686                    } else {
1687                        this.failedOver = false;
1688
1689                        if (hostListSize > 1) {
1690                            setReadOnly(false);
1691                        } else {
1692                            setReadOnly(oldReadOnly);
1693                        }
1694                    }
1695
1696                    break; // low-level connection succeeded
1697
} catch (SQLException JavaDoc sqlEx) {
1698                    if (this.io != null) {
1699                        this.io.forceClose();
1700                    }
1701
1702                    String JavaDoc sqlState = sqlEx.getSQLState();
1703
1704                    if ((sqlState == null)
1705                            || !sqlState.equals(
1706                                SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE)) {
1707                        throw sqlEx;
1708                    }
1709
1710                    if ((hostListSize - 1) == hostIndex) {
1711                        throw sqlEx;
1712                    }
1713                } catch (Exception JavaDoc unknownException) {
1714                    if (this.io != null) {
1715                        this.io.forceClose();
1716                    }
1717
1718                    if ((hostListSize - 1) == hostIndex) {
1719                        throw new SQLException JavaDoc(
1720                            "Unable to connect to any hosts due to exception: "
1721                            + unknownException.toString(),
1722                            SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE);
1723                    }
1724                }
1725            }
1726        } else {
1727            double timeout = this.initialTimeout;
1728            boolean connectionGood = false;
1729            Exception JavaDoc connectionException = null;
1730
1731            for (int hostIndex = 0;
1732                    (hostIndex < hostListSize) && !connectionGood;
1733                    hostIndex++) {
1734                for (int attemptCount = 0;
1735                        !connectionGood && (attemptCount < this.maxReconnects);
1736                        attemptCount++) {
1737                    try {
1738                        if (this.io != null) {
1739                            this.io.forceClose();
1740                        }
1741
1742                        this.io = new MysqlIO(this.hostList.get(hostIndex)
1743                                                           .toString(),
1744                                this.port, this.socketFactoryClassName,
1745                                this.props, this, this.socketTimeout);
1746                        this.io.doHandshake(this.user, this.password,
1747                            this.database);
1748
1749                        if (this.database.length() != 0) {
1750                            this.io.sendCommand(MysqlDefs.INIT_DB,
1751                                this.database, null);
1752                        }
1753
1754                        ping();
1755                        this.isClosed = false;
1756
1757                        // save state from old connection
1758
boolean autoCommit = getAutoCommit();
1759                        int oldIsolationLevel = getTransactionIsolation();
1760                        boolean oldReadOnly = isReadOnly();
1761                        String JavaDoc oldCatalog = getCatalog();
1762
1763                        // Server properties might be different
1764
// from previous connection, so initialize
1765
// again...
1766
initializePropsFromServer(this.props);
1767
1768                        if (isForReconnect) {
1769                            // Restore state from old connection
1770
setAutoCommit(autoCommit);
1771
1772                            if (this.hasIsolationLevels) {
1773                                setTransactionIsolation(oldIsolationLevel);
1774                            }
1775
1776                            setCatalog(oldCatalog);
1777                        }
1778
1779                        connectionGood = true;
1780
1781                        if (hostIndex != 0) {
1782                            setFailedOverState();
1783                        } else {
1784                            this.failedOver = false;
1785
1786                            if (hostListSize > 1) {
1787                                setReadOnly(false);
1788                            } else {
1789                                setReadOnly(oldReadOnly);
1790                            }
1791                        }
1792
1793                        break;
1794                    } catch (Exception JavaDoc EEE) {
1795                        connectionException = EEE;
1796                        connectionGood = false;
1797                    }
1798
1799                    if (!connectionGood) {
1800                        try {
1801                            Thread.sleep((long) timeout * 1000);
1802                            timeout = timeout * 2;
1803                        } catch (InterruptedException JavaDoc IE) {
1804                            ;
1805                        }
1806                    }
1807                }
1808
1809                if (!connectionGood) {
1810                    // We've really failed!
1811
throw new SQLException JavaDoc(
1812                        "Server connection failure during transaction. Due to underlying exception: '"
1813                        + connectionException + "'.\nAttempted reconnect "
1814                        + this.maxReconnects + " times. Giving up.",
1815                        SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE);
1816                }
1817            }
1818        }
1819
1820        if (paranoid && !highAvailability && (hostListSize <= 1)) {
1821            password = null;
1822            user = null;
1823        }
1824
1825        return newIo;
1826    }
1827
1828    /**
1829     * Closes connection and frees resources.
1830     *
1831     * @param calledExplicitly is this being called from close()
1832     * @param issueRollback should a rollback() be issued?
1833     *
1834     * @throws SQLException if an error occurs
1835     */

1836    protected void realClose(boolean calledExplicitly, boolean issueRollback)
1837        throws SQLException JavaDoc {
1838        if (Driver.TRACE) {
1839            Object JavaDoc[] args = new Object JavaDoc[] {
1840                    new Boolean JavaDoc(calledExplicitly), new Boolean JavaDoc(issueRollback)
1841                };
1842            Debug.methodCall(this, "realClose", args);
1843        }
1844
1845        SQLException JavaDoc sqlEx = null;
1846
1847        if (!isClosed() && !getAutoCommit() && issueRollback) {
1848            try {
1849                rollback();
1850            } catch (SQLException JavaDoc ex) {
1851                sqlEx = ex;
1852            }
1853        }
1854
1855        if (this.io != null) {
1856            try {
1857                this.io.quit();
1858            } catch (Exception JavaDoc e) {
1859                ;
1860            }
1861
1862            this.io = null;
1863        }
1864
1865        if (this.cachedPreparedStatementParams != null) {
1866            this.cachedPreparedStatementParams.clear();
1867            this.cachedPreparedStatementParams = null;
1868        }
1869
1870        this.isClosed = true;
1871
1872        if (sqlEx != null) {
1873            throw sqlEx;
1874        }
1875    }
1876
1877    /**
1878     * Returns the locally mapped instance of a charset converter (to avoid
1879     * overhead of static synchronization).
1880     *
1881     * @param javaEncodingName the encoding name to retrieve
1882     *
1883     * @return a character converter, or null if one couldn't be mapped.
1884     */

1885    synchronized SingleByteCharsetConverter getCharsetConverter(
1886        String JavaDoc javaEncodingName) {
1887        SingleByteCharsetConverter converter = (SingleByteCharsetConverter) this.charsetConverterMap
1888            .get(javaEncodingName);
1889
1890        if (converter == CHARSET_CONVERTER_NOT_AVAILABLE_MARKER) {
1891            return null;
1892        }
1893
1894        if (converter == null) {
1895            try {
1896                converter = SingleByteCharsetConverter.getInstance(javaEncodingName);
1897
1898                if (converter == null) {
1899                    this.charsetConverterMap.put(javaEncodingName,
1900                        CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
1901                }
1902
1903                this.charsetConverterMap.put(javaEncodingName, converter);
1904            } catch (UnsupportedEncodingException JavaDoc unsupEncEx) {
1905                this.charsetConverterMap.put(javaEncodingName,
1906                    CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
1907
1908                converter = null;
1909            }
1910        }
1911
1912        return converter;
1913    }
1914
1915    /**
1916     * Returns the maximum packet size the MySQL server will accept
1917     *
1918     * @return DOCUMENT ME!
1919     */

1920    int getMaxAllowedPacket() {
1921        return this.maxAllowedPacket;
1922    }
1923
1924    /**
1925     * DOCUMENT ME!
1926     *
1927     * @return the max rows to return for statements (by default)
1928     */

1929    int getMaxRows() {
1930        return this.maxRows;
1931    }
1932
1933    /**
1934     * Returns the Mutex all queries are locked against
1935     *
1936     * @return DOCUMENT ME!
1937     *
1938     * @throws SQLException DOCUMENT ME!
1939     */

1940    Object JavaDoc getMutex() throws SQLException JavaDoc {
1941        if (this.io == null) {
1942            throw new SQLException JavaDoc("Connection.close() has already been called. Invalid operation in this state.",
1943                "08003");
1944        }
1945
1946        return this.mutex;
1947    }
1948
1949    /**
1950     * Returns the packet buffer size the MySQL server reported upon connection
1951     *
1952     * @return DOCUMENT ME!
1953     */

1954    int getNetBufferLength() {
1955        return this.netBufferLength;
1956    }
1957
1958    boolean isPedantic() {
1959        return this.pedantic;
1960    }
1961
1962    void setReadInfoMsgEnabled(boolean flag) {
1963        this.readInfoMsg = flag;
1964    }
1965
1966    boolean isReadInfoMsgEnabled() {
1967        return this.readInfoMsg;
1968    }
1969
1970    int getServerMajorVersion() {
1971        return this.io.getServerMajorVersion();
1972    }
1973
1974    int getServerMinorVersion() {
1975        return this.io.getServerMinorVersion();
1976    }
1977
1978    int getServerSubMinorVersion() {
1979        return this.io.getServerSubMinorVersion();
1980    }
1981
1982    String JavaDoc getServerVersion() {
1983        return this.io.getServerVersion();
1984    }
1985
1986    String JavaDoc getURL() {
1987        return this.myURL;
1988    }
1989
1990    /**
1991     * Set whether or not this connection should use SSL
1992     *
1993     * @param flag DOCUMENT ME!
1994     */

1995    void setUseSSL(boolean flag) {
1996        this.useSSL = flag;
1997    }
1998
1999    String JavaDoc getUser() {
2000        return this.user;
2001    }
2002
2003    boolean alwaysClearStream() {
2004        return this.alwaysClearStream;
2005    }
2006
2007    boolean continueBatchOnError() {
2008        return this.continueBatchOnError;
2009    }
2010
2011    /**
2012     * Send a query to the server. Returns one of the ResultSet objects. This
2013     * is synchronized, so Statement's queries will be serialized.
2014     *
2015     * @param sql the SQL statement to be executed
2016     * @param maxRowsToRetreive DOCUMENT ME!
2017     * @param catalog DOCUMENT ME!
2018     *
2019     * @return a ResultSet holding the results
2020     *
2021     * @exception java.sql.SQLException if a database error occurs
2022     */

2023    ResultSet execSQL(String JavaDoc sql, int maxRowsToRetreive, String JavaDoc catalog)
2024        throws java.sql.SQLException JavaDoc {
2025        if (Driver.TRACE) {
2026            Object JavaDoc[] args = { sql, new Integer JavaDoc(maxRowsToRetreive) };
2027            Debug.methodCall(this, "execSQL", args);
2028        }
2029
2030        return execSQL(sql, maxRowsToRetreive, null,
2031            java.sql.ResultSet.CONCUR_READ_ONLY, catalog);
2032    }
2033
2034    ResultSet execSQL(String JavaDoc sql, int maxRows, int resultSetType,
2035        boolean streamResults, boolean queryIsSelectOnly, String JavaDoc catalog)
2036        throws SQLException JavaDoc {
2037        return execSQL(sql, maxRows, null, resultSetType, streamResults,
2038            queryIsSelectOnly, catalog);
2039    }
2040
2041    ResultSet execSQL(String JavaDoc sql, int maxRows, Buffer packet, String JavaDoc catalog)
2042        throws java.sql.SQLException JavaDoc {
2043        return execSQL(sql, maxRows, packet,
2044            java.sql.ResultSet.CONCUR_READ_ONLY, catalog);
2045    }
2046
2047    ResultSet execSQL(String JavaDoc sql, int maxRows, Buffer packet,
2048        int resultSetType, String JavaDoc catalog) throws java.sql.SQLException JavaDoc {
2049        return execSQL(sql, maxRows, packet, resultSetType, true, false, catalog);
2050    }
2051
2052    ResultSet execSQL(String JavaDoc sql, int maxRows, Buffer packet,
2053        int resultSetType, boolean streamResults, boolean queryIsSelectOnly,
2054        String JavaDoc catalog) throws java.sql.SQLException JavaDoc {
2055        if (Driver.TRACE) {
2056            Object JavaDoc[] args = { sql, new Integer JavaDoc(maxRows), packet };
2057            Debug.methodCall(this, "execSQL", args);
2058        }
2059
2060        if ((sql == null) || (sql.length() == 0)) {
2061            if (packet == null) {
2062                throw new SQLException JavaDoc("Query can not be null or empty",
2063                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2064            }
2065        }
2066
2067        //
2068
// Fall-back if the master is back online if we've
2069
// issued queriesBeforeRetryMaster queries since
2070
// we failed over
2071
//
2072
synchronized (this.mutex) {
2073            this.lastQueryFinishedTime = 0; // we're busy!
2074

2075            pingAndReconnect(false);
2076
2077            try {
2078                int realMaxRows = (maxRows == -1) ? MysqlDefs.MAX_ROWS : maxRows;
2079
2080                if (packet == null) {
2081                    String JavaDoc encoding = null;
2082
2083                    if (useUnicode()) {
2084                        encoding = getEncoding();
2085                    }
2086
2087                    return this.io.sqlQuery(sql, realMaxRows, encoding, this,
2088                        resultSetType, streamResults, catalog);
2089                } else {
2090                    return this.io.sqlQueryDirect(packet, realMaxRows, this,
2091                        resultSetType, streamResults, catalog);
2092                }
2093            } catch (java.sql.SQLException JavaDoc sqlE) {
2094                // don't clobber SQL exceptions
2095
String JavaDoc sqlState = sqlE.getSQLState();
2096
2097                if ((sqlState != null)
2098                        && sqlState.equals(
2099                            SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE)) {
2100                    cleanup(sqlE);
2101                }
2102
2103                throw sqlE;
2104            } catch (Exception JavaDoc ex) {
2105                if (ex instanceof IOException JavaDoc) {
2106                    cleanup(ex);
2107                }
2108
2109                String JavaDoc exceptionType = ex.getClass().getName();
2110                String JavaDoc exceptionMessage = ex.getMessage();
2111
2112                if (!this.useParanoidErrorMessages()) {
2113                    exceptionMessage += "\n\nNested Stack Trace:\n";
2114                    exceptionMessage += Util.stackTraceToString(ex);
2115                }
2116
2117                throw new java.sql.SQLException JavaDoc(
2118                    "Error during query: Unexpected Exception: "
2119                    + exceptionType + " message given: " + exceptionMessage,
2120                    SQLError.SQL_STATE_GENERAL_ERROR);
2121            } finally {
2122                this.lastQueryFinishedTime = System.currentTimeMillis();
2123            }
2124        }
2125    }
2126
2127    /**
2128     * Has the maxRows value changed?
2129     *
2130     * @param stmt DOCUMENT ME!
2131     */

2132    void maxRowsChanged(Statement stmt) {
2133        synchronized (this.mutex) {
2134            if (this.statementsUsingMaxRows == null) {
2135                this.statementsUsingMaxRows = new HashMap JavaDoc();
2136            }
2137
2138            this.statementsUsingMaxRows.put(stmt, stmt);
2139
2140            this.maxRowsChanged = true;
2141        }
2142    }
2143
2144    /**
2145     * Called by statements on their .close() to let the connection know when
2146     * it is safe to set the connection back to 'default' row limits.
2147     *
2148     * @param stmt the statement releasing it's max-rows requirement
2149     *
2150     * @throws SQLException if a database error occurs issuing the statement
2151     * that sets the limit default.
2152     */

2153    void unsetMaxRows(Statement stmt) throws SQLException JavaDoc {
2154        synchronized (this.mutex) {
2155            if (this.statementsUsingMaxRows != null) {
2156                Object JavaDoc found = this.statementsUsingMaxRows.remove(stmt);
2157
2158                if ((found != null)
2159                        && (this.statementsUsingMaxRows.size() == 0)) {
2160                    execSQL("SET OPTION SQL_SELECT_LIMIT=DEFAULT", -1,
2161                        this.database);
2162                    this.maxRowsChanged = false;
2163                }
2164            }
2165        }
2166    }
2167
2168    boolean useAnsiQuotedIdentifiers() {
2169        return this.useAnsiQuotes;
2170    }
2171
2172    boolean useHostsInPrivileges() {
2173        return this.useHostsInPrivileges;
2174    }
2175
2176    /**
2177     * Has maxRows() been set?
2178     *
2179     * @return DOCUMENT ME!
2180     */

2181    boolean useMaxRows() {
2182        synchronized (this.mutex) {
2183            return this.maxRowsChanged;
2184        }
2185    }
2186
2187    boolean useStreamLengthsInPrepStmts() {
2188        return this.useStreamLengthsInPrepStmts;
2189    }
2190
2191    /**
2192     * Sets state for a failed-over connection
2193     *
2194     * @throws SQLException DOCUMENT ME!
2195     */

2196    private void setFailedOverState() throws SQLException JavaDoc {
2197        // FIXME: User Selectable?
2198
setReadOnly(true);
2199        this.queriesIssuedFailedOver = 0;
2200        this.failedOver = true;
2201        this.masterFailTimeMillis = System.currentTimeMillis();
2202    }
2203
2204    private void checkClosed() throws SQLException JavaDoc {
2205        if (this.isClosed) {
2206            StringBuffer JavaDoc exceptionMessage = new StringBuffer JavaDoc();
2207
2208            exceptionMessage.append(
2209                "No operations allowed after connection closed.");
2210
2211            if (!this.paranoid) {
2212                if (this.forcedCloseReason != null) {
2213                    exceptionMessage.append(
2214                        "\n\nConnection was closed due to the following exception:");
2215                    exceptionMessage.append(Util.stackTraceToString(
2216                            this.forcedCloseReason));
2217                } else if (this.explicitCloseLocation != null) {
2218                    exceptionMessage.append(
2219                        "\n\nConnection was closed explicitly by the application at the following location:");
2220                    exceptionMessage.append(Util.stackTraceToString(
2221                            this.explicitCloseLocation));
2222                }
2223            }
2224
2225            throw new SQLException JavaDoc(exceptionMessage.toString(), "08003");
2226        }
2227    }
2228
2229    /**
2230     * If useUnicode flag is set and explicit client character encoding isn't
2231     * specified then assign encoding from server if any.
2232     *
2233     * @throws SQLException DOCUMENT ME!
2234     */

2235    private void checkServerEncoding() throws SQLException JavaDoc {
2236        if (this.doUnicode && (this.encoding != null)) {
2237            // spec'd by client, don't map, but check
2238
// for character encoding 'overlaps' when using
2239
// pre-4.1 servers
2240
if (!this.io.versionMeetsMinimum(4, 1, 0)) {
2241                if ("ISO8859_2".equals("this.encoding")) {
2242                    throw new SQLException JavaDoc(
2243                        "Character encoding 'ISO8859_2' specified in JDBC URL which maps to multiple MySQL character encodings:"
2244                        + "\n\n" + "* 'latin2'\n" + "* 'czech'\n"
2245                        + "* 'hungarian'\n" + "* 'croat'\n"
2246                        + "\nSpecify one of the above encodings using the 'mysqlEncoding' connection property.",
2247                        SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2248                } else if ("ISO8859_13".equals("this.encoding")) {
2249                    throw new SQLException JavaDoc(
2250                        "Character encoding 'ISO8859_13' specified in JDBC URL which maps to multiple MySQL character encodings:"
2251                        + "\n\n" + "* 'latvian'\n" + "* 'latvian1'\n"
2252                        + "* 'estonia'\n"
2253                        + "\nSpecify one of the above encodings using the 'mysqlEncoding' connection property.",
2254                        SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2255                }
2256            }
2257
2258            return;
2259        }
2260
2261        this.mysqlEncodingName = (String JavaDoc) this.serverVariables.get(
2262                "character_set");
2263
2264        if (this.mysqlEncodingName == null) {
2265            // must be 4.1.1 or newer?
2266
this.mysqlEncodingName = (String JavaDoc) this.serverVariables.get(
2267                    "character_set_client");
2268        }
2269
2270        String JavaDoc javaEncodingName = null;
2271
2272        if (this.mysqlEncodingName != null) {
2273            javaEncodingName = (String JavaDoc) charsetMap.get(this.mysqlEncodingName
2274                    .toUpperCase());
2275        }
2276
2277        //
2278
// First check if we can do the encoding ourselves
2279
//
2280
if (!this.doUnicode && (javaEncodingName != null)) {
2281            SingleByteCharsetConverter converter = getCharsetConverter(javaEncodingName);
2282
2283            if (converter != null) { // we know how to convert this ourselves
2284
this.doUnicode = true; // force the issue
2285
this.encoding = javaEncodingName;
2286
2287                return;
2288            }
2289        }
2290
2291        //
2292
// Now, try and find a Java I/O converter that can do
2293
// the encoding for us
2294
//
2295
if (this.mysqlEncodingName != null) {
2296            if (javaEncodingName == null) {
2297                // We don't have a mapping for it, so try
2298
// and canonicalize the name....
2299
if (Character.isLowerCase(this.mysqlEncodingName.charAt(0))) {
2300                    char[] ach = this.mysqlEncodingName.toCharArray();
2301                    ach[0] = Character.toUpperCase(this.mysqlEncodingName
2302                            .charAt(0));
2303                    this.encoding = new String JavaDoc(ach);
2304                }
2305            }
2306
2307            //
2308
// Attempt to use the encoding, and bail out if it
2309
// can't be used
2310
//
2311
try {
2312                "abc".getBytes(javaEncodingName);
2313                this.encoding = javaEncodingName;
2314                this.doUnicode = true;
2315            } catch (UnsupportedEncodingException JavaDoc UE) {
2316                throw new SQLException JavaDoc(
2317                    "The driver can not map the character encoding '"
2318                    + this.encoding + "' that your server is using "
2319                    + "to a character encoding your JVM understands. You "
2320                    + "can specify this mapping manually by adding \"useUnicode=true\" "
2321                    + "as well as \"characterEncoding=[an_encoding_your_jvm_understands]\" "
2322                    + "to your JDBC URL.",
2323                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2324            }
2325        }
2326    }
2327
2328    /**
2329     * Set transaction isolation level to the value received from server if
2330     * any. Is called by connectionInit(...)
2331     *
2332     * @throws SQLException DOCUMENT ME!
2333     */

2334    private void checkTransactionIsolationLevel() throws SQLException JavaDoc {
2335        String JavaDoc txIsolationName = null;
2336
2337        if (this.io.versionMeetsMinimum(4, 0, 3)) {
2338            txIsolationName = "tx_isolation";
2339        } else {
2340            txIsolationName = "transaction_isolation";
2341        }
2342
2343        String JavaDoc s = (String JavaDoc) this.serverVariables.get(txIsolationName);
2344
2345        if (s != null) {
2346            Integer JavaDoc intTI = (Integer JavaDoc) mapTransIsolationName2Value.get(s);
2347
2348            if (intTI != null) {
2349                isolationLevel = intTI.intValue();
2350            }
2351        }
2352    }
2353
2354    /**
2355     * Destroys this connection and any underlying resources
2356     *
2357     * @param cleanupReason DOCUMENT ME!
2358     */

2359    private void cleanup(Throwable JavaDoc cleanupReason) {
2360        try {
2361            if ((this.io != null) && !isClosed()) {
2362                realClose(false, false);
2363            } else if (this.io != null) {
2364                this.io.forceClose();
2365            }
2366        } catch (SQLException JavaDoc sqlEx) {
2367            // ignore, we're going away.
2368
}
2369
2370        this.isClosed = true;
2371        this.forcedCloseReason = cleanupReason;
2372    }
2373
2374    private void detectFloatingPointStyle() throws SQLException JavaDoc {
2375        java.sql.Statement JavaDoc stmt = null;
2376        java.sql.ResultSet JavaDoc rs = null;
2377
2378        try {
2379            stmt = createStatement();
2380
2381            if (stmt.getMaxRows() != 0) {
2382                stmt.setMaxRows(0);
2383            }
2384
2385            rs = stmt.executeQuery(
2386                    "select round('inf'), round('-inf'), round('nan')");
2387
2388            if (rs.next()) {
2389                String JavaDoc posInf = rs.getString(1);
2390
2391                if ("inf".equalsIgnoreCase(posInf)) {
2392                    this.positiveInfinityRep = "'inf'";
2393                    this.positiveInfinityRepIsClipped = false;
2394                }
2395
2396                String JavaDoc negInf = rs.getString(2);
2397
2398                if ("-inf".equalsIgnoreCase(negInf)) {
2399                    this.negativeInfinityRep = "'-inf'";
2400                    this.negativeInfinityRepIsClipped = false;
2401                }
2402
2403                String JavaDoc nan = rs.getString(3);
2404
2405                if ("nan".equalsIgnoreCase(nan)) {
2406                    this.notANumberRep = "'nan'";
2407                    this.notANumberRepIsClipped = false;
2408                }
2409            }
2410
2411            rs.close();
2412            rs = null;
2413
2414            stmt.close();
2415            stmt = null;
2416        } catch (SQLException JavaDoc sqlEx) {
2417            ; // ignore here, we default to lowest-common denominator
2418
} finally {
2419            if (rs != null) {
2420                try {
2421                    rs.close();
2422                } catch (SQLException JavaDoc sqlEx) {
2423                    ; // ignore
2424
}
2425
2426                rs = null;
2427            }
2428
2429            if (stmt != null) {
2430                try {
2431                    stmt.close();
2432                } catch (SQLException JavaDoc sqlEx) {
2433                    ; // ignore
2434
}
2435
2436                stmt = null;
2437            }
2438        }
2439    }
2440
2441    /**
2442     * Initializes driver properties that come from URL or properties passed to
2443     * the driver manager.
2444     *
2445     * @param info DOCUMENT ME!
2446     *
2447     * @throws SQLException DOCUMENT ME!
2448     */

2449    private void initializeDriverProperties(Properties JavaDoc info)
2450        throws SQLException JavaDoc {
2451        this.socketFactoryClassName = info.getProperty("socketFactory",
2452                DEFAULT_SOCKET_FACTORY);
2453
2454        this.useUnbufferedInput = "TRUE".equalsIgnoreCase(info.getProperty(
2455                    "useUnbufferedInput"));
2456
2457        if (info.getProperty("cachePrepStmts") != null) {
2458            this.cachePreparedStatements = info.getProperty("cachePrepStmts")
2459                                               .equalsIgnoreCase("TRUE");
2460
2461            if (this.cachePreparedStatements) {
2462                if (info.getProperty("prepStmtCacheSize") != null) {
2463                    try {
2464                        this.preparedStatementCacheSize = Integer.parseInt(info
2465                                .getProperty("prepStmtCacheSize"));
2466
2467                        if (this.preparedStatementCacheSize < 0) {
2468                            throw new SQLException JavaDoc("Connection property 'prepStmtCacheSize' must be a non-negative integer value.",
2469                                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2470                        }
2471                    } catch (NumberFormatException JavaDoc nfe) {
2472                        throw new SQLException JavaDoc("Connection property 'prepStmtCacheSize' must be a non-negative integer value.",
2473                            SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2474                    }
2475                }
2476
2477                if (info.getProperty("prepStmtCacheSqlLimit") != null) {
2478                    try {
2479                        this.preparedStatementCacheMaxSqlSize = Integer
2480                            .parseInt(info.getProperty("prepStmtCacheSqlLimit"));
2481
2482                        if (this.preparedStatementCacheMaxSqlSize < 0) {
2483                            throw new SQLException JavaDoc("Connection property 'prepStmtCacheSqlLimit' must be a non-negative integer value.",
2484                                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2485                        }
2486                    } catch (NumberFormatException JavaDoc nfe) {
2487                        throw new SQLException JavaDoc("Connection property 'prepStmtCacheSqlLimit' must be a non-negative integer value.",
2488                            SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2489                    }
2490                }
2491
2492                this.cachedPreparedStatementParams = new HashMap JavaDoc(this.preparedStatementCacheSize);
2493            }
2494        }
2495
2496        if (info.getProperty("alwaysClearStream") != null) {
2497            this.alwaysClearStream = info.getProperty("alwaysClearStream")
2498                                         .equalsIgnoreCase("TRUE");
2499        }
2500
2501        if (info.getProperty("reconnectAtTxEnd") != null) {
2502            this.reconnectAtTxEnd = info.getProperty("reconnectAtTxEnd")
2503                                        .equalsIgnoreCase("TRUE");
2504        }
2505
2506        if (info.getProperty("clobberStreamingResults") != null) {
2507            this.clobberStreamingResults = info.getProperty(
2508                    "clobberStreamingResults").equalsIgnoreCase("TRUE");
2509        }
2510
2511        if (info.getProperty("strictUpdates") != null) {
2512            this.strictUpdates = info.getProperty("strictUpdates")
2513                                     .equalsIgnoreCase("TRUE");
2514        }
2515
2516        if (info.getProperty("ignoreNonTxTables") != null) {
2517            this.ignoreNonTxTables = info.getProperty("ignoreNonTxTables")
2518                                         .equalsIgnoreCase("TRUE");
2519        }
2520
2521        if (info.getProperty("secondsBeforeRetryMaster") != null) {
2522            String JavaDoc secondsBeforeRetryStr = info.getProperty(
2523                    "secondsBeforeRetryMaster");
2524
2525            try {
2526                int seconds = Integer.parseInt(secondsBeforeRetryStr);
2527
2528                if (seconds < 1) {
2529                    throw new SQLException JavaDoc("Illegal (< 1) value '"
2530                        + secondsBeforeRetryStr
2531                        + "' for 'secondsBeforeRetryMaster'",
2532                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2533                }
2534
2535                this.secondsBeforeRetryMaster = seconds;
2536            } catch (NumberFormatException JavaDoc nfe) {
2537                throw new SQLException JavaDoc("Illegal non-numeric value '"
2538                    + secondsBeforeRetryStr
2539                    + "' for 'secondsBeforeRetryMaster'",
2540                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2541            }
2542        }
2543
2544        if (info.getProperty("queriesBeforeRetryMaster") != null) {
2545            String JavaDoc queriesBeforeRetryStr = info.getProperty(
2546                    "queriesBeforeRetryMaster");
2547
2548            try {
2549                this.queriesBeforeRetryMaster = Integer.parseInt(queriesBeforeRetryStr);
2550            } catch (NumberFormatException JavaDoc nfe) {
2551                throw new SQLException JavaDoc("Illegal non-numeric value '"
2552                    + queriesBeforeRetryStr
2553                    + "' for 'queriesBeforeRetryMaster'",
2554                    SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2555            }
2556        }
2557
2558        if (info.getProperty("allowLoadLocalInfile") != null) {
2559            this.allowLoadLocalInfile = info.getProperty("allowLoadLocalInfile")
2560                                            .equalsIgnoreCase("TRUE");
2561        }
2562
2563        if (info.getProperty("continueBatchOnError") != null) {
2564            this.continueBatchOnError = info.getProperty("continueBatchOnError")
2565                                            .equalsIgnoreCase("TRUE");
2566        }
2567
2568        if (info.getProperty("pedantic") != null) {
2569            this.pedantic = info.getProperty("pedantic").equalsIgnoreCase("TRUE");
2570        }
2571
2572        if (info.getProperty("useStreamLengthsInPrepStmts") != null) {
2573            this.useStreamLengthsInPrepStmts = info.getProperty(
2574                    "useStreamLengthsInPrepStmts").equalsIgnoreCase("TRUE");
2575        }
2576
2577        if (info.getProperty("useTimezone") != null) {
2578            this.useTimezone = info.getProperty("useTimezone").equalsIgnoreCase("TRUE");
2579        }
2580
2581        if (info.getProperty("relaxAutoCommit") != null) {
2582            this.relaxAutoCommit = info.getProperty("relaxAutoCommit")
2583                                       .equalsIgnoreCase("TRUE");
2584        } else if (info.getProperty("relaxAutocommit") != null) {
2585            this.relaxAutoCommit = info.getProperty("relaxAutocommit")
2586                                       .equalsIgnoreCase("TRUE");
2587        }
2588
2589        if (info.getProperty("paranoid") != null) {
2590            this.paranoid = info.getProperty("paranoid").equalsIgnoreCase("TRUE");
2591        }
2592
2593        if (info.getProperty("autoReconnect") != null) {
2594            this.highAvailability = info.getProperty("autoReconnect")
2595                                        .equalsIgnoreCase("TRUE");
2596        }
2597
2598        if (info.getProperty("capitalizeTypeNames") != null) {
2599            this.capitalizeDBMDTypes = info.getProperty("capitalizeTypeNames")
2600                                           .equalsIgnoreCase("TRUE");
2601        }
2602
2603        if (info.getProperty("ultraDevHack") != null) {
2604            this.useUltraDevWorkAround = info.getProperty("ultraDevHack")
2605                                             .equalsIgnoreCase("TRUE");
2606        }
2607
2608        if (info.getProperty("strictFloatingPoint") != null) {
2609            this.strictFloatingPoint = info.getProperty("strictFloatingPoint")
2610                                           .equalsIgnoreCase("TRUE");
2611        }
2612
2613        if (info.getProperty("useSSL") != null) {
2614            this.useSSL = info.getProperty("useSSL").equalsIgnoreCase("TRUE");
2615        }
2616
2617        if (info.getProperty("useCompression") != null) {
2618            this.useCompression = info.getProperty("useCompression")
2619                                      .equalsIgnoreCase("TRUE");
2620        }
2621
2622        if (info.getProperty("socketTimeout") != null) {
2623            try {
2624                int n = Integer.parseInt(info.getProperty("socketTimeout"));
2625
2626                if (n < 0) {
2627                    throw new SQLException JavaDoc("socketTimeout can not " + "be < 0",
2628                        SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2629                }
2630
2631                this.socketTimeout = n;
2632            } catch (NumberFormatException JavaDoc NFE) {
2633                throw new SQLException JavaDoc("Illegal parameter '"
2634                    + info.getProperty("socketTimeout") + "' for socketTimeout",
2635                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2636            }
2637        }
2638
2639        if (this.highAvailability) {
2640            if (info.getProperty("maxReconnects") != null) {
2641                try {
2642                    int n = Integer.parseInt(info.getProperty("maxReconnects"));
2643                    this.maxReconnects = n;
2644                } catch (NumberFormatException JavaDoc NFE) {
2645                    throw new SQLException JavaDoc("Illegal parameter '"
2646                        + info.getProperty("maxReconnects")
2647                        + "' for maxReconnects",
2648                        SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2649                }
2650            }
2651
2652            if (info.getProperty("initialTimeout") != null) {
2653                try {
2654                    double n = Integer.parseInt(info.getProperty(
2655                                "initialTimeout"));
2656                    this.initialTimeout = n;
2657                } catch (NumberFormatException JavaDoc NFE) {
2658                    throw new SQLException JavaDoc("Illegal parameter '"
2659                        + info.getProperty("initialTimeout")
2660                        + "' for initialTimeout",
2661                        SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2662                }
2663            }
2664        }
2665
2666        if (info.getProperty("maxRows") != null) {
2667            try {
2668                int n = Integer.parseInt(info.getProperty("maxRows"));
2669
2670                if (n == 0) {
2671                    n = -1;
2672                }
2673
2674                // adjust so that it will become MysqlDefs.MAX_ROWS
2675
// in execSQL()
2676
this.maxRows = n;
2677                this.maxRowsChanged = true;
2678            } catch (NumberFormatException JavaDoc NFE) {
2679                throw new SQLException JavaDoc("Illegal parameter '"
2680                    + info.getProperty("maxRows") + "' for maxRows",
2681                    SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2682            }
2683        }
2684
2685        if (info.getProperty("useHostsInPrivileges") != null) {
2686            this.useHostsInPrivileges = info.getProperty("useHostsInPrivileges")
2687                                            .equalsIgnoreCase("TRUE");
2688        }
2689
2690        if (info.getProperty("interactiveClient") != null) {
2691            this.isInteractiveClient = info.getProperty("interactiveClient")
2692                                           .equalsIgnoreCase("TRUE");
2693        }
2694
2695        if (info.getProperty("useUnicode") != null) {
2696            this.doUnicode = info.getProperty("useUnicode").equalsIgnoreCase("TRUE");
2697        }
2698
2699        if (this.doUnicode) {
2700            if (info.getProperty("mysqlEncoding") != null) {
2701                this.mysqlEncodingName = info.getProperty("mysqlEncoding");
2702            }
2703
2704            if (info.getProperty("characterEncoding") != null) {
2705                this.encoding = info.getProperty("characterEncoding");
2706
2707                // Attempt to use the encoding, and bail out if it
2708
// can't be used
2709
try {
2710                    String JavaDoc testString = "abc";
2711                    testString.getBytes(this.encoding);
2712                } catch (UnsupportedEncodingException JavaDoc UE) {
2713                    throw new SQLException JavaDoc("Unsupported character "
2714                        + "encoding '" + this.encoding + "'.",
2715                        SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE);
2716                }
2717            }
2718        }
2719    }
2720
2721    /**
2722     * Sets varying properties that depend on server information. Called once
2723     * we have connected to the server.
2724     *
2725     * @param info DOCUMENT ME!
2726     *
2727     * @throws SQLException DOCUMENT ME!
2728     */

2729    private void initializePropsFromServer(Properties JavaDoc info)
2730        throws SQLException JavaDoc {
2731        if (this.io.versionMeetsMinimum(3, 22, 1)) {
2732            this.useFastPing = true;
2733        }
2734
2735        detectFloatingPointStyle();
2736
2737        this.serverVariables.clear();
2738
2739        //
2740
// If version is greater than 3.21.22 get the server
2741
// variables.
2742
if (this.io.versionMeetsMinimum(3, 21, 22)) {
2743            com.mysql.jdbc.Statement stmt = null;
2744            com.mysql.jdbc.ResultSet results = null;
2745
2746            try {
2747                stmt = (com.mysql.jdbc.Statement) createStatement();
2748
2749                if (stmt.getMaxRows() != 0) {
2750                    stmt.setMaxRows(0);
2751                }
2752
2753                results = (com.mysql.jdbc.ResultSet) stmt.executeQuery(
2754                        "SHOW VARIABLES");
2755
2756                while (results.next()) {
2757                    this.serverVariables.put(results.getString(1),
2758                        results.getString(2));
2759                }
2760            } catch (java.sql.SQLException JavaDoc e) {
2761                throw e;
2762            } finally {
2763                if (results != null) {
2764                    try {
2765                        results.close();
2766                    } catch (java.sql.SQLException JavaDoc sqlE) {
2767                        ;
2768                    }
2769                }
2770
2771                if (stmt != null) {
2772                    try {
2773                        stmt.close();
2774                    } catch (java.sql.SQLException JavaDoc sqlE) {
2775                        ;
2776                    }
2777                }
2778            }
2779
2780            String JavaDoc lowerCaseTables = (String JavaDoc) serverVariables.get(
2781                    "lower_case_table_names");
2782
2783            this.lowerCaseTableNames = "on".equalsIgnoreCase(lowerCaseTables)
2784                || "1".equalsIgnoreCase(lowerCaseTables)
2785                || "2".equalsIgnoreCase(lowerCaseTables);
2786
2787            if (this.useTimezone
2788                    && this.serverVariables.containsKey("timezone")) {
2789                // user can specify/override as property
2790
String JavaDoc canoncicalTimezone = this.props.getProperty(
2791                        "serverTimezone");
2792
2793                if ((canoncicalTimezone == null)
2794                        || (canoncicalTimezone.length() == 0)) {
2795                    String JavaDoc serverTimezoneStr = (String JavaDoc) this.serverVariables
2796                        .get("timezone");
2797
2798                    try {
2799                        canoncicalTimezone = TimeUtil.getCanoncialTimezone(serverTimezoneStr);
2800
2801                        if (canoncicalTimezone == null) {
2802                            throw new SQLException JavaDoc("Can't map timezone '"
2803                                + serverTimezoneStr + "' to "
2804                                + " canonical timezone.",
2805                                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2806                        }
2807                    } catch (IllegalArgumentException JavaDoc iae) {
2808                        throw new SQLException JavaDoc(iae.getMessage(),
2809                            SQLError.SQL_STATE_GENERAL_ERROR);
2810                    }
2811                }
2812
2813                serverTimezone = TimeZone.getTimeZone(canoncicalTimezone);
2814
2815                //
2816
// The Calendar class has the behavior of mapping
2817
// unknown timezones to 'GMT' instead of throwing an
2818
// exception, so we must check for this...
2819
//
2820
if (!canoncicalTimezone.equalsIgnoreCase("GMT")
2821                        && serverTimezone.getID().equals("GMT")) {
2822                    throw new SQLException JavaDoc("No timezone mapping entry for '"
2823                        + canoncicalTimezone + "'",
2824                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2825                }
2826            }
2827
2828            if (this.serverVariables.containsKey("max_allowed_packet")) {
2829                this.maxAllowedPacket = Integer.parseInt((String JavaDoc) this.serverVariables
2830                        .get("max_allowed_packet"));
2831            }
2832
2833            if (this.serverVariables.containsKey("net_buffer_length")) {
2834                this.netBufferLength = Integer.parseInt((String JavaDoc) this.serverVariables
2835                        .get("net_buffer_length"));
2836            }
2837
2838            checkTransactionIsolationLevel();
2839            checkServerEncoding();
2840            this.io.checkForCharsetMismatch();
2841        }
2842
2843        if (this.io.versionMeetsMinimum(3, 23, 15)) {
2844            this.transactionsSupported = true;
2845            setAutoCommit(true); // to override anything
2846
// the server is set to...reqd
2847
// by JDBC spec.
2848
} else {
2849            this.transactionsSupported = false;
2850        }
2851
2852        if (this.io.versionMeetsMinimum(3, 23, 36)) {
2853            this.hasIsolationLevels = true;
2854        } else {
2855            this.hasIsolationLevels = false;
2856        }
2857
2858        // Start logging perf/profile data if the user has requested it.
2859
String JavaDoc profileSql = info.getProperty("profileSql");
2860
2861        if ((profileSql != null) && profileSql.trim().equalsIgnoreCase("true")) {
2862            this.io.setProfileSql(true);
2863        } else {
2864            this.io.setProfileSql(false);
2865        }
2866
2867        this.hasQuotedIdentifiers = this.io.versionMeetsMinimum(3, 23, 6);
2868
2869        if (this.serverVariables.containsKey("sql_mode")) {
2870            int sqlMode = 0;
2871
2872            try {
2873                sqlMode = Integer.parseInt((String JavaDoc) this.serverVariables.get(
2874                            "sql_mode"));
2875            } catch (NumberFormatException JavaDoc nfe) {
2876                sqlMode = 0;
2877            }
2878
2879            if ((sqlMode & 4) > 0) {
2880                this.useAnsiQuotes = true;
2881            } else {
2882                this.useAnsiQuotes = false;
2883            }
2884        }
2885
2886        //
2887
// Setup client character set for MySQL-4.1 and newer
2888
//
2889
if (this.io.versionMeetsMinimum(4, 1, 0) && useUnicode()
2890                && (getEncoding() != null)) {
2891            if (getEncoding().equalsIgnoreCase("UTF-8")
2892                    || getEncoding().equalsIgnoreCase("UTF8")) {
2893                // charset names are case-sensitive
2894
execSQL("SET NAMES utf8", -1, this.database);
2895            } else {
2896                String JavaDoc namesEncoding = this.mysqlEncodingName;
2897
2898                if ("koi8_ru".equals(this.mysqlEncodingName)) {
2899                    // This has a _different_ name in 4.1...
2900
namesEncoding = "ko18r";
2901                }
2902
2903                if (namesEncoding != null) {
2904                    execSQL("SET NAMES " + namesEncoding, -1, this.database);
2905                }
2906            }
2907        }
2908
2909        this.io.resetMaxBuf();
2910    }
2911
2912    /**
2913     * Loads the mapping between MySQL character sets and Java character sets
2914     */

2915    private static void loadCharacterSetMapping() {
2916        multibyteCharsetsMap = new HashMap JavaDoc();
2917
2918        Iterator JavaDoc multibyteCharsets = CharsetMapping.MULTIBYTE_CHARSETS.keySet()
2919                                                                      .iterator();
2920
2921        while (multibyteCharsets.hasNext()) {
2922            String JavaDoc charset = ((String JavaDoc) multibyteCharsets.next()).toUpperCase();
2923            multibyteCharsetsMap.put(charset, charset);
2924        }
2925
2926        //
2927
// Now change all server encodings to upper-case to "future-proof"
2928
// this mapping
2929
//
2930
Iterator JavaDoc keys = CharsetMapping.CHARSETMAP.keySet().iterator();
2931        charsetMap = new HashMap JavaDoc();
2932
2933        while (keys.hasNext()) {
2934            String JavaDoc mysqlCharsetName = ((String JavaDoc) keys.next()).trim();
2935            String JavaDoc javaCharsetName = CharsetMapping.CHARSETMAP.get(mysqlCharsetName)
2936                                                              .toString().trim();
2937            charsetMap.put(mysqlCharsetName.toUpperCase(), javaCharsetName);
2938            charsetMap.put(mysqlCharsetName, javaCharsetName);
2939        }
2940    }
2941
2942    private boolean getUseUltraDevWorkAround() {
2943        return useUltraDevWorkAround;
2944    }
2945
2946    // *********************************************************************
2947
//
2948
// END OF PUBLIC INTERFACE
2949
//
2950
// *********************************************************************
2951

2952    /**
2953     * Detect if the connection is still good
2954     *
2955     * @throws Exception DOCUMENT ME!
2956     */

2957    private void ping() throws Exception JavaDoc {
2958        if (this.useFastPing) {
2959            this.io.sendCommand(MysqlDefs.PING, null, null);
2960        } else {
2961            this.io.sqlQuery(PING_COMMAND, MysqlDefs.MAX_ROWS, this.encoding,
2962                this, java.sql.ResultSet.CONCUR_READ_ONLY, false, this.database);
2963        }
2964    }
2965
2966    private void pingAndReconnect(boolean ignoreAutoCommitSetting)
2967        throws SQLException JavaDoc {
2968        boolean localAutoCommit = this.autoCommit;
2969
2970        // We use this to catch the 'edge' case
2971
// of autoReconnect going from true->false
2972
//
2973
if (ignoreAutoCommitSetting) {
2974            localAutoCommit = true;
2975        }
2976
2977        if (this.failedOver && localAutoCommit) {
2978            this.queriesIssuedFailedOver++;
2979
2980            if (shouldFallBack()) {
2981                createNewIO(true);
2982
2983                String JavaDoc connectedHost = this.io.getHost();
2984
2985                if ((connectedHost != null)
2986                        && this.hostList.get(0).equals(connectedHost)) {
2987                    this.failedOver = false;
2988                    this.queriesIssuedFailedOver = 0;
2989                    setReadOnly(false);
2990                }
2991            }
2992        }
2993
2994        if ((this.highAvailability || this.failedOver) && localAutoCommit) {
2995            try {
2996                ping();
2997            } catch (Exception JavaDoc Ex) {
2998                createNewIO(true);
2999            }
3000        }
3001    }
3002
3003    private void rollbackNoChecks() throws SQLException JavaDoc {
3004        execSQL("rollback", -1, null);
3005    }
3006
3007    /**
3008     * Should we try to connect back to the master? We try when we've been
3009     * failed over >= this.secondsBeforeRetryMaster _or_ we've issued >
3010     * this.queriesIssuedFailedOver
3011     *
3012     * @return DOCUMENT ME!
3013     */

3014    private boolean shouldFallBack() {
3015        long secondsSinceFailedOver = (System.currentTimeMillis()
3016            - this.masterFailTimeMillis) / 1000;
3017
3018        return ((secondsSinceFailedOver >= this.secondsBeforeRetryMaster)
3019        || ((this.queriesIssuedFailedOver % this.queriesBeforeRetryMaster) == 0));
3020    }
3021
3022    /**
3023     * Wrapper class for UltraDev CallableStatements that are really
3024     * PreparedStatments. Nice going, UltraDev developers.
3025     */

3026    class UltraDevWorkAround implements java.sql.CallableStatement JavaDoc {
3027        private java.sql.PreparedStatement JavaDoc delegate = null;
3028
3029        UltraDevWorkAround(java.sql.PreparedStatement JavaDoc pstmt) {
3030            delegate = pstmt;
3031        }
3032
3033        public void setArray(int p1, final java.sql.Array JavaDoc p2)
3034            throws java.sql.SQLException JavaDoc {
3035            delegate.setArray(p1, p2);
3036        }
3037
3038        public java.sql.Array JavaDoc getArray(int p1) throws java.sql.SQLException JavaDoc {
3039            throw new SQLException JavaDoc("Not supported");
3040        }
3041
3042        /**
3043         * @see CallableStatement#getArray(String)
3044         */

3045        public java.sql.Array JavaDoc getArray(String JavaDoc arg0) throws SQLException JavaDoc {
3046            throw new NotImplemented();
3047        }
3048
3049        public void setAsciiStream(int p1, final java.io.InputStream JavaDoc p2, int p3)
3050            throws java.sql.SQLException JavaDoc {
3051            delegate.setAsciiStream(p1, p2, p3);
3052        }
3053
3054        /**
3055         * @see CallableStatement#setAsciiStream(String, InputStream, int)
3056         */

3057        public void setAsciiStream(String JavaDoc arg0, InputStream JavaDoc arg1, int arg2)
3058            throws SQLException JavaDoc {
3059            throw new NotImplemented();
3060        }
3061
3062        public void setBigDecimal(int p1, final java.math.BigDecimal JavaDoc p2)
3063            throws java.sql.SQLException JavaDoc {
3064            delegate.setBigDecimal(p1, p2);
3065        }
3066
3067        /**
3068         * @see CallableStatement#setBigDecimal(String, BigDecimal)
3069         */

3070        public void setBigDecimal(String JavaDoc arg0, BigDecimal JavaDoc arg1)
3071            throws SQLException JavaDoc {
3072            throw new NotImplemented();
3073        }
3074
3075        public java.math.BigDecimal JavaDoc getBigDecimal(int p1)
3076            throws java.sql.SQLException JavaDoc {
3077            throw new SQLException JavaDoc("Not supported");
3078        }
3079
3080        public java.math.BigDecimal JavaDoc getBigDecimal(int p1, int p2)
3081            throws java.sql.SQLException JavaDoc {
3082            throw new SQLException JavaDoc("Not supported");
3083        }
3084
3085        /**
3086         * @see CallableStatement#getBigDecimal(String)
3087         */

3088        public BigDecimal JavaDoc getBigDecimal(String JavaDoc arg0) throws SQLException JavaDoc {
3089            return null;
3090        }
3091
3092        public void setBinaryStream(int p1, final java.io.InputStream JavaDoc p2, int p3)
3093            throws java.sql.SQLException JavaDoc {
3094            delegate.setBinaryStream(p1, p2, p3);
3095        }
3096
3097        /**
3098         * @see CallableStatement#setBinaryStream(String, InputStream, int)
3099         */

3100        public void setBinaryStream(String JavaDoc arg0, InputStream JavaDoc arg1, int arg2)
3101            throws SQLException JavaDoc {
3102            throw new NotImplemented();
3103        }
3104
3105        public void setBlob(int p1, final java.sql.Blob JavaDoc p2)
3106            throws java.sql.SQLException JavaDoc {
3107            delegate.setBlob(p1, p2);
3108        }
3109
3110        public java.sql.Blob JavaDoc getBlob(int p1) throws java.sql.SQLException JavaDoc {
3111            throw new SQLException JavaDoc("Not supported");
3112        }
3113
3114        /**
3115         * @see CallableStatement#getBlob(String)
3116         */

3117        public java.sql.Blob JavaDoc getBlob(String JavaDoc arg0) throws SQLException JavaDoc {
3118            throw new NotImplemented();
3119        }
3120
3121        public void setBoolean(int p1, boolean p2) throws java.sql.SQLException JavaDoc {
3122            delegate.setBoolean(p1, p2);
3123        }
3124
3125        /**
3126         * @see CallableStatement#setBoolean(String, boolean)
3127         */

3128        public void setBoolean(String JavaDoc arg0, boolean arg1)
3129            throws SQLException JavaDoc {
3130            throw new NotImplemented();
3131        }
3132
3133        public boolean getBoolean(int p1) throws java.sql.SQLException JavaDoc {
3134            throw new SQLException JavaDoc("Not supported");
3135        }
3136
3137        /**
3138         * @see CallableStatement#getBoolean(String)
3139         */

3140        public boolean getBoolean(String JavaDoc arg0) throws SQLException JavaDoc {
3141            throw new NotImplemented();
3142        }
3143
3144        public void setByte(int p1, byte p2) throws java.sql.SQLException JavaDoc {
3145            delegate.setByte(p1, p2);
3146        }
3147
3148        /**
3149         * @see CallableStatement#setByte(String, byte)
3150         */

3151        public void setByte(String JavaDoc arg0, byte arg1) throws SQLException JavaDoc {
3152            throw new NotImplemented();
3153        }
3154
3155        public byte getByte(int p1) throws java.sql.SQLException JavaDoc {
3156            throw new SQLException JavaDoc("Not supported");
3157        }
3158
3159        /**
3160         * @see CallableStatement#getByte(String)
3161         */

3162        public byte getByte(String JavaDoc arg0) throws SQLException JavaDoc {
3163            throw new NotImplemented();
3164        }
3165
3166        public void setBytes(int p1, byte[] p2) throws java.sql.SQLException JavaDoc {
3167            delegate.setBytes(p1, p2);
3168        }
3169
3170        /**
3171         * @see CallableStatement#setBytes(String, byte[])
3172         */

3173        public void setBytes(String JavaDoc arg0, byte[] arg1)
3174            throws SQLException JavaDoc {
3175            throw new NotImplemented();
3176        }
3177
3178        public byte[] getBytes(int p1) throws java.sql.SQLException JavaDoc {
3179            throw new SQLException JavaDoc("Not supported");
3180        }
3181
3182        /**
3183         * @see CallableStatement#getBytes(String)
3184         */

3185        public byte[] getBytes(String JavaDoc arg0) throws SQLException JavaDoc {
3186            throw new NotImplemented();
3187        }
3188
3189        public void setCharacterStream(int p1, final java.io.Reader JavaDoc p2, int p3)
3190            throws java.sql.SQLException JavaDoc {
3191            delegate.setCharacterStream(p1, p2, p3);
3192        }
3193
3194        /**
3195         * @see CallableStatement#setCharacterStream(String, Reader, int)
3196         */

3197        public void setCharacterStream(String JavaDoc arg0, Reader JavaDoc arg1, int arg2)
3198            throws SQLException JavaDoc {
3199            throw new NotImplemented();
3200        }
3201
3202        public void setClob(int p1, final java.sql.Clob JavaDoc p2)
3203            throws java.sql.SQLException JavaDoc {
3204            delegate.setClob(p1, p2);
3205        }
3206
3207        public java.sql.Clob JavaDoc getClob(int p1) throws java.sql.SQLException JavaDoc {
3208            throw new SQLException JavaDoc("Not supported");
3209        }
3210
3211        /**
3212         * @see CallableStatement#getClob(String)
3213         */

3214        public Clob getClob(String JavaDoc arg0) throws SQLException JavaDoc {
3215            throw new NotImplemented();
3216        }
3217
3218        public java.sql.Connection JavaDoc getConnection() throws java.sql.SQLException JavaDoc {
3219            return delegate.getConnection();
3220        }
3221
3222        public void setCursorName(java.lang.String JavaDoc p1)
3223            throws java.sql.SQLException JavaDoc {
3224            throw new SQLException JavaDoc("Not supported");
3225        }
3226
3227        public void setDate(int p1, final java.sql.Date JavaDoc p2)
3228            throws java.sql.SQLException JavaDoc {
3229            delegate.setDate(p1, p2);
3230        }
3231
3232        public void setDate(int p1, final java.sql.Date JavaDoc p2,
3233            final java.util.Calendar JavaDoc p3) throws java.sql.SQLException JavaDoc {
3234            delegate.setDate(p1, p2, p3);
3235        }
3236
3237        /**
3238         * @see CallableStatement#setDate(String, Date, Calendar)
3239         */

3240        public void setDate(String JavaDoc arg0, Date JavaDoc arg1, Calendar JavaDoc arg2)
3241            throws SQLException JavaDoc {
3242            throw new NotImplemented();
3243        }
3244
3245        /**
3246         * @see CallableStatement#setDate(String, Date)
3247         */

3248        public void setDate(String JavaDoc arg0, Date JavaDoc arg1) throws SQLException JavaDoc {
3249            throw new NotImplemented();
3250        }
3251
3252        public java.sql.Date JavaDoc getDate(int p1) throws java.sql.SQLException JavaDoc {
3253            throw new SQLException JavaDoc("Not supported");
3254        }
3255
3256        public java.sql.Date JavaDoc getDate(int p1, final java.util.Calendar JavaDoc p2)
3257            throws java.sql.SQLException JavaDoc {
3258            throw new SQLException JavaDoc("Not supported");
3259        }
3260
3261        /**
3262         * @see CallableStatement#getDate(String, Calendar)
3263         */

3264        public Date JavaDoc getDate(String JavaDoc arg0, Calendar JavaDoc arg1)
3265            throws SQLException JavaDoc {
3266            throw new NotImplemented();
3267        }
3268
3269        /**
3270         * @see CallableStatement#getDate(String)
3271         */

3272        public Date JavaDoc getDate(String JavaDoc arg0) throws SQLException JavaDoc {
3273            throw new NotImplemented();
3274        }
3275
3276        public void setDouble(int p1, double p2) throws java.sql.SQLException JavaDoc {
3277            delegate.setDouble(p1, p2);
3278        }
3279
3280        /**
3281         * @see CallableStatement#setDouble(String, double)
3282         */

3283        public void setDouble(String JavaDoc arg0, double arg1)
3284            throws SQLException JavaDoc {
3285            throw new NotImplemented();
3286        }
3287
3288        public double getDouble(int p1) throws java.sql.SQLException JavaDoc {
3289            throw new SQLException JavaDoc("Not supported");
3290        }
3291
3292        /**
3293         * @see CallableStatement#getDouble(String)
3294         */

3295        public double getDouble(String JavaDoc arg0) throws SQLException JavaDoc {
3296            throw new NotImplemented();
3297        }
3298
3299        public void setEscapeProcessing(boolean p1)
3300            throws java.sql.SQLException JavaDoc {
3301            delegate.setEscapeProcessing(p1);
3302        }
3303
3304        public void setFetchDirection(int p1) throws java.sql.SQLException JavaDoc {
3305            delegate.setFetchDirection(p1);
3306        }
3307
3308        public int getFetchDirection() throws java.sql.SQLException JavaDoc {
3309            return delegate.getFetchDirection();
3310        }
3311
3312        public void setFetchSize(int p1) throws java.sql.SQLException JavaDoc {
3313            delegate.setFetchSize(p1);
3314        }
3315
3316        public int getFetchSize() throws java.sql.SQLException JavaDoc {
3317            return delegate.getFetchSize();
3318        }
3319
3320        public void setFloat(int p1, float p2) throws java.sql.SQLException JavaDoc {
3321            delegate.setFloat(p1, p2);
3322        }
3323
3324        /**
3325         * @see CallableStatement#setFloat(String, float)
3326         */

3327        public void setFloat(String JavaDoc arg0, float arg1) throws SQLException JavaDoc {
3328            throw new NotImplemented();
3329        }
3330
3331        public float getFloat(int p1) throws java.sql.SQLException JavaDoc {
3332            throw new SQLException JavaDoc("Not supported");
3333        }
3334
3335        /**
3336         * @see CallableStatement#getFloat(String)
3337         */

3338        public float getFloat(String JavaDoc arg0) throws SQLException JavaDoc {
3339            throw new NotImplemented();
3340        }
3341
3342        /**
3343         * @see Statement#getGeneratedKeys()
3344         */

3345        public java.sql.ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc {
3346            return delegate.getGeneratedKeys();
3347        }
3348
3349        public void setInt(int p1, int p2) throws java.sql.SQLException JavaDoc {
3350            delegate.setInt(p1, p2);
3351        }
3352
3353        /**
3354         * @see CallableStatement#setInt(String, int)
3355         */

3356        public void setInt(String JavaDoc arg0, int arg1) throws SQLException JavaDoc {
3357            throw new NotImplemented();
3358        }
3359
3360        public int getInt(int p1) throws java.sql.SQLException JavaDoc {
3361            throw new SQLException JavaDoc("Not supported");
3362        }
3363
3364        /**
3365         * @see CallableStatement#getInt(String)
3366         */

3367        public int getInt(String JavaDoc arg0) throws SQLException JavaDoc {
3368            throw new NotImplemented();
3369        }
3370
3371        public void setLong(int p1, long p2) throws java.sql.SQLException JavaDoc {
3372            delegate.setLong(p1, p2);
3373        }
3374
3375        /**
3376         * @see CallableStatement#setLong(String, long)
3377         */

3378        public void setLong(String JavaDoc arg0, long arg1) throws SQLException JavaDoc {
3379            throw new NotImplemented();
3380        }
3381
3382        public long getLong(int p1) throws java.sql.SQLException JavaDoc {
3383            throw new SQLException JavaDoc("Not supported");
3384        }
3385
3386        /**
3387         * @see CallableStatement#getLong(String)
3388         */

3389        public long getLong(String JavaDoc arg0) throws SQLException JavaDoc {
3390            throw new NotImplemented();
3391        }
3392
3393        public void setMaxFieldSize(int p1) throws java.sql.SQLException JavaDoc {
3394            delegate.setMaxFieldSize(p1);
3395        }
3396
3397        public int getMaxFieldSize() throws java.sql.SQLException JavaDoc {
3398            return delegate.getMaxFieldSize();
3399        }
3400
3401        public void setMaxRows(int p1) throws java.sql.SQLException JavaDoc {
3402            delegate.setMaxRows(p1);
3403        }
3404
3405        public int getMaxRows() throws java.sql.SQLException JavaDoc {
3406            return delegate.getMaxRows();
3407        }
3408
3409        public java.sql.ResultSetMetaData JavaDoc getMetaData()
3410            throws java.sql.SQLException JavaDoc {
3411            throw new SQLException JavaDoc("Not supported");
3412        }
3413
3414        public boolean getMoreResults() throws java.sql.SQLException JavaDoc {
3415            return delegate.getMoreResults();
3416        }
3417
3418        /**
3419         * @see Statement#getMoreResults(int)
3420         */

3421        public boolean getMoreResults(int arg0) throws SQLException JavaDoc {
3422            return delegate.getMoreResults();
3423        }
3424
3425        public void setNull(int p1, int p2) throws java.sql.SQLException JavaDoc {
3426            delegate.setNull(p1, p2);
3427        }
3428
3429        public void setNull(int p1, int p2, java.lang.String JavaDoc p3)
3430            throws java.sql.SQLException JavaDoc {
3431            delegate.setNull(p1, p2, p3);
3432        }
3433
3434        /**
3435         * @see CallableStatement#setNull(String, int, String)
3436         */

3437        public void setNull(String JavaDoc arg0, int arg1, String JavaDoc arg2)
3438            throws SQLException JavaDoc {
3439            throw new NotImplemented();
3440        }
3441
3442        /**
3443         * @see CallableStatement#setNull(String, int)
3444         */

3445        public void setNull(String JavaDoc arg0, int arg1) throws SQLException JavaDoc {
3446            throw new NotImplemented();
3447        }
3448
3449        public void setObject(int p1, final java.lang.Object JavaDoc p2)
3450            throws java.sql.SQLException JavaDoc {
3451            delegate.setObject(p1, p2);
3452        }
3453
3454        public void setObject(int p1, final java.lang.Object JavaDoc p2, int p3)
3455            throws java.sql.SQLException JavaDoc {
3456            delegate.setObject(p1, p2, p3);
3457        }
3458
3459        public void setObject(int p1, final java.lang.Object JavaDoc p2, int p3, int p4)
3460            throws java.sql.SQLException JavaDoc {
3461            delegate.setObject(p1, p2, p3, p4);
3462        }
3463
3464        /**
3465         * @see CallableStatement#setObject(String, Object, int, int)
3466         */

3467        public void setObject(String JavaDoc arg0, Object JavaDoc arg1, int arg2, int arg3)
3468            throws SQLException JavaDoc {
3469            throw new NotImplemented();
3470        }
3471
3472        /**
3473         * @see CallableStatement#setObject(String, Object, int)
3474         */

3475        public void setObject(String JavaDoc arg0, Object JavaDoc arg1, int arg2)
3476            throws SQLException JavaDoc {
3477            throw new NotImplemented();
3478        }
3479
3480        /**
3481         * @see CallableStatement#setObject(String, Object)
3482         */

3483        public void setObject(String JavaDoc arg0, Object JavaDoc arg1)
3484            throws SQLException JavaDoc {
3485            throw new NotImplemented();
3486        }
3487
3488        public java.lang.Object JavaDoc getObject(int p1) throws java.sql.SQLException JavaDoc {
3489            throw new SQLException JavaDoc("Not supported");
3490        }
3491
3492        public java.lang.Object JavaDoc getObject(int p1, final java.util.Map JavaDoc p2)
3493            throws java.sql.SQLException JavaDoc {
3494            throw new SQLException JavaDoc("Not supported");
3495        }
3496
3497        /**
3498         * @see CallableStatement#getObject(String, Map)
3499         */

3500        public Object JavaDoc getObject(String JavaDoc arg0, Map JavaDoc arg1)
3501            throws SQLException JavaDoc {
3502            throw new NotImplemented();
3503        }
3504
3505        /**
3506         * @see CallableStatement#getObject(String)
3507         */

3508        public Object JavaDoc getObject(String JavaDoc arg0) throws SQLException JavaDoc {
3509            throw new NotImplemented();
3510        }
3511
3512        /**
3513         * @see PreparedStatement#getParameterMetaData()
3514         */

3515        public ParameterMetaData JavaDoc getParameterMetaData()
3516            throws SQLException JavaDoc {
3517            return delegate.getParameterMetaData();
3518        }
3519
3520        public void setQueryTimeout(int p1) throws java.sql.SQLException JavaDoc {
3521            throw new SQLException JavaDoc("Not supported");
3522        }
3523
3524        public int getQueryTimeout() throws java.sql.SQLException JavaDoc {
3525            return delegate.getQueryTimeout();
3526        }
3527
3528        public void setRef(int p1, final java.sql.Ref JavaDoc p2)
3529            throws java.sql.SQLException JavaDoc {
3530            throw new SQLException JavaDoc("Not supported");
3531        }
3532
3533        public java.sql.Ref JavaDoc getRef(int p1) throws java.sql.SQLException JavaDoc {
3534            throw new SQLException JavaDoc("Not supported");
3535        }
3536
3537        /**
3538         * @see CallableStatement#getRef(String)
3539         */

3540        public Ref JavaDoc getRef(String JavaDoc arg0) throws SQLException JavaDoc {
3541            throw new NotImplemented();
3542        }
3543
3544        public java.sql.ResultSet JavaDoc getResultSet() throws java.sql.SQLException JavaDoc {
3545            return delegate.getResultSet();
3546        }
3547
3548        public int getResultSetConcurrency() throws java.sql.SQLException JavaDoc {
3549            return delegate.getResultSetConcurrency();
3550        }
3551
3552        /**
3553         * @see Statement#getResultSetHoldability()
3554         */

3555        public int getResultSetHoldability() throws SQLException JavaDoc {
3556            return delegate.getResultSetHoldability();
3557        }
3558
3559        public int getResultSetType() throws java.sql.SQLException JavaDoc {
3560            return delegate.getResultSetType();
3561        }
3562
3563        public void setShort(int p1, short p2) throws java.sql.SQLException JavaDoc {
3564            delegate.setShort(p1, p2);
3565        }
3566
3567        /**
3568         * @see CallableStatement#setShort(String, short)
3569         */

3570        public void setShort(String JavaDoc arg0, short arg1) throws SQLException JavaDoc {
3571            throw new NotImplemented();
3572        }
3573
3574        public short getShort(int p1) throws java.sql.SQLException JavaDoc {
3575            throw new SQLException JavaDoc("Not supported");
3576        }
3577
3578        /**
3579         * @see CallableStatement#getShort(String)
3580         */

3581        public short getShort(String JavaDoc arg0) throws SQLException JavaDoc {
3582            throw new NotImplemented();
3583        }
3584
3585        public void setString(int p1, java.lang.String JavaDoc p2)
3586            throws java.sql.SQLException JavaDoc {
3587            delegate.setString(p1, p2);
3588        }
3589
3590        /**
3591         * @see CallableStatement#setString(String, String)
3592         */

3593        public void setString(String JavaDoc arg0, String JavaDoc arg1)
3594            throws SQLException JavaDoc {
3595            throw new NotImplemented();
3596        }
3597
3598        public java.lang.String JavaDoc getString(int p1) throws java.sql.SQLException JavaDoc {
3599            throw new SQLException JavaDoc("Not supported");
3600        }
3601
3602        /**
3603         * @see CallableStatement#getString(String)
3604         */

3605        public String JavaDoc getString(String JavaDoc arg0) throws SQLException JavaDoc {
3606            throw new NotImplemented();
3607        }
3608
3609        public void setTime(int p1, final java.sql.Time JavaDoc p2)
3610            throws java.sql.SQLException JavaDoc {
3611            delegate.setTime(p1, p2);
3612        }
3613
3614        public void setTime(int p1, final java.sql.Time JavaDoc p2,
3615            final java.util.Calendar JavaDoc p3) throws java.sql.SQLException JavaDoc {
3616            delegate.setTime(p1, p2, p3);
3617        }
3618
3619        /**
3620         * @see CallableStatement#setTime(String, Time, Calendar)
3621         */

3622        public void setTime(String JavaDoc arg0, Time JavaDoc arg1, Calendar JavaDoc arg2)
3623            throws SQLException JavaDoc {
3624            throw new NotImplemented();
3625        }
3626
3627        /**
3628         * @see CallableStatement#setTime(String, Time)
3629         */

3630        public void setTime(String JavaDoc arg0, Time JavaDoc arg1) throws SQLException JavaDoc {
3631            throw new NotImplemented();
3632        }
3633
3634        public java.sql.Time JavaDoc getTime(int p1) throws java.sql.SQLException JavaDoc {
3635            throw new SQLException JavaDoc("Not supported");
3636        }
3637
3638        public java.sql.Time JavaDoc getTime(int p1, final java.util.Calendar JavaDoc p2)
3639            throws java.sql.SQLException JavaDoc {
3640            throw new SQLException JavaDoc("Not supported");
3641        }
3642
3643        /**
3644         * @see CallableStatement#getTime(String, Calendar)
3645         */

3646        public Time JavaDoc getTime(String JavaDoc arg0, Calendar JavaDoc arg1)
3647            throws SQLException JavaDoc {
3648            throw new NotImplemented();
3649        }
3650
3651        /**
3652         * @see CallableStatement#getTime(String)
3653         */

3654        public Time JavaDoc getTime(String JavaDoc arg0) throws SQLException JavaDoc {
3655            throw new NotImplemented();
3656        }
3657
3658        public void setTimestamp(int p1, final java.sql.Timestamp JavaDoc p2)
3659            throws java.sql.SQLException JavaDoc {
3660            delegate.setTimestamp(p1, p2);
3661        }
3662
3663        public void setTimestamp(int p1, final java.sql.Timestamp JavaDoc p2,
3664            final java.util.Calendar JavaDoc p3) throws java.sql.SQLException JavaDoc {
3665            delegate.setTimestamp(p1, p2, p3);
3666        }
3667
3668        /**
3669         * @see CallableStatement#setTimestamp(String, Timestamp, Calendar)
3670         */

3671        public void setTimestamp(String JavaDoc arg0, Timestamp JavaDoc arg1, Calendar JavaDoc arg2)
3672            throws SQLException JavaDoc {
3673            throw new NotImplemented();
3674        }
3675
3676        /**
3677         * @see CallableStatement#setTimestamp(String, Timestamp)
3678         */

3679        public void setTimestamp(String JavaDoc arg0, Timestamp JavaDoc arg1)
3680            throws SQLException JavaDoc {
3681            throw new NotImplemented();
3682        }
3683
3684        public java.sql.Timestamp JavaDoc getTimestamp(int p1)
3685            throws java.sql.SQLException JavaDoc {
3686            throw new SQLException JavaDoc("Not supported");
3687        }
3688
3689        public java.sql.Timestamp JavaDoc getTimestamp(int p1,
3690            final java.util.Calendar JavaDoc p2) throws java.sql.SQLException JavaDoc {
3691            throw new SQLException JavaDoc("Not supported");
3692        }
3693
3694        /**
3695         * @see CallableStatement#getTimestamp(String, Calendar)
3696         */

3697        public Timestamp JavaDoc getTimestamp(String JavaDoc arg0, Calendar JavaDoc arg1)
3698            throws SQLException JavaDoc {
3699            throw new NotImplemented();
3700        }
3701
3702        /**
3703         * @see CallableStatement#getTimestamp(String)
3704         */

3705        public Timestamp JavaDoc getTimestamp(String JavaDoc arg0) throws SQLException JavaDoc {
3706            throw new NotImplemented();
3707        }
3708
3709        /**
3710         * @see CallableStatement#setURL(String, URL)
3711         */

3712        public void setURL(String JavaDoc arg0, URL JavaDoc arg1) throws SQLException JavaDoc {
3713            throw new NotImplemented();
3714        }
3715
3716        /**
3717         * @see PreparedStatement#setURL(int, URL)
3718         */

3719        public void setURL(int arg0, URL JavaDoc arg1) throws SQLException JavaDoc {
3720            delegate.setURL(arg0, arg1);
3721        }
3722
3723        /**
3724         * @see CallableStatement#getURL(int)
3725         */

3726        public URL JavaDoc getURL(int arg0) throws SQLException JavaDoc {
3727            throw new NotImplemented();
3728        }
3729
3730        /**
3731         * @see CallableStatement#getURL(String)
3732         */

3733        public URL JavaDoc getURL(String JavaDoc arg0) throws SQLException JavaDoc {
3734            throw new NotImplemented();
3735        }
3736
3737        public void setUnicodeStream(int p1, final java.io.InputStream JavaDoc p2,
3738            int p3) throws java.sql.SQLException JavaDoc {
3739            delegate.setUnicodeStream(p1, p2, p3);
3740        }
3741
3742        public int getUpdateCount() throws java.sql.SQLException JavaDoc {
3743            return delegate.getUpdateCount();
3744        }
3745
3746        public java.sql.SQLWarning JavaDoc getWarnings() throws java.sql.SQLException JavaDoc {
3747            return delegate.getWarnings();
3748        }
3749
3750        public void addBatch() throws java.sql.SQLException JavaDoc {
3751            delegate.addBatch();
3752        }
3753
3754        public void addBatch(java.lang.String JavaDoc p1) throws java.sql.SQLException JavaDoc {
3755            delegate.addBatch(p1);
3756        }
3757
3758        public void cancel() throws java.sql.SQLException JavaDoc {
3759            delegate.cancel();
3760        }
3761
3762        public void clearBatch() throws java.sql.SQLException JavaDoc {
3763            delegate.clearBatch();
3764        }
3765
3766        public void clearParameters() throws java.sql.SQLException JavaDoc {
3767            delegate.clearParameters();
3768        }
3769
3770        public void clearWarnings() throws java.sql.SQLException JavaDoc {
3771            delegate.clearWarnings();
3772        }
3773
3774        public void close() throws java.sql.SQLException JavaDoc {
3775            delegate.close();
3776        }
3777
3778        public boolean execute() throws java.sql.SQLException JavaDoc {
3779            return delegate.execute();
3780        }
3781
3782        public boolean execute(java.lang.String JavaDoc p1)
3783            throws java.sql.SQLException JavaDoc {
3784            return delegate.execute(p1);
3785        }
3786
3787        /**
3788         * @see Statement#execute(String, int)
3789         */

3790        public boolean execute(String JavaDoc arg0, int arg1) throws SQLException JavaDoc {
3791            return delegate.execute(arg0, arg1);
3792        }
3793
3794        /**
3795         * @see Statement#execute(String, int[])
3796         */

3797        public boolean execute(String JavaDoc arg0, int[] arg1)
3798            throws SQLException JavaDoc {
3799            return delegate.execute(arg0, arg1);
3800        }
3801
3802        /**
3803         * @see Statement#execute(String, String[])
3804         */

3805        public boolean execute(String JavaDoc arg0, String JavaDoc[] arg1)
3806            throws SQLException JavaDoc {
3807            return delegate.execute(arg0, arg1);
3808        }
3809
3810        public int[] executeBatch() throws java.sql.SQLException JavaDoc {
3811            return delegate.executeBatch();
3812        }
3813
3814        public java.sql.ResultSet JavaDoc executeQuery() throws java.sql.SQLException JavaDoc {
3815            return delegate.executeQuery();
3816        }
3817
3818        public java.sql.ResultSet JavaDoc executeQuery(java.lang.String JavaDoc p1)
3819            throws java.sql.SQLException JavaDoc {
3820            return delegate.executeQuery(p1);
3821        }
3822
3823        public int executeUpdate() throws java.sql.SQLException JavaDoc {
3824            return delegate.executeUpdate();
3825        }
3826
3827        public int executeUpdate(java.lang.String JavaDoc p1)
3828            throws java.sql.SQLException JavaDoc {
3829            return delegate.executeUpdate(p1);
3830        }
3831
3832        /**
3833         * @see Statement#executeUpdate(String, int)
3834         */

3835        public int executeUpdate(String JavaDoc arg0, int arg1)
3836            throws SQLException JavaDoc {
3837            return delegate.executeUpdate(arg0, arg1);
3838        }
3839
3840        /**
3841         * @see Statement#executeUpdate(String, int[])
3842         */

3843        public int executeUpdate(String JavaDoc arg0, int[] arg1)
3844            throws SQLException JavaDoc {
3845            return delegate.executeUpdate(arg0, arg1);
3846        }
3847
3848        /**
3849         * @see Statement#executeUpdate(String, String[])
3850         */

3851        public int executeUpdate(String JavaDoc arg0, String JavaDoc[] arg1)
3852            throws SQLException JavaDoc {
3853            return delegate.executeUpdate(arg0, arg1);
3854        }
3855
3856        public void registerOutParameter(int p1, int p2)
3857            throws java.sql.SQLException JavaDoc {
3858            throw new SQLException JavaDoc("Not supported");
3859        }
3860
3861        public void registerOutParameter(int p1, int p2, int p3)
3862            throws java.sql.SQLException JavaDoc {
3863            throw new SQLException JavaDoc("Not supported");
3864        }
3865
3866        public void registerOutParameter(int p1, int p2, java.lang.String JavaDoc p3)
3867            throws java.sql.SQLException JavaDoc {
3868            throw new SQLException JavaDoc("Not supported");
3869        }
3870
3871        /**
3872         * @see CallableStatement#registerOutParameter(String, int, int)
3873         */

3874        public void registerOutParameter(String JavaDoc arg0, int arg1, int arg2)
3875            throws SQLException JavaDoc {
3876            throw new NotImplemented();
3877        }
3878
3879        /**
3880         * @see CallableStatement#registerOutParameter(String, int, String)
3881         */

3882        public void registerOutParameter(String JavaDoc arg0, int arg1, String JavaDoc arg2)
3883            throws SQLException JavaDoc {
3884            throw new NotImplemented();
3885        }
3886
3887        /**
3888         * @see CallableStatement#registerOutParameter(String, int)
3889         */

3890        public void registerOutParameter(String JavaDoc arg0, int arg1)
3891            throws SQLException JavaDoc {
3892            throw new NotImplemented();
3893        }
3894
3895        public boolean wasNull() throws java.sql.SQLException JavaDoc {
3896            throw new SQLException JavaDoc("Not supported");
3897        }
3898    }
3899}
3900
Popular Tags