~ubuntu-branches/ubuntu/trusty/mysql-connector-java/trusty

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/ConnectionPropertiesImpl.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Miguel Landaeta
  • Date: 2013-07-02 17:07:51 UTC
  • mfrom: (1.1.8) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130702170751-f4rszjabxg0391fr
Tags: 5.1.25-1
* New upstream release
* Refreshed the patches
* Added a patch to build with one JDK and removed the build
  dependency on java-gcj-compat-dev
* Updated Standards-Version to 3.9.4 (no changes)
* Use canonical URLs for the Vcs-* fields
* debian/rules: Improved the clean target to allow rebuilds
* Updated the watch file
* Renamed debian/README.Debian-source to README.source

[ Miguel Landaeta ] 
* Fix FTBFS with OpenJDK 7 (Closes: #706668)
* Remove Michael Koch from Uploaders list.
  Thanks for your work on this package. (Closes: #654122).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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.
3
3
 
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;
120
119
        }
121
120
 
122
121
        abstract class ConnectionProperty implements Serializable {
 
122
 
 
123
                static final long serialVersionUID = -6644853639584478367L;
 
124
 
123
125
                String[] allowableValues;
124
126
 
125
127
                String categoryName;
629
631
                HA_CATEGORY, SECURITY_CATEGORY,
630
632
                PERFORMANCE_CATEGORY, DEBUGING_PROFILING_CATEGORY, MISC_CATEGORY };
631
633
        
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>();
633
635
 
634
636
        //
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);
686
689
        }
687
690
 
794
797
 
795
798
        private boolean cacheResultSetMetaDataAsBoolean;
796
799
 
 
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$
 
802
        
797
803
        private BooleanConnectionProperty cacheServerConfiguration = new BooleanConnectionProperty(
798
804
                        "cacheServerConfiguration", //$NON-NLS-1$
799
805
                        false,
821
827
                        "1.1g", MISC_CATEGORY, 5); //$NON-NLS-1$
822
828
 
823
829
        private String characterEncodingAsString = null;
 
830
        
 
831
        protected boolean characterEncodingIsAliasForSjis = false;
824
832
 
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);
 
837
 
 
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$
 
841
                        MISC_CATEGORY, 7);
 
842
 
829
843
        
830
844
        private StringConnectionProperty clientInfoProvider = new StringConnectionProperty(
831
845
                        "clientInfoProvider", "com.mysql.jdbc.JDBC4CommentClientInfoProvider", //$NON-NLS-1$ //$NON-NLS-2$
881
895
 
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$
883
897
 
 
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$
886
904
                        false,
1258
1276
                        Messages.getString("ConnectionProperties.prepStmtCacheSqlLimit"), //$NON-NLS-1$
1259
1277
                        "3.0.10", PERFORMANCE_CATEGORY, 11); //$NON-NLS-1$
1260
1278
 
 
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$
 
1281
        
1261
1282
        private BooleanConnectionProperty processEscapeCodesForPrepStmts = 
1262
1283
                new BooleanConnectionProperty("processEscapeCodesForPrepStmts", //$NON-NLS-1$
1263
1284
                                true,
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);
 
