⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connection.java

📁 网上销售系统是目前 Internet 上广泛使用的在线系统之一。 网上售书这是信息社会发展的必然要求。国际互联网的开通
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public boolean useTimezone() {
        return this.useTimezone;
    }

    /**
     * Should unicode character mapping be used ?
     *
     * @return should we use Unicode character mapping?
     */
    public boolean useUnicode() {
        return this.doUnicode;
    }

    /**
     * DOCUMENT ME!
     *
     * @return Returns the defaultTimeZone.
     */
    protected TimeZone getDefaultTimeZone() {
        return defaultTimeZone;
    }

    /**
     * Returns the IO channel to the server
     *
     * @return the IO channel to the server
     *
     * @throws SQLException if the connection is closed.
     */
    protected MysqlIO getIO() throws SQLException {
        if ((this.io == null) || this.isClosed) {
            throw new SQLException("Operation not allowed on closed connection",
                "08003");
        }

        return this.io;
    }

    protected int getNetWriteTimeout() {
        String netWriteTimeoutStr = (String) this.serverVariables.get(
                "net_write_timeout");

        if (netWriteTimeoutStr != null) {
            try {
                return Integer.parseInt(netWriteTimeoutStr);
            } catch (NumberFormatException nfe) {
                return Integer.MAX_VALUE;
            }
        } else {
            return Integer.MAX_VALUE;
        }
    }

    /**
     * Is this connection using unbuffered input?
     *
     * @return whether or not to use buffered input streams
     */
    protected boolean isUsingUnbufferedInput() {
        return this.useUnbufferedInput;
    }

    /**
     * Creates an IO channel to the server
     *
     * @param isForReconnect is this request for a re-connect
     *
     * @return a new MysqlIO instance connected to a server
     *
     * @throws SQLException if a database access error occurs
     */
    protected com.mysql.jdbc.MysqlIO createNewIO(boolean isForReconnect)
        throws SQLException {
        MysqlIO newIo = null;

        if (!highAvailability && !this.failedOver) {
            for (int hostIndex = 0; hostIndex < hostListSize; hostIndex++) {
                try {
                    this.io = new MysqlIO(this.hostList.get(hostIndex).toString(),
                            this.port, this.socketFactoryClassName, this.props,
                            this, this.socketTimeout);
                    this.io.doHandshake(this.user, this.password, this.database);
                    this.isClosed = false;

                    if (this.database.length() != 0) {
                        this.io.sendCommand(MysqlDefs.INIT_DB, this.database,
                            null);
                    }

                    // save state from old connection
                    boolean autoCommit = getAutoCommit();
                    int oldIsolationLevel = getTransactionIsolation();
                    boolean oldReadOnly = isReadOnly();
                    String oldCatalog = getCatalog();

                    // Server properties might be different
                    // from previous connection, so initialize
                    // again...
                    initializePropsFromServer(this.props);

                    if (isForReconnect) {
                        // Restore state from old connection
                        setAutoCommit(autoCommit);

                        if (this.hasIsolationLevels) {
                            setTransactionIsolation(oldIsolationLevel);
                        }

                        setCatalog(oldCatalog);
                    }

                    if (hostIndex != 0) {
                        setFailedOverState();
                    } else {
                        this.failedOver = false;

                        if (hostListSize > 1) {
                            setReadOnly(false);
                        } else {
                            setReadOnly(oldReadOnly);
                        }
                    }

                    break; // low-level connection succeeded
                } catch (SQLException sqlEx) {
                    if (this.io != null) {
                        this.io.forceClose();
                    }

                    String sqlState = sqlEx.getSQLState();

                    if ((sqlState == null)
                            || !sqlState.equals(
                                SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE)) {
                        throw sqlEx;
                    }

                    if ((hostListSize - 1) == hostIndex) {
                        throw sqlEx;
                    }
                } catch (Exception unknownException) {
                    if (this.io != null) {
                        this.io.forceClose();
                    }

                    if ((hostListSize - 1) == hostIndex) {
                        throw new SQLException(
                            "Unable to connect to any hosts due to exception: "
                            + unknownException.toString(),
                            SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE);
                    }
                }
            }
        } else {
            double timeout = this.initialTimeout;
            boolean connectionGood = false;
            Exception connectionException = null;

            for (int hostIndex = 0;
                    (hostIndex < hostListSize) && !connectionGood;
                    hostIndex++) {
                for (int attemptCount = 0;
                        !connectionGood && (attemptCount < this.maxReconnects);
                        attemptCount++) {
                    try {
                        if (this.io != null) {
                            this.io.forceClose();
                        }

                        this.io = new MysqlIO(this.hostList.get(hostIndex)
                                                           .toString(),
                                this.port, this.socketFactoryClassName,
                                this.props, this, this.socketTimeout);
                        this.io.doHandshake(this.user, this.password,
                            this.database);

                        if (this.database.length() != 0) {
                            this.io.sendCommand(MysqlDefs.INIT_DB,
                                this.database, null);
                        }

                        ping();
                        this.isClosed = false;

                        // save state from old connection
                        boolean autoCommit = getAutoCommit();
                        int oldIsolationLevel = getTransactionIsolation();
                        boolean oldReadOnly = isReadOnly();
                        String oldCatalog = getCatalog();

                        // Server properties might be different
                        // from previous connection, so initialize
                        // again...
                        initializePropsFromServer(this.props);

                        if (isForReconnect) {
                            // Restore state from old connection
                            setAutoCommit(autoCommit);

                            if (this.hasIsolationLevels) {
                                setTransactionIsolation(oldIsolationLevel);
                            }

                            setCatalog(oldCatalog);
                        }

                        connectionGood = true;

                        if (hostIndex != 0) {
                            setFailedOverState();
                        } else {
                            this.failedOver = false;

                            if (hostListSize > 1) {
                                setReadOnly(false);
                            } else {
                                setReadOnly(oldReadOnly);
                            }
                        }

                        break;
                    } catch (Exception EEE) {
                        connectionException = EEE;
                        connectionGood = false;
                    }

                    if (!connectionGood) {
                        try {
                            Thread.sleep((long) timeout * 1000);
                            timeout = timeout * 2;
                        } catch (InterruptedException IE) {
                            ;
                        }
                    }
                }

                if (!connectionGood) {
                    // We've really failed!
                    throw new SQLException(
                        "Server connection failure during transaction. Due to underlying exception: '"
                        + connectionException + "'.\nAttempted reconnect "
                        + this.maxReconnects + " times. Giving up.",
                        SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE);
                }
            }
        }

        if (paranoid && !highAvailability && (hostListSize <= 1)) {
            password = null;
            user = null;
        }

        return newIo;
    }

    /**
     * Closes connection and frees resources.
     *
     * @param calledExplicitly is this being called from close()
     * @param issueRollback should a rollback() be issued?
     *
     * @throws SQLException if an error occurs
     */
    protected void realClose(boolean calledExplicitly, boolean issueRollback)
        throws SQLException {
        if (Driver.TRACE) {
            Object[] args = new Object[] {
                    new Boolean(calledExplicitly), new Boolean(issueRollback)
                };
            Debug.methodCall(this, "realClose", args);
        }

        SQLException sqlEx = null;

        if (!isClosed() && !getAutoCommit() && issueRollback) {
            try {
                rollback();
            } catch (SQLException ex) {
                sqlEx = ex;
            }
        }

        if (this.io != null) {
            try {
                this.io.quit();
            } catch (Exception e) {
                ;
            }

            this.io = null;
        }

        if (this.cachedPreparedStatementParams != null) {
            this.cachedPreparedStatementParams.clear();
            this.cachedPreparedStatementParams = null;
        }

        this.isClosed = true;

        if (sqlEx != null) {
            throw sqlEx;
        }
    }

    /**
     * Returns the locally mapped instance of a charset converter (to avoid
     * overhead of static synchronization).
     *
     * @param javaEncodingName the encoding name to retrieve
     *
     * @return a character converter, or null if one couldn't be mapped.
     */
    synchronized SingleByteCharsetConverter getCharsetConverter(
        String javaEncodingName) {
        SingleByteCharsetConverter converter = (SingleByteCharsetConverter) this.charsetConverterMap
            .get(javaEncodingName);

        if (converter == CHARSET_CONVERTER_NOT_AVAILABLE_MARKER) {
            return null;
        }

        if (converter == null) {
            try {
                converter = SingleByteCharsetConverter.getInstance(javaEncodingName);

                if (converter == null) {
                    this.charsetConverterMap.put(javaEncodingName,
                        CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);
                }

                this.charsetConverterMap.put(javaEncodingName, converter);
            } catch (UnsupportedEncodingException unsupEncEx) {
                this.charsetConverterMap.put(javaEncodingName,
                    CHARSET_CONVERTER_NOT_AVAILABLE_MARKER);

                converter = null;
            }
        }

        return converter;
    }

    /**
     * Returns the maximum packet size the MySQL server will accept
     *
     * @return DOCUMENT ME!
     */
    int getMaxAllowedPacket() {
        return this.maxAllowedPacket;
    }

    /**
     * DOCUMENT ME!
     *
     * @return the max rows to return for statements (by default)
     */
    int getMaxRows() {
        return this.maxRows;
    }

    /**
     * Returns the Mutex all queries are locked against
     *
     * @return DOCUMENT ME!
     *
     * @throws SQLException DOCUMENT ME!
     */
    Object getMutex() throws SQLException {
        if (this.io == null) {
            throw new SQLException("Connection.close() has already been called. Invalid operation in this state.",
                "08003");
        }

        return this.mutex;
    }

    /**
     * Returns the packet buffer size the MySQL server reported upon connection
     *
     * @return DOCUMENT ME!
     */
    int getNetBufferLength() {
        return this.netBufferLength;
    }

    boolean isPedantic() 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -