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

📄 connection.java

📁 SearchPathServer
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        else if (_transactionsSupported)
        {
            execSQL("commit", -1);
        }

        return;
    }


    /**
     * The method rollback() drops all changes made since the previous
     * commit/rollback and releases any database locks currently held by
     * the Connection.
     *
     * @exception java.sql.SQLException if a database access error occurs
     * @see commit
     */
    public void rollback()
                  throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "rollback", args);
        }

        if (_isClosed)
        {
            throw new java.sql.SQLException("Rollback attempt on closed connection.", 
                                            "08003");
        }

        // no-op if _relaxAutoCommit == true
        if (_autoCommit && !_relaxAutoCommit)
        {
            throw new SQLException("Can't call commit when autocommit=true", 
                                   "08003");
        }
        else if (_transactionsSupported)
        {
            execSQL("rollback", -1);
        }
    }


    /**
     * In some cases, it is desirable to immediately release a Connection's
     * database and JDBC resources instead of waiting for them to be
     * automatically released (cant think why off the top of my head)
     *
     * <B>Note:</B> A Connection is automatically closed when it is
     * garbage collected.  Certain fatal errors also result in a closed
     * connection.
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public void close()
               throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "close", args);
        }

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

            _io = null;
        }

        _isClosed = true;
    }


    /**
     * Tests to see if a Connection is closed
     *
     * @return the status of the connection
     * @exception java.sql.SQLException (why?)
     */
    public boolean isClosed()
                     throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "isClosed", args);
            Debug.returnValue(this, "isClosed", new Boolean(_isClosed));
        }

        if (!_isClosed)
        {

            // Test the connection
            try
            {
                synchronized (_io)
                {
                    ping();
                }
            }
            catch (Exception E)
            {
                _isClosed = true;
            }
        }

        return _isClosed;
    }


    /**
     * A connection's database is able to provide information describing
     * its tables, its supported SQL grammar, its stored procedures, the
     * capabilities of this connection, etc.  This information is made
     * available through a DatabaseMetaData object.
     *
     * @return a DatabaseMetaData object for this connection
     * @exception java.sql.SQLException if a database access error occurs
     */
    public abstract java.sql.DatabaseMetaData getMetaData()
                                                   throws java.sql.SQLException;


    /**
     * You can put a connection in read-only mode as a hint to enable
     * database optimizations
     *
     * <B>Note:</B> setReadOnly cannot be called while in the middle
     * of a transaction
     *
     * @param readOnly - true enables read-only mode; false disables it
     * @exception java.sql.SQLException if a database access error occurs
     */
    public void setReadOnly(boolean readOnly)
                     throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = {new Boolean(readOnly)};
            Debug.methodCall(this, "setReadOnly", args);
            Debug.returnValue(this, "setReadOnly", new Boolean(readOnly));
        }

        _readOnly = readOnly;
    }


    /**
     * Tests to see if the connection is in Read Only Mode.  Note that
     * we cannot really put the database in read only mode, but we pretend
     * we can by returning the value of the readOnly flag
     *
     * @return true if the connection is read only
     * @exception java.sql.SQLException if a database access error occurs
     */
    public boolean isReadOnly()
                       throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "isReadOnly", args);
            Debug.returnValue(this, "isReadOnly", new Boolean(_readOnly));
        }

        return _readOnly;
    }


    /**
     * A sub-space of this Connection's database may be selected by
     * setting a catalog name.  If the driver does not support catalogs,
     * it will silently ignore this request
     *
     * <p><b>Note:</b> MySQL's notion of catalogs are individual databases.
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public void setCatalog(String catalog)
                    throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = {catalog};
            Debug.methodCall(this, "setCatalog", args);
        }

        execSQL("USE " + catalog, -1);
        _database = catalog;
    }


    /**
     * Return the connections current catalog name, or null if no
     * catalog name is set, or we dont support catalogs.
     *
     * <p><b>Note:</b> MySQL's notion of catalogs are individual databases.
     * @return the current catalog name or null
     * @exception java.sql.SQLException if a database access error occurs
     */
    public String getCatalog()
                      throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getCatalog", args);
            Debug.returnValue(this, "getCatalog", _database);
        }

        return _database;
    }


    /**
     * You can call this method to try to change the transaction
     * isolation level using one of the TRANSACTION_* values.
     *
     * <B>Note:</B> setTransactionIsolation cannot be called while
     * in the middle of a transaction
     *
     * @param level one of the TRANSACTION_* isolation values with
     *    the exception of TRANSACTION_NONE; some databases may
     *    not support other values
     * @exception java.sql.SQLException if a database access error occurs
     * @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel
     */
    private int isolationLevel = java.sql.Connection.TRANSACTION_READ_COMMITTED;

    public void setTransactionIsolation(int level)
                                 throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = {new Integer(level)};
            Debug.methodCall(this, "setTransactionIsolation", args);
        }

        if (_hasIsolationLevels)
        {
            StringBuffer sql = new StringBuffer("SET SESSION TRANSACTION ISOLATION LEVEL ");

            switch (level)
            {
                case java.sql.Connection.TRANSACTION_NONE:
                    throw new SQLException("Transaction isolation level NONE not supported by MySQL");

                case java.sql.Connection.TRANSACTION_READ_COMMITTED:
                    sql.append("READ COMMITTED");
                    break;

                case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:
                    sql.append("READ UNCOMMITTED");
                    break;

                case java.sql.Connection.TRANSACTION_REPEATABLE_READ:
                    sql.append("REPEATABLE READ");
                    break;

                case java.sql.Connection.TRANSACTION_SERIALIZABLE:
                    sql.append("SERIALIZABLE");
                    break;

                default:
                    throw new SQLException(
                            "Unsupported transaction isolation level '" + 
                            level + "'", "S1C00");
            }

            execSQL(sql.toString(), -1);
            isolationLevel = level;
        }
        else
        {
            throw new java.sql.SQLException("Transaction Isolation Levels are not supported on MySQL versions older than 3.23.36.", 
                                            "S1C00");
        }
    }


    /**
     * Get this Connection's current transaction isolation mode.
     *
     * @return the current TRANSACTION_* mode value
     * @exception java.sql.SQLException if a database access error occurs
     */
    public int getTransactionIsolation()
                                throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getTransactionIsolation", args);
            Debug.returnValue(this, "getTransactionIsolation", 
                              new Integer(java.sql.Connection.TRANSACTION_SERIALIZABLE));
        }

        return isolationLevel;
    }


    /**
     * The first warning reported by calls on this Connection is
     * returned.
     *
     * <B>Note:</B> Sebsequent warnings will be changed to this
     * java.sql.SQLWarning
     *
     * @return the first java.sql.SQLWarning or null
     * @exception java.sql.SQLException if a database access error occurs
     */
    public java.sql.SQLWarning getWarnings()
                                    throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "getWarnings", args);
            Debug.returnValue(this, "getWarnings", null);
        }

        return null;
    }


    /**
     * After this call, getWarnings returns null until a new warning
     * is reported for this connection.
     *
     * @exception java.sql.SQLException if a database access error occurs
     */
    public void clearWarnings()
                       throws java.sql.SQLException
    {
        if (Driver.trace)
        {
            Object[] args = new Object[0];
            Debug.methodCall(this, "clearWarnings", args);
        }

        // firstWarning = null;
    }


    /**
     * NOT JDBC-Compliant, but clients can use this method
     * to determine how long this connection has been idle.
     * 
     * This time (reported in milliseconds) is updated once
     * a query has completed.
     * 
     * @return number of ms that this connection has
     * been idle, 0 if the driver is busy retrieving results.
     */
    public long getIdleFor()
    {
        if (_lastQueryFinishedTime == 0)
        {
            return 0;
        }
        else
        {
            long now = System.currentTimeMillis();
            long idleTime = now - _lastQueryFinishedTime;

            return idleTime;
        }
    }

⌨️ 快捷键说明

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