1801
 
 
1802
        private StringConnectionProperty authenticationPlugins = new StringConnectionProperty(
 
1803
                        "authenticationPlugins",
 
1804
                        null,
 
1805
                        Messages.getString("ConnectionProperties.authenticationPlugins"),
 
1806
                        "5.1.19", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
 
1807
        
 
1808
        private StringConnectionProperty disabledAuthenticationPlugins = new StringConnectionProperty(
 
1809
                        "disabledAuthenticationPlugins",
 
1810
                        null,
 
1811
                        Messages.getString("ConnectionProperties.disabledAuthenticationPlugins"),
 
1812
                        "5.1.19", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
 
1813
        
 
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);
 
1819
        
 
1820
        private BooleanConnectionProperty disconnectOnExpiredPasswords = new BooleanConnectionProperty("disconnectOnExpiredPasswords",
 
1821
                        true,
 
1822
                        Messages.getString("ConnectionProperties.disconnectOnExpiredPasswords"),
 
1823
                        "5.1.23", CONNECTION_AND_AUTH_CATEGORY, Integer.MIN_VALUE);
 
1824
        
 
1825
        
1780
1826
        
1781
1827
        protected DriverPropertyInfo[] exposeAsDriverPropertyInfoInternal(
1782
1828
                        Properties info, int slotsToReserve) throws SQLException {
1789
1835
                DriverPropertyInfo[] driverProperties = new DriverPropertyInfo[listSize];
1790
1836
 
1791
1837
                for (int i = slotsToReserve; i < listSize; i++) {
1792
 
                        java.lang.reflect.Field propertyField = (java.lang.reflect.Field) PROPERTY_LIST
 
1838
                        java.lang.reflect.Field propertyField = PROPERTY_LIST
1793
1839
                                        .get(i - slotsToReserve);
1794
1840
 
1795
1841
                        try {
1820
1866
                int numPropertiesToSet = PROPERTY_LIST.size();
1821
1867
 
1822
1868
                for (int i = 0; i < numPropertiesToSet; i++) {
1823
 
                        java.lang.reflect.Field propertyField = (java.lang.reflect.Field) PROPERTY_LIST
 
1869
                        java.lang.reflect.Field propertyField = PROPERTY_LIST
1824
1870
                                        .get(i);
1825
1871
 
1826
1872
                        try {
1842
1888
                return info;
1843
1889
        }
1844
1890
 
 
1891
        class XmlMap {
 
1892
                protected Map<Integer, Map<String, ConnectionProperty>> ordered = new TreeMap<Integer, Map<String, ConnectionProperty>>();
 
1893
                protected Map<String, ConnectionProperty> alpha = new TreeMap<String, ConnectionProperty>();
 
1894
        }
 
1895
        
1845
1896
        /* (non-Javadoc)
1846
1897
         * @see com.mysql.jdbc.IConnectionProperties#exposeAsXml()
1847
1898
         */
1853
1904
 
1854
1905
                int numCategories = PROPERTY_CATEGORIES.length;
1855
1906
 
1856
 
                Map propertyListByCategory = new HashMap();
 
1907
                Map<String, XmlMap> propertyListByCategory = new HashMap<String, XmlMap>();
1857
1908
 
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());
1861
1911
                }
1862
1912
 
1863
1913
                //
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);
1877
1927
 
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);
1882
1931
                
1883
 
                connectionSortMaps[0].put(Integer.valueOf(userProp.getOrder()), userMap);
 
1932
                connectionSortMaps.ordered.put(Integer.valueOf(userProp.getOrder()), userMap);
1884
1933
                
1885
 
                TreeMap passwordMap = new TreeMap();
 
1934
                TreeMap<String, ConnectionProperty> passwordMap = new TreeMap<String, ConnectionProperty>();
1886
1935
                passwordMap.put(passwordProp.getPropertyName(), passwordProp);
1887
1936
                
1888
 
                connectionSortMaps[0]
1889
 
                                .put(new Integer(passwordProp.getOrder()), passwordMap);
 
1937
                connectionSortMaps.ordered.put(new Integer(passwordProp.getOrder()), passwordMap);
1890
1938
 
1891
1939
                try {
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
1894
1942
                                                .get(i);
1895
1943
                                ConnectionProperty propToGet = (ConnectionProperty) propertyField
1896
1944
                                                .get(this);
1897
 
                                Map[] sortMaps = (Map[]) propertyListByCategory.get(propToGet
 
1945
                                XmlMap sortMaps = propertyListByCategory.get(propToGet
1898
1946
                                                .getCategoryName());
1899
1947
                                int orderInCategory = propToGet.getOrder();
1900
1948
 
1901
1949
                                if (orderInCategory == Integer.MIN_VALUE) {
1902
 
                                        sortMaps[1].put(propToGet.getPropertyName(), propToGet);
 
1950
                                        sortMaps.alpha.put(propToGet.getPropertyName(), propToGet);
1903
1951
                                } else {
1904
1952
                                        Integer order = Integer.valueOf(orderInCategory);
1905
 
                                        
1906
 
                                        Map orderMap = (Map)sortMaps[0].get(order);
 
1953
                                        Map<String, ConnectionProperty> orderMap = sortMaps.ordered.get(order);
1907
1954
                                        
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);
1911
1958
                                        }
1912
1959
                                        
1913
1960
                                        orderMap.put(propToGet.getPropertyName(), propToGet);
1915
1962
                        }
1916
1963
 
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]);
1922
1966
 
1923
1967
                                xmlBuf.append("\n <PropertyCategory name=\""); //$NON-NLS-1$
1924
1968
                                xmlBuf.append(PROPERTY_CATEGORIES[j]);
1925
1969
                                xmlBuf.append("\">"); //$NON-NLS-1$
1926
1970
 
