2
Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
2
Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
4
4
The MySQL Connector/J is licensed under the terms of the GPLv2
5
5
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
28
28
import java.sql.SQLException;
29
29
import java.util.ArrayList;
30
30
import java.util.HashMap;
31
import java.util.Iterator;
32
31
import java.util.Map;
33
32
import java.util.Properties;
34
33
import java.util.TreeMap;
629
631
HA_CATEGORY, SECURITY_CATEGORY,
630
632
PERFORMANCE_CATEGORY, DEBUGING_PROFILING_CATEGORY, MISC_CATEGORY };
632
private static final ArrayList PROPERTY_LIST = new ArrayList();
634
private static final ArrayList<java.lang.reflect.Field> PROPERTY_LIST = new ArrayList<java.lang.reflect.Field>();
635
637
// Yes, this looks goofy, but we're trying to avoid intern()ing here
682
684
protected static DriverPropertyInfo[] exposeAsDriverPropertyInfo(
683
685
Properties info, int slotsToReserve) throws SQLException {
684
686
return (new ConnectionPropertiesImpl() {
687
private static final long serialVersionUID = 4257801713007640581L;
685
688
}).exposeAsDriverPropertyInfoInternal(info, slotsToReserve);
795
798
private boolean cacheResultSetMetaDataAsBoolean;
800
private StringConnectionProperty serverConfigCacheFactory = new StringConnectionProperty("serverConfigCacheFactory", //$NON-NLS-1$
801
PerVmServerConfigCacheFactory.class.getName(), Messages.getString("ConnectionProperties.serverConfigCacheFactory"), "5.1.1", PERFORMANCE_CATEGORY, 12); //$NON-NLS-1$ //$NON-NLS-2$
797
803
private BooleanConnectionProperty cacheServerConfiguration = new BooleanConnectionProperty(
798
804
"cacheServerConfiguration", //$NON-NLS-1$
821
827
"1.1g", MISC_CATEGORY, 5); //$NON-NLS-1$
823
829
private String characterEncodingAsString = null;
831
protected boolean characterEncodingIsAliasForSjis = false;
825
833
private StringConnectionProperty characterSetResults = new StringConnectionProperty(
826
834
"characterSetResults", null, //$NON-NLS-1$
827
835
Messages.getString("ConnectionProperties.characterSetResults"), "3.0.13", //$NON-NLS-1$ //$NON-NLS-2$
828
836
MISC_CATEGORY, 6);
838
private StringConnectionProperty connectionAttributes = new StringConnectionProperty(
839
"connectionAttributes", null, //$NON-NLS-1$
840
Messages.getString("ConnectionProperties.connectionAttributes"), "5.1.25", //$NON-NLS-1$ //$NON-NLS-2$
830
844
private StringConnectionProperty clientInfoProvider = new StringConnectionProperty(
831
845
"clientInfoProvider", "com.mysql.jdbc.JDBC4CommentClientInfoProvider", //$NON-NLS-1$ //$NON-NLS-2$
882
896
private IntegerConnectionProperty defaultFetchSize = new IntegerConnectionProperty("defaultFetchSize", 0, Messages.getString("ConnectionProperties.defaultFetchSize"), "3.1.9", PERFORMANCE_CATEGORY, Integer.MIN_VALUE); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
898
// Think really long and hard about changing the default for this
899
// many, many applications have come to be acustomed to the
900
// latency profile of preparing stuff client-side, rather than
901
// prepare (round-trip), execute (round-trip), close (round-trip).
884
902
private BooleanConnectionProperty detectServerPreparedStmts = new BooleanConnectionProperty(
885
903
"useServerPrepStmts", //$NON-NLS-1$
1258
1276
Messages.getString("ConnectionProperties.prepStmtCacheSqlLimit"), //$NON-NLS-1$
1259
1277
"3.0.10", PERFORMANCE_CATEGORY, 11); //$NON-NLS-1$
1279
private StringConnectionProperty parseInfoCacheFactory = new StringConnectionProperty("parseInfoCacheFactory", //$NON-NLS-1$
1280
PerConnectionLRUFactory.class.getName(), Messages.getString("ConnectionProperties.parseInfoCacheFactory"), "5.1.1", PERFORMANCE_CATEGORY, 12); //$NON-NLS-1$ //$NON-NLS-2$
1261
1282
private BooleanConnectionProperty processEscapeCodesForPrepStmts =
1262
1283
new BooleanConnectionProperty("processEscapeCodesForPrepStmts", //$NON-NLS-1$
1777
1798
private IntegerConnectionProperty maxAllowedPacket = new IntegerConnectionProperty("maxAllowedPacket",
1778
1799
-1, Messages.getString("ConnectionProperties.maxAllowedPacket"), "5.1.8", NETWORK_CATEGORY,
1779
1800
Integer.MIN_VALUE);
1802
private StringConnectionProperty authenticationPlugins = new StringConnectionProperty(
1803
"authenticationPlugins",
1805
Messages.getString("ConnectionProperties.authenticationPlugins"),
1806
"5.1.19", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
1808
private StringConnectionProperty disabledAuthenticationPlugins = new StringConnectionProperty(
1809
"disabledAuthenticationPlugins",
1811
Messages.getString("ConnectionProperties.disabledAuthenticationPlugins"),
1812
"5.1.19", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
1814
private StringConnectionProperty defaultAuthenticationPlugin = new StringConnectionProperty(
1815
"defaultAuthenticationPlugin",
1816
"com.mysql.jdbc.authentication.MysqlNativePasswordPlugin",
1817
Messages.getString("ConnectionProperties.defaultAuthenticationPlugin"),
1818
"5.1.19", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
1820
private BooleanConnectionProperty disconnectOnExpiredPasswords = new BooleanConnectionProperty("disconnectOnExpiredPasswords",
1822
Messages.getString("ConnectionProperties.disconnectOnExpiredPasswords"),
1823
"5.1.23", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
1781
1827
protected DriverPropertyInfo[] exposeAsDriverPropertyInfoInternal(
1782
1828
Properties info, int slotsToReserve) throws SQLException {
1892
protected Map<Integer, Map<String, ConnectionProperty>> ordered = new TreeMap<Integer, Map<String, ConnectionProperty>>();
1893
protected Map<String, ConnectionProperty> alpha = new TreeMap<String, ConnectionProperty>();
1845
1896
/* (non-Javadoc)
1846
1897
* @see com.mysql.jdbc.IConnectionProperties#exposeAsXml()
1854
1905
int numCategories = PROPERTY_CATEGORIES.length;
1856
Map propertyListByCategory = new HashMap();
1907
Map<String, XmlMap> propertyListByCategory = new HashMap<String, XmlMap>();
1858
1909
for (int i = 0; i < numCategories; i++) {
1859
propertyListByCategory.put(PROPERTY_CATEGORIES[i], new Map[] {
1860
new TreeMap(), new TreeMap() });
1910
propertyListByCategory.put(PROPERTY_CATEGORIES[i], new XmlMap());
1875
1925
Messages.getString("ConnectionProperties.Password"), Messages.getString("ConnectionProperties.allVersions"), //$NON-NLS-1$ //$NON-NLS-2$
1876
1926
CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE + 2);
1878
Map[] connectionSortMaps = (Map[]) propertyListByCategory
1879
.get(CONNECTION_AND_AUTH_CATEGORY);
1880
TreeMap userMap = new TreeMap();
1928
XmlMap connectionSortMaps = propertyListByCategory.get(CONNECTION_AND_AUTH_CATEGORY);
1929
TreeMap<String, ConnectionProperty> userMap = new TreeMap<String, ConnectionProperty>();
1881
1930
userMap.put(userProp.getPropertyName(), userProp);
1883
connectionSortMaps[0].put(Integer.valueOf(userProp.getOrder()), userMap);
1932
connectionSortMaps.ordered.put(Integer.valueOf(userProp.getOrder()), userMap);
1885
TreeMap passwordMap = new TreeMap();
1934
TreeMap<String, ConnectionProperty> passwordMap = new TreeMap<String, ConnectionProperty>();
1886
1935
passwordMap.put(passwordProp.getPropertyName(), passwordProp);
1888
connectionSortMaps[0]
1889
.put(new Integer(passwordProp.getOrder()), passwordMap);
1937
connectionSortMaps.ordered.put(new Integer(passwordProp.getOrder()), passwordMap);
1892
1940
for (int i = 0; i < numPropertiesToSet; i++) {
1893
java.lang.reflect.Field propertyField = (java.lang.reflect.Field) PROPERTY_LIST
1941
java.lang.reflect.Field propertyField = PROPERTY_LIST
1895
1943
ConnectionProperty propToGet = (ConnectionProperty) propertyField
1897
Map[] sortMaps = (Map[]) propertyListByCategory.get(propToGet
1945
XmlMap sortMaps = propertyListByCategory.get(propToGet
1898
1946
.getCategoryName());
1899
1947
int orderInCategory = propToGet.getOrder();
1901
1949
if (orderInCategory == Integer.MIN_VALUE) {
1902
sortMaps[1].put(propToGet.getPropertyName(), propToGet);
1950
sortMaps.alpha.put(propToGet.getPropertyName(), propToGet);
1904
1952
Integer order = Integer.valueOf(orderInCategory);
1906
Map orderMap = (Map)sortMaps[0].get(order);
1953
Map<String, ConnectionProperty> orderMap = sortMaps.ordered.get(order);
1908
1955
if (orderMap == null) {
1909
orderMap = new TreeMap();
1910
sortMaps[0].put(order, orderMap);
1956
orderMap = new TreeMap<String, ConnectionProperty>();
1957
sortMaps.ordered.put(order, orderMap);
1913
1960
orderMap.put(propToGet.getPropertyName(), propToGet);
1917
1964
for (int j = 0; j < numCategories; j++) {
1918
Map[] sortMaps = (Map[]) propertyListByCategory
1919
.get(PROPERTY_CATEGORIES[j]);
1920
Iterator orderedIter = sortMaps[0].values().iterator();
1921
Iterator alphaIter = sortMaps[1].values().iterator();
1965
XmlMap sortMaps = propertyListByCategory.get(PROPERTY_CATEGORIES[j]);
1923
1967
xmlBuf.append("\n <PropertyCategory name=\""); //$NON-NLS-1$
1924
1968
xmlBuf.append(PROPERTY_CATEGORIES[j]);
1925
1969
xmlBuf.append("\">"); //$NON-NLS-1$
1927
while (orderedIter.hasNext()) {
1928
Iterator orderedAlphaIter = ((Map)orderedIter.next()).values().iterator();
1930
while (orderedAlphaIter.hasNext()) {
1931
ConnectionProperty propToGet = (ConnectionProperty) orderedAlphaIter
1971
for (Map<String, ConnectionProperty> orderedEl : sortMaps.ordered.values()) {
1972
for (ConnectionProperty propToGet : orderedEl.values()) {
1934
1973
xmlBuf.append("\n <Property name=\""); //$NON-NLS-1$
1935
1974
xmlBuf.append(propToGet.getPropertyName());
1936
1975
xmlBuf.append("\" required=\""); //$NON-NLS-1$
1948
1987
xmlBuf.append(propToGet.sinceVersion);
1949
1988
xmlBuf.append("\">\n"); //$NON-NLS-1$
1950
1989
xmlBuf.append(" "); //$NON-NLS-1$
1951
xmlBuf.append(propToGet.description);
1990
String escapedDescription = propToGet.description;
1991
escapedDescription = escapedDescription.replace("&", "&").replace("<", "<").replace(">", ">");
1993
xmlBuf.append(escapedDescription);
1952
1994
xmlBuf.append("\n </Property>"); //$NON-NLS-1$
1956
while (alphaIter.hasNext()) {
1957
ConnectionProperty propToGet = (ConnectionProperty) alphaIter
1998
for (ConnectionProperty propToGet : sortMaps.alpha.values()) {
1960
1999
xmlBuf.append("\n <Property name=\""); //$NON-NLS-1$
1961
2000
xmlBuf.append(propToGet.getPropertyName());
1962
2001
xmlBuf.append("\" required=\""); //$NON-NLS-1$
2100
2139
public String getCharacterSetResults() {
2101
2140
return this.characterSetResults.getValueAsString();
2143
public String getConnectionAttributes() {
2144
return this.connectionAttributes.getValueAsString();
2147
public void setConnectionAttributes(String val) {
2148
this.connectionAttributes.setValue(val);
2104
2151
/* (non-Javadoc)
2105
2152
* @see com.mysql.jdbc.IConnectionProperties#getClobberStreamingResults()
2808
2855
// can't be used
2810
2857
String testString = "abc"; //$NON-NLS-1$
2811
testString.getBytes(testEncoding);
2858
StringUtils.getBytes(testString, testEncoding);
2812
2859
} catch (UnsupportedEncodingException UE) {
2813
2860
throw SQLError.createSQLException(Messages.getString(
2814
2861
"ConnectionProperties.unsupportedCharacterEncoding",
2833
2880
this.useUnicodeAsBoolean = this.useUnicode.getValueAsBoolean();
2834
2881
this.characterEncodingAsString = ((String) this.characterEncoding
2835
2882
.getValueAsObject());
2883
this.characterEncodingIsAliasForSjis = CharsetMapping.isAliasForSjis(this.characterEncodingAsString);
2836
2884
this.highAvailabilityAsBoolean = this.autoReconnect.getValueAsBoolean();
2837
2885
this.autoReconnectForPoolsAsBoolean = this.autoReconnectForPools
2838
2886
.getValueAsBoolean();
4639
4688
return includeThreadNamesAsStatementComment.getValueAsBoolean();
4691
public void setAuthenticationPlugins(String authenticationPlugins) {
4692
this.authenticationPlugins.setValue(authenticationPlugins);
4695
public String getAuthenticationPlugins() {
4696
return this.authenticationPlugins.getValueAsString();
4699
public void setDisabledAuthenticationPlugins(String disabledAuthenticationPlugins) {
4700
this.disabledAuthenticationPlugins.setValue(disabledAuthenticationPlugins);
4703
public String getDisabledAuthenticationPlugins() {
4704
return this.disabledAuthenticationPlugins.getValueAsString();
4707
public void setDefaultAuthenticationPlugin(String defaultAuthenticationPlugin) {
4708
this.defaultAuthenticationPlugin.setValue(defaultAuthenticationPlugin);
4712
public String getDefaultAuthenticationPlugin() {
4713
return this.defaultAuthenticationPlugin.getValueAsString();
4716
public void setParseInfoCacheFactory(String factoryClassname) {
4717
this.parseInfoCacheFactory.setValue(factoryClassname);
4720
public String getParseInfoCacheFactory() {
4721
return this.parseInfoCacheFactory.getValueAsString();
4724
public void setServerConfigCacheFactory(String factoryClassname) {
4725
this.serverConfigCacheFactory.setValue(factoryClassname);
4728
public String getServerConfigCacheFactory() {
4729
return this.serverConfigCacheFactory.getValueAsString();
4732
public void setDisconnectOnExpiredPasswords(boolean disconnectOnExpiredPasswords) {
4733
this.disconnectOnExpiredPasswords.setValue(disconnectOnExpiredPasswords);
4736
public boolean getDisconnectOnExpiredPasswords() {
4737
return this.disconnectOnExpiredPasswords.getValueAsBoolean();