Logo Search packages:      
Sourcecode: mysql-connector-java version File versions

void com::mysql::jdbc::Connection::initializePropsFromServer ( Properties  info  )  throws SQLException [inline, private]

Sets varying properties that depend on server information. Called once we have connected to the server.

Parameters:
info DOCUMENT ME!
Exceptions:
SQLException DOCUMENT ME!

Definition at line 3211 of file Connection.java.

References buildCollationMapping(), characterSetMetadata, characterSetResultsOnServer, com::mysql::jdbc::MysqlIO::checkForCharsetMismatch(), checkServerEncoding(), checkTransactionIsolationLevel(), configureClientCharacterSet(), configureTimezone(), com::mysql::jdbc::ConnectionProperties::getAllowMultiQueries(), com::mysql::jdbc::ConnectionProperties::getUseServerPreparedStmts(), hasIsolationLevels, hasQuotedIdentifiers, io, loadServerVariables(), lowerCaseTableNames(), maxAllowedPacket, parserKnowsUnicode(), com::mysql::jdbc::MysqlIO::resetMaxBuf(), serverVariables, com::mysql::jdbc::ConnectionProperties::setAllowMultiQueries(), setAutoCommit(), transactionsSupported, useAnsiQuotes, useFastPing, useServerPreparedStmts, and com::mysql::jdbc::MysqlIO::versionMeetsMinimum().

Referenced by createNewIO().

                            {
        // We need to do this before any further data gets
        // sent to the server....
        boolean clientCharsetIsConfigured = configureClientCharacterSet();

        this.useFastPing = versionMeetsMinimum(3, 22, 1);

        this.parserKnowsUnicode = versionMeetsMinimum(4, 1, 0);

        //
        // Users can turn off detection of server-side prepared statements
        //
        if (getUseServerPreparedStmts() && versionMeetsMinimum(4, 1, 0)) {
            this.useServerPreparedStmts = true;
            
            if (versionMeetsMinimum(5, 0, 0) && !versionMeetsMinimum(5, 0, 3)) {
                  this.useServerPreparedStmts = false; // 4.1.2+ style prepared statements
                                                         // don't work on these versions
            }
        }

        this.serverVariables.clear();

        //
        // If version is greater than 3.21.22 get the server
        // variables.
        if (versionMeetsMinimum(3, 21, 22)) {
            loadServerVariables();

            buildCollationMapping();

            LicenseConfiguration.checkLicenseType(this.serverVariables);

            String lowerCaseTables = (String) this.serverVariables.get(
                    "lower_case_table_names");

            this.lowerCaseTableNames = "on".equalsIgnoreCase(lowerCaseTables)
                || "1".equalsIgnoreCase(lowerCaseTables)
                || "2".equalsIgnoreCase(lowerCaseTables);

            configureTimezone();

            if (this.serverVariables.containsKey("max_allowed_packet")) {
                this.maxAllowedPacket = Integer.parseInt((String) this.serverVariables
                        .get("max_allowed_packet"));
            }

            if (this.serverVariables.containsKey("net_buffer_length")) {
                this.netBufferLength = Integer.parseInt((String) this.serverVariables
                        .get("net_buffer_length"));
            }

            checkTransactionIsolationLevel();

            //
            // We only do this for servers older than 4.1.0, because
            // 4.1.0 and newer actually send the server charset
            // during the handshake, and that's handled at the
            // top of this method...
            //
            if (!clientCharsetIsConfigured) {
                checkServerEncoding();
            }

            this.io.checkForCharsetMismatch();

            if (this.serverVariables.containsKey("sql_mode")) {
                int sqlMode = 0;

                String sqlModeAsString = (String) this.serverVariables
                  .get("sql_mode");
                try {
                    sqlMode = Integer.parseInt(sqlModeAsString);
                } catch (NumberFormatException nfe) {
                  // newer versions of the server has this as a string-y list...
                    sqlMode = 0;
                    
                    if (sqlModeAsString != null) {
                        if (sqlModeAsString.indexOf("ANSI_QUOTES") != -1) {
                              sqlMode |= 4;
                        }
                    
                        if (sqlModeAsString.indexOf("NO_BACKSLASH_ESCAPES") != -1) {
                              this.noBackslashEscapes  = true;
                        }
                    }
                }

                if ((sqlMode & 4) > 0) {
                    this.useAnsiQuotes = true;
                } else {
                    this.useAnsiQuotes = false;
                }
            }
        }

        if (versionMeetsMinimum(3, 23, 15)) {
            this.transactionsSupported = true;
            setAutoCommit(true); // to override anything
                                 // the server is set to...reqd
                                 // by JDBC spec.
        } else {
            this.transactionsSupported = false;
        }

        if (versionMeetsMinimum(3, 23, 36)) {
            this.hasIsolationLevels = true;
        } else {
            this.hasIsolationLevels = false;
        }

        this.hasQuotedIdentifiers = versionMeetsMinimum(3, 23, 6);

        this.io.resetMaxBuf();
        
        //
        // If we're using MySQL 4.1.0 or newer, we need to figure
        // out what character set metadata will be returned in,
        // and then map that to a Java encoding name.
        //
        if (this.io.versionMeetsMinimum(4, 1, 0)) {
            String characterSetResultsOnServerMysql = (String)this.serverVariables.get("character_set_results");
            
            if (characterSetResultsOnServerMysql == null || StringUtils.startsWithIgnoreCaseAndWs(characterSetResultsOnServerMysql, "NULL")) {
                  String defaultMetadataCharsetMysql = (String)this.serverVariables.get("character_set_system");
                  String defaultMetadataCharset = null;
                        
                  if (defaultMetadataCharsetMysql != null) {
                        defaultMetadataCharset = (String)CharsetMapping.MYSQL_TO_JAVA_CHARSET_MAP.get(defaultMetadataCharsetMysql);
                  } else {
                        defaultMetadataCharset = "UTF-8";
                  }
                  
                  this.characterSetMetadata = defaultMetadataCharset;
            } else {
                  this.characterSetResultsOnServer = (String)CharsetMapping.MYSQL_TO_JAVA_CHARSET_MAP.get(characterSetResultsOnServerMysql);
                  this.characterSetMetadata = this.characterSetResultsOnServer;
            }
        }
        
        //
        // Query cache is broken wrt. multi-statements before MySQL-4.1.10
        //
        
        if (this.versionMeetsMinimum(4, 1, 0) && 
            !this.versionMeetsMinimum(4, 1, 10) && getAllowMultiQueries()) {
            if ("ON".equalsIgnoreCase((String)this.serverVariables.get("query_cache_type")) &&
                  !"0".equalsIgnoreCase((String)this.serverVariables.get("query_cache_size"))) {
                  setAllowMultiQueries(false);
            }
        }
    }


Generated by  Doxygen 1.6.0   Back to index