1927
 
                                while (orderedIter.hasNext()) {
1928
 
                                        Iterator orderedAlphaIter = ((Map)orderedIter.next()).values().iterator();
1929
 
                                        
1930
 
                                        while (orderedAlphaIter.hasNext()) {
1931
 
                                                ConnectionProperty propToGet = (ConnectionProperty) orderedAlphaIter
1932
 
                                                                .next();
1933
 
                                                
 
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("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
 
1992
                                                
 
1993
                                                xmlBuf.append(escapedDescription);
1952
1994
                                                xmlBuf.append("\n  </Property>"); //$NON-NLS-1$
1953
1995
                                        }
1954
1996
                                }
1955
1997
 
1956
 
                                while (alphaIter.hasNext()) {
1957
 
                                        ConnectionProperty propToGet = (ConnectionProperty) alphaIter
1958
 
                                                        .next();
1959
 
                                        
 
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();
2102
2141
        }
 
2142
        
 
2143
        public String getConnectionAttributes() {
 
2144
                return this.connectionAttributes.getValueAsString();
 
2145
        }
 
2146
        
 
2147
        public void setConnectionAttributes(String val) {
 
2148
                this.connectionAttributes.setValue(val);
 
2149
        }
2103
2150
 
2104
2151
        /* (non-Javadoc)
2105
2152
         * @see com.mysql.jdbc.IConnectionProperties#getClobberStreamingResults()
2711
2758
                int numPropertiesToSet = PROPERTY_LIST.size();
2712
2759
 
2713
2760
                for (int i = 0; i < numPropertiesToSet; i++) {
2714
 
                        java.lang.reflect.Field propertyField = (java.lang.reflect.Field) PROPERTY_LIST
 
2761
                        java.lang.reflect.Field propertyField = PROPERTY_LIST
2715
2762
                                        .get(i);
2716
2763
 
2717
2764
                        try {
2760
2807
                        int numPropertiesToSet = PROPERTY_LIST.size();
2761
2808
 
2762
2809
                        for (int i = 0; i < numPropertiesToSet; i++) {
2763
 
                                java.lang.reflect.Field propertyField = (java.lang.reflect.Field) PROPERTY_LIST
 
2810
                                java.lang.reflect.Field propertyField = PROPERTY_LIST
2764
2811
                                                .get(i);
2765
2812
 
2766
2813
                                try {
2808
2855
                        // can't be used
2809
2856
                        try {
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();
3121
3169
                this.characterEncoding.setValue(property);
3122
3170
                this.characterEncodingAsString = this.characterEncoding
3123
3171
                                .getValueAsString();
 
3172
                this.characterEncodingIsAliasForSjis = CharsetMapping.isAliasForSjis(this.characterEncodingAsString);
3124
3173
        }
3125
3174
 
3126
3175
        /* (non-Javadoc)
3617
3666
                int numPropertiesToSet = PROPERTY_LIST.size();
3618
3667
 
3619
3668
                for (int i = 0; i < numPropertiesToSet; i++) {
3620
 
                        java.lang.reflect.Field propertyField = (java.lang.reflect.Field) PROPERTY_LIST
 
3669
                        java.lang.reflect.Field propertyField = PROPERTY_LIST
3621
3670
                                        .get(i);
3622
3671
 
3623
3672
                        try {
4639
4688
                return includeThreadNamesAsStatementComment.getValueAsBoolean();
4640
4689
        }
4641
4690
 
 
4691
        public void setAuthenticationPlugins(String authenticationPlugins) {
 
4692
                this.authenticationPlugins.setValue(authenticationPlugins);
 
4693
        }
 
4694
 
 
4695
        public String getAuthenticationPlugins() {
 
4696
                return this.authenticationPlugins.getValueAsString();
 
4697
        }
 
4698
 
 
4699
        public void setDisabledAuthenticationPlugins(String disabledAuthenticationPlugins) {
 
4700
                this.disabledAuthenticationPlugins.setValue(disabledAuthenticationPlugins);
 
4701
        }
 
4702
 
 
4703
        public String getDisabledAuthenticationPlugins() {
 
4704
                return this.disabledAuthenticationPlugins.getValueAsString();
 
4705
        }
 
4706
 
 
4707
        public void setDefaultAuthenticationPlugin(String defaultAuthenticationPlugin) {
 
4708
                this.defaultAuthenticationPlugin.setValue(defaultAuthenticationPlugin);
 
4709
                
 
4710
        }
 
4711
 
 
4712
        public String getDefaultAuthenticationPlugin() {
 
4713
                return this.defaultAuthenticationPlugin.getValueAsString();
 
4714
        }
 
4715
 
 
4716
        public void setParseInfoCacheFactory(String factoryClassname) {
 
4717
                this.parseInfoCacheFactory.setValue(factoryClassname);  
 
4718
        }
 
4719
 
 
4720
        public String getParseInfoCacheFactory() {
 
4721
                return this.parseInfoCacheFactory.getValueAsString();
 
4722
        }
 
4723
        
 
4724
        public void setServerConfigCacheFactory(String factoryClassname) {
 
4725
                this.serverConfigCacheFactory.setValue(factoryClassname);       
 
4726
        }
 
4727
 
 
4728
        public String getServerConfigCacheFactory() {
 
4729
                return this.serverConfigCacheFactory.getValueAsString();
 
4730
        }
 
4731
 
 
4732
        public void setDisconnectOnExpiredPasswords(boolean disconnectOnExpiredPasswords) {
 
4733
                this.disconnectOnExpiredPasswords.setValue(disconnectOnExpiredPasswords);
 
4734
        }
 
4735
 
 
4736
        public boolean getDisconnectOnExpiredPasswords() {
 
4737
                return this.disconnectOnExpiredPasswords.getValueAsBoolean();
 
4738
        }
4642
4739
}