📄 connectionproperties.java
字号:
/* Copyright (C) 2002-2004 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. There are special exceptions to the terms and conditions of the GPL as it is applied to this software. View the full text of the exception in file EXCEPTIONS-CONNECTOR-J in the directory of this software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package com.mysql.jdbc;import com.mysql.jdbc.log.Log;import com.mysql.jdbc.log.StandardLogger;import java.io.UnsupportedEncodingException;import java.sql.DriverPropertyInfo;import java.sql.SQLException;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Properties;import java.util.TreeMap;import javax.naming.RefAddr;import javax.naming.Reference;import javax.naming.StringRefAddr;/** * Represents configurable properties for Connections and DataSources. Can also * expose properties as JDBC DriverPropertyInfo if required as well. * * @author Mark Matthews * @version $Id: ConnectionProperties.java,v 1.1.2.65 2005/02/17 15:36:33 mmatthews Exp $ */public class ConnectionProperties { private static final ArrayList PROPERTY_LIST = new ArrayList(); private static final String CONNECTION_AND_AUTH_CATEGORY = "Connection/Authentication"; private static final String HA_CATEGORY = "High Availability and Clustering"; private static final String SECURITY_CATEGORY = "Security"; private static final String PERFORMANCE_CATEGORY = "Performance Extensions"; private static final String DEBUGING_PROFILING_CATEGORY = "Debuging/Profiling"; private static final String MISC_CATEGORY = "Miscellaneous"; private static final String[] propertyCategories = new String[] { CONNECTION_AND_AUTH_CATEGORY, HA_CATEGORY, SECURITY_CATEGORY, PERFORMANCE_CATEGORY, DEBUGING_PROFILING_CATEGORY, MISC_CATEGORY }; protected static final String ZERO_DATETIME_BEHAVIOR_EXCEPTION = "exception"; protected static final String ZERO_DATETIME_BEHAVIOR_ROUND = "round"; protected static final String ZERO_DATETIME_BEHAVIOR_CONVERT_TO_NULL = "convertToNull"; static { try { java.lang.reflect.Field[] declaredFields = ConnectionProperties.class.getDeclaredFields(); for (int i = 0; i < declaredFields.length; i++) { if (ConnectionProperties.ConnectionProperty.class.isAssignableFrom( declaredFields[i].getType())) { PROPERTY_LIST.add(declaredFields[i]); } } } catch (Exception ex) { throw new RuntimeException(ex.toString()); } } private BooleanConnectionProperty alwaysSendSetIsolation = new BooleanConnectionProperty("alwaysSendSetIsolation", true, "Should the driver always communicate with the database when " +" Connection.setTransactionIsolation() is called? " + "If set to false, the driver will only communicate with the " + "database when the requested transaction isolation is different " + "than the whichever is newer, the last value that was set via " + "Connection.setTransactionIsolation(), or the value that was read from " + "the server when the connection was established.", "3.1.7", PERFORMANCE_CATEGORY, Integer.MAX_VALUE); private BooleanConnectionProperty allowLoadLocalInfile = new BooleanConnectionProperty("allowLoadLocalInfile", true, "Should the driver allow use of 'LOAD DATA LOCAL INFILE...' (defaults to 'true').", "3.0.3", SECURITY_CATEGORY, Integer.MAX_VALUE); private BooleanConnectionProperty allowNanAndInf = new BooleanConnectionProperty("allowNanAndInf", false, "Should the driver allow NaN or +/- INF values in PreparedStatement.setDouble()?", "3.1.5", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty allowUrlInLocalInfile = new BooleanConnectionProperty("allowUrlInLocalInfile", false, "Should the driver allow URLs in 'LOAD DATA LOCAL INFILE' statements?", "3.1.4", SECURITY_CATEGORY, Integer.MAX_VALUE); private BooleanConnectionProperty allowMultiQueries = new BooleanConnectionProperty("allowMultiQueries", false, "Allow the use of ';' to delimit multiple queries during one statement (true/false, defaults to 'false'", "3.1.1", SECURITY_CATEGORY, 1); private BooleanConnectionProperty autoDeserialize = new BooleanConnectionProperty("autoDeserialize", false, "Should the driver automatically detect and de-serialize objects stored in BLOB fields?", "3.1.5", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty autoReconnect = new BooleanConnectionProperty("autoReconnect", false, "Should the driver try to re-establish bad connections?", "1.1", HA_CATEGORY, 0); private BooleanConnectionProperty autoReconnectForPools = new BooleanConnectionProperty("autoReconnectForPools", false, "Use a reconnection strategy appropriate for connection pools (defaults to 'false')", "3.1.3", HA_CATEGORY, 1); private BooleanConnectionProperty cacheCallableStatements = new BooleanConnectionProperty("cacheCallableStmts", false, "Should the driver cache the parsing stage of CallableStatements", "3.1.2", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty cacheServerConfiguration = new BooleanConnectionProperty("cacheServerConfiguration", false, "Should the driver cache the results of " + "'SHOW VARIABLES' and 'SHOW COLLATION' on a per-URL basis?", "3.1.5", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty cachePreparedStatements = new BooleanConnectionProperty("cachePrepStmts", false, "Should the driver cache the parsing stage of PreparedStatements?", "3.0.10", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty cacheResultSetMetadata = new BooleanConnectionProperty("cacheResultSetMetadata", false, "Should the driver cache ResultSetMetaData for Statements and PreparedStatements? (Req. JDK-1.4+, true/false, default 'false')", "3.1.1", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty capitalizeTypeNames = new BooleanConnectionProperty("capitalizeTypeNames", false, "Capitalize type names in DatabaseMetaData? (usually only useful when using WebObjects, true/false, defaults to 'false')", "2.0.7", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty clobberStreamingResults = new BooleanConnectionProperty("clobberStreamingResults", false, "This will cause a 'streaming' ResultSet to be automatically closed, " + "and any oustanding data still streaming from the server to be discarded if another query is executed " + "before all the data has been read from the server.", "3.0.9", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty continueBatchOnError = new BooleanConnectionProperty("continueBatchOnError", true, "Should the driver continue processing batch commands if " + "one statement fails. The JDBC spec allows either way (defaults to 'true').", "3.0.3", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty detectServerPreparedStmts = new BooleanConnectionProperty("useServerPrepStmts", true, "Use server-side prepared statements if the server supports them? (defaults to 'true').", "3.1.0", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty dontTrackOpenResources = new BooleanConnectionProperty("dontTrackOpenResources", false, "The JDBC specification requires the driver to automatically track and close resources, " + "however if your application doesn't do a good job of " + "explicitly calling close() on statements or result sets, " + "this can cause memory leakage. Setting this property to true " + "relaxes this constraint, and can be more memory efficient for " + "some applications.", "3.1.7", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty emulateUnsupportedPstmts = new BooleanConnectionProperty("emulateUnsupportedPstmts", true, "Should the driver detect prepared statements that are not supported by the server, and " + "replace them with client-side emulated versions?","3.1.7", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty dumpQueriesOnException = new BooleanConnectionProperty("dumpQueriesOnException", false, "Should the driver dump the contents of the query sent to the server in the message for SQLExceptions?", "3.1.3", DEBUGING_PROFILING_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty dynamicCalendars = new BooleanConnectionProperty("dynamicCalendars", false, "Should the driver retrieve the default" + " calendar when required, or cache it per connection/session?", "3.1.5", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty elideSetAutoCommits = new BooleanConnectionProperty("elideSetAutoCommits", false, "If using MySQL-4.1 or newer, should the driver only issue 'set autocommit=n' queries when the server's state doesn't match the requested state by Connection.setAutoCommit(boolean)?", "3.1.3", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty emulateLocators = new BooleanConnectionProperty("emulateLocators", false, "N/A", "3.1.0", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty enablePacketDebug = new BooleanConnectionProperty("enablePacketDebug", false, "When enabled, a ring-buffer of 'packetDebugBufferSize' packets will be kept, and dumped when exceptions are thrown in key areas in the driver's code", "3.1.3", DEBUGING_PROFILING_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty explainSlowQueries = new BooleanConnectionProperty("explainSlowQueries", false, "If 'logSlowQueries' is enabled, should the driver automatically issue an 'EXPLAIN' on the" + " server and send the results to the configured log at a WARN level?", "3.1.2", DEBUGING_PROFILING_CATEGORY, Integer.MIN_VALUE); /** When failed-over, set connection to read-only? */ private BooleanConnectionProperty failOverReadOnly = new BooleanConnectionProperty("failOverReadOnly", true, "When failing over in autoReconnect mode, should the connection be set to 'read-only'?", "3.0.12", HA_CATEGORY, 2); private BooleanConnectionProperty gatherPerformanceMetrics = new BooleanConnectionProperty("gatherPerfMetrics", false, "Should the driver gather performance metrics, and report them via the configured logger every 'reportMetricsIntervalMillis' milliseconds?", "3.1.2", DEBUGING_PROFILING_CATEGORY, 1); private BooleanConnectionProperty holdResultsOpenOverStatementClose = new BooleanConnectionProperty("holdResultsOpenOverStatementClose", false, "Should the driver close result sets on Statement.close() as required by the JDBC specification?", "3.1.7", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty ignoreNonTxTables = new BooleanConnectionProperty("ignoreNonTxTables", false, "Ignore non-transactional table warning for rollback? (defaults to 'false').", "3.0.9", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty isInteractiveClient = new BooleanConnectionProperty("interactiveClient", false, "Set the CLIENT_INTERACTIVE flag, which tells MySQL " + "to timeout connections based on INTERACTIVE_TIMEOUT instead of WAIT_TIMEOUT", "3.1.0", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty jdbcCompliantTruncation = new BooleanConnectionProperty("jdbcCompliantTruncation", true, "Should the driver throw java.sql.DataTruncation" + " exceptions when data is truncated as is required by the JDBC specification when connected to a server that supports warnings" + "(MySQL 4.1.0 and newer)?", "3.1.2", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty logSlowQueries = new BooleanConnectionProperty("logSlowQueries", false, "Should queries that take longer than 'slowQueryThresholdMillis' be logged?", "3.1.2", DEBUGING_PROFILING_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty paranoid = new BooleanConnectionProperty("paranoid", false, "Take measures to prevent exposure sensitive information in error messages and clear " + "data structures holding sensitive data when possible? (defaults to 'false')", "3.0.1", SECURITY_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty pedantic = new BooleanConnectionProperty("pedantic", false, "Follow the JDBC spec to the letter.", "3.0.0", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty profileSQL = new BooleanConnectionProperty("profileSQL", false, "Trace queries and their execution/fetch times to the configured logger (true/false) defaults to 'false'", "3.1.0", DEBUGING_PROFILING_CATEGORY, 1); private StringConnectionProperty propertiesTransform = new StringConnectionProperty(NonRegisteringDriver.PROPERTIES_TRANSFORM_KEY, null, "An implementation of com.mysql.jdbc.ConnectionPropertiesTransform that the driver will use to modify URL properties passed to the driver before attempting a connection", "3.1.4", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty reconnectAtTxEnd = new BooleanConnectionProperty("reconnectAtTxEnd", false, "If autoReconnect is set to true, should the driver attempt reconnections" + "at the end of every transaction?", "3.0.10", HA_CATEGORY, 4); private BooleanConnectionProperty relaxAutoCommit = new BooleanConnectionProperty("relaxAutoCommit", false, "If the version of MySQL the driver connects to does not support transactions, still allow calls to commit(), rollback() and setAutoCommit() (true/false, defaults to 'false')?", "2.0.13", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty requireSSL = new BooleanConnectionProperty("requireSSL", false, "Require SSL connection if useSSL=true? (defaults to 'false').", "3.1.0", SECURITY_CATEGORY, 3); private BooleanConnectionProperty rollbackOnPooledClose = new BooleanConnectionProperty("rollbackOnPooledClose", true, "Should the driver issue a rollback() when the logical connection in a pool is closed?", "3.0.15", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty roundRobinLoadBalance = new BooleanConnectionProperty("roundRobinLoadBalance", false, "When autoReconnect is enabled, and failoverReadonly is false, should we pick hosts to connect to on a round-robin basis?", "3.1.2", HA_CATEGORY, 5); private BooleanConnectionProperty runningCTS13 = new BooleanConnectionProperty("runningCTS13", false, "Enables workarounds for bugs in Sun's JDBC compliance testsuite version 1.3", "3.1.7", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty strictFloatingPoint = new BooleanConnectionProperty("strictFloatingPoint", false, "Used only in older versions of compliance test", "3.0.0", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty strictUpdates = new BooleanConnectionProperty("strictUpdates", true, "Should the driver do strict checking (all primary keys selected) of updatable result sets (true, false, defaults to 'true')?", "3.0.4", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty traceProtocol = new BooleanConnectionProperty("traceProtocol", false, "Should trace-level network protocol be logged?", "3.1.2", DEBUGING_PROFILING_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty tinyInt1isBit = new BooleanConnectionProperty("tinyInt1isBit", true, "Should the driver treat the datatype TINYINT(1) as the BIT type " + "(because the server silently converts BIT -> TINYINT(1) when creating tables)?", "3.0.16", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useCompression = new BooleanConnectionProperty("useCompression", false, "Use zlib compression when communicating with the server (true/false)? Defaults to 'false'.", "3.1.0", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE); private StringConnectionProperty useConfig = new StringConnectionProperty("useConfigs", null, "Load the comma-delimited list of configuration properties before parsing the " + "URL or applying user-specified properties. These configurations are explained in the 'Configurations' of the documentation.", "3.1.5", CONNECTION_AND_AUTH_CATEGORY, Integer.MAX_VALUE); private BooleanConnectionProperty useFastIntParsing = new BooleanConnectionProperty("useFastIntParsing", true, "Use internal String->Integer conversion routines to avoid excessive object creation?", "3.1.4", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useHostsInPrivileges = new BooleanConnectionProperty("useHostsInPrivileges", true, "Add '@hostname' to users in DatabaseMetaData.getColumn/TablePrivileges() (true/false), defaults to 'true'.", "3.0.2", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useLocalSessionState = new BooleanConnectionProperty("useLocalSessionState", false, "Should the driver refer to the internal values of autocommit and transaction isolation that are set " + " by Connection.setAutoCommit() and Connection.setTransactionIsolation(), rather than querying the database?", "3.1.7", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useNewIo = new BooleanConnectionProperty("useNewIO", false, "Should the driver use the java.nio.* interfaces for network communication (true/false), defaults to 'false'", "3.1.0", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useOldUTF8Behavior = new BooleanConnectionProperty("useOldUTF8Behavior", false, "Use the UTF-8 behavior the driver did when communicating with 4.0 and older servers", "3.1.6", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useOnlyServerErrorMessages = new BooleanConnectionProperty("useOnlyServerErrorMessages", true, "Don't prepend 'standard' SQLState error messages to error messages returned by the server.", "3.0.15", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useReadAheadInput = new BooleanConnectionProperty("useReadAheadInput", true, "Use newer, optimized non-blocking, buffered input stream when reading from the server?", "3.1.5", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useSSL = new BooleanConnectionProperty("useSSL", false, "Use SSL when communicating with the server (true/false), defaults to 'false'", "3.0.2", SECURITY_CATEGORY, 2); private BooleanConnectionProperty useSqlStateCodes = new BooleanConnectionProperty("useSqlStateCodes", true, "Use SQL Standard state codes instead of 'legacy' X/Open/SQL state codes (true/false), default is 'true'", "3.1.3", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useStreamLengthsInPrepStmts = new BooleanConnectionProperty("useStreamLengthsInPrepStmts", true, "Honor stream length parameter in " + "PreparedStatement/ResultSet.setXXXStream() method calls (true/false, defaults to 'true')?", "3.0.2", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useTimezone = new BooleanConnectionProperty("useTimezone", false, "Convert time/date types between client and server timezones (true/false, defaults to 'false')?", "3.0.2", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useUltraDevWorkAround = new BooleanConnectionProperty("ultraDevHack", false, "Create PreparedStatements for prepareCall() when required, because UltraDev " + " is broken and issues a prepareCall() for _all_ statements? (true/false, defaults to 'false')", "2.0.3", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useUnbufferedInput = new BooleanConnectionProperty("useUnbufferedInput", true, "Don't use BufferedInputStream for reading data from the server", "3.0.11", MISC_CATEGORY, Integer.MIN_VALUE); private BooleanConnectionProperty useUnicode = new BooleanConnectionProperty("useUnicode", false, "Should the driver use Unicode character encodings when handling strings? Should only be used when the driver can't determine the character set mapping, or you are trying to 'force' the driver to use a character set that MySQL either doesn't natively support (such as UTF-8), true/false, defaults to 'true'", "1.1g", MISC_CATEGORY, 0); private BooleanConnectionProperty useUsageAdvisor = new BooleanConnectionProperty("useUsageAdvisor", false, "Should the driver issue 'usage' warnings advising proper and efficient usage of JDBC and MySQL Connector/J to the log (true/false, defaults to 'false')?", "3.1.1", DEBUGING_PROFILING_CATEGORY, 10); private IntegerConnectionProperty callableStatementCacheSize = new IntegerConnectionProperty("callableStmtCacheSize", 100, 0, Integer.MAX_VALUE, "If 'cacheCallableStmts' is enabled, how many callable statements should be cached?", "3.1.2", PERFORMANCE_CATEGORY, 5); private IntegerConnectionProperty connectTimeout = new IntegerConnectionProperty("connectTimeout", 0, 0, Integer.MAX_VALUE, "Timeout for socket connect (in milliseconds), with 0 being no timeout. " + "Only works on JDK-1.4 or newer. Defaults to '0'.", "3.0.1", CONNECTION_AND_AUTH_CATEGORY, 9); private IntegerConnectionProperty initialTimeout = new IntegerConnectionProperty("initialTimeout", 2, 1, Integer.MAX_VALUE, "If autoReconnect is enabled, the" + " initial time to wait between" + " re-connect attempts (in seconds, defaults to '2').", "1.1", HA_CATEGORY, 5); private IntegerConnectionProperty maxQuerySizeToLog = new IntegerConnectionProperty("maxQuerySizeToLog", 2048, 0, Integer.MAX_VALUE, "Controls the maximum length/size of a query that will get logged when profiling or tracing", "3.1.3", DEBUGING_PROFILING_CATEGORY, 4); private IntegerConnectionProperty maxReconnects = new IntegerConnectionProperty("maxReconnects", 3, 1, Integer.MAX_VALUE, "Maximum number of reconnects to attempt if autoReconnect is true, default is '3'.", "1.1", HA_CATEGORY, 4); private IntegerConnectionProperty maxRows = new IntegerConnectionProperty("maxRows", -1, -1, Integer.MAX_VALUE, "The maximum number of rows to return " + " (0, the default means return all rows).", "all versions", MISC_CATEGORY, Integer.MIN_VALUE); private IntegerConnectionProperty metadataCacheSize = new IntegerConnectionProperty("metadataCacheSize", 50, 1, Integer.MAX_VALUE, "The number of queries to cache" + "ResultSetMetadata for if cacheResultSetMetaData is set to 'true' (default 50)", "3.1.1", PERFORMANCE_CATEGORY, 5); private BooleanConnectionProperty noDatetimeStringSync = new BooleanConnectionProperty("noDatetimeStringSync", false, "Don't ensure that ResultSet.getDatetimeType().toString().equals(ResultSet.getString())", "3.1.7", MISC_CATEGORY, Integer.MIN_VALUE); private IntegerConnectionProperty packetDebugBufferSize = new IntegerConnectionProperty("packetDebugBufferSize", 20, 0, Integer.MAX_VALUE, "The maximum number of packets to retain when 'enablePacketDebug' is true", "3.1.3", DEBUGING_PROFILING_CATEGORY, 7); private IntegerConnectionProperty preparedStatementCacheSize = new IntegerConnectionProperty("prepStmtCacheSize", 25, 0, Integer.MAX_VALUE, "If prepared statement caching is enabled, " + "how many prepared statements should be cached?", "3.0.10", PERFORMANCE_CATEGORY, 10); private IntegerConnectionProperty preparedStatementCacheSqlLimit = new IntegerConnectionProperty("prepStmtCacheSqlLimit", 256, 1, Integer.MAX_VALUE, "If prepared statement caching is enabled, " + "what's the largest SQL the driver will cache the parsing for?",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -