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

📄 connectionjdbc2.java

📁 第三方的SQL Server and Sybase的jdbc dirver,速度更快
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *     * @return the xa state variable as an <code>int</code>     */    int getXaState() {        return this.xaState;    }    /**     * Retrieves the XA Emulation flag.     * @return True if in XA emulation mode.     */    boolean isXaEmulation() {        return xaEmulation;    }    /**     * Retrieves the connection mutex and acquires an exclusive lock on the     * network connection.     *     * @return the mutex object as a <code>Semaphore</code>     */    Semaphore getMutex() {        //        // If the current thread has been interrupted but the thread        // has caught the InterruptedException and continued to execute,        // we need to clear the Interrupted status now to ensure that        // we don't fail trying to obtain the connection mutex.        // The c3p0 connection pool software seems to start threads        // in an interrupted state under some circumstances.        //        if (Thread.interrupted()) {            // Thread.interrupted() will clear the interrupt status            Logger.println("Thread status of Interrupted found and cleared");        }        try {            this.mutex.acquire();        } catch (InterruptedException e) {            throw new IllegalStateException("Thread execution interrupted");        }        return this.mutex;    }    /**     * Releases (either closes or caches) a <code>TdsCore</code>.     *     * @param tds the <code>TdsCore</code> instance to release     * @throws SQLException if an error occurs while closing or cleaning up     * @todo Should probably synchronize on another object     */    synchronized void releaseTds(TdsCore tds) throws SQLException {        if (cachedTds != null) {            // There's already a cached TdsCore; close this one            tds.close();        } else {            // No cached TdsCore; clean up this one and cache it            tds.clearResponseQueue();            tds.cleanUp();            cachedTds = tds;        }    }    /**     * Retrieves the cached <code>TdsCore</code> or <code>null</code> if     * nothing is cached and resets the cache (sets it to <code>null</code>).     *     * @return the value of {@see cachedTds}     * @todo Should probably synchronize on another object     */    synchronized TdsCore getCachedTds() {        TdsCore result = cachedTds;        cachedTds = null;        return result;    }    //    // ------------------- java.sql.Connection interface methods -------------------    //    public int getHoldability() throws SQLException {        checkOpen();        return JtdsResultSet.HOLD_CURSORS_OVER_COMMIT;    }    public int getTransactionIsolation() throws SQLException {        checkOpen();        return this.transactionIsolation;    }    public void clearWarnings() throws SQLException {        checkOpen();        messages.clearWarnings();    }    /**     * Releases this <code>Connection</code> object's database and JDBC     * resources immediately instead of waiting for them to be automatically     * released.     * <p>     * Calling the method close on a <code>Connection</code> object that is     * already closed is a no-op.     * <p>     * <b>Note:</b> A <code>Connection</code> object is automatically closed     * when it is garbage collected. Certain fatal errors also close a     * <code>Connection</code> object.     * <p>     * Synchronized because it accesses the statement list and the     * <code>baseTds</code>.     *     * @throws SQLException if a database access error occurs     */    synchronized public void close() throws SQLException {        if (!closed) {            try {                //                // Close any open statements                //                ArrayList tmpList;                synchronized (statements) {                    tmpList = new ArrayList(statements);                }                for (int i = 0; i < tmpList.size(); i++) {                    WeakReference wr = (WeakReference)tmpList.get(i);                    if (wr != null) {                        Statement stmt = (Statement)wr.get();                        if (stmt != null) {                            stmt.close();                        }                    }                }                //                // Tell the server the session is ending                //                baseTds.closeConnection();                //                // Close network connection                //                baseTds.close();                if (cachedTds != null) {                    cachedTds = null;                }                socket.close();            } catch (IOException e) {                // Ignore            } finally {                closed = true;            }        }    }    synchronized public void commit() throws SQLException {        checkOpen();        checkLocal("commit");        if (getAutoCommit()) {            throw new SQLException(                    Messages.get("error.connection.autocommit", "commit"),                    "25000");        }        baseTds.submitSQL("IF @@TRANCOUNT > 0 COMMIT TRAN");        procInTran.clear();        clearSavepoints();    }    synchronized public void rollback() throws SQLException {        checkOpen();        checkLocal("rollback");        if (getAutoCommit()) {            throw new SQLException(                    Messages.get("error.connection.autocommit", "rollback"),                    "25000");        }        baseTds.submitSQL("IF @@TRANCOUNT > 0 ROLLBACK TRAN");        for (int i = 0; i < procInTran.size(); i++) {            String key = (String) procInTran.get(i);            if (key != null) {                statementCache.remove(key);            }        }        procInTran.clear();        clearSavepoints();    }    public boolean getAutoCommit() throws SQLException {        checkOpen();        return this.autoCommit;    }    public boolean isClosed() throws SQLException {        return closed;    }    public boolean isReadOnly() throws SQLException {        checkOpen();        return this.readOnly;    }    public void setHoldability(int holdability) throws SQLException {        checkOpen();        switch (holdability) {            case JtdsResultSet.HOLD_CURSORS_OVER_COMMIT:                break;            case JtdsResultSet.CLOSE_CURSORS_AT_COMMIT:                throw new SQLException(                        Messages.get("error.generic.optvalue",                                "CLOSE_CURSORS_AT_COMMIT",                                "setHoldability"),                        "HY092");            default:                throw new SQLException(                        Messages.get("error.generic.badoption",                                Integer.toString(holdability),                                "holdability"),                        "HY092");        }    }    synchronized public void setTransactionIsolation(int level) throws SQLException {        checkOpen();        if (transactionIsolation == level) {            // No need to submit a request            return;        }        String sql = "SET TRANSACTION ISOLATION LEVEL ";        boolean sybase = serverType == Driver.SYBASE;        switch (level) {            case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:                sql += (sybase) ? "0" : "READ UNCOMMITTED";                break;            case java.sql.Connection.TRANSACTION_READ_COMMITTED:                sql += (sybase) ? "1" : "READ COMMITTED";                break;            case java.sql.Connection.TRANSACTION_REPEATABLE_READ:                sql += (sybase) ? "2" : "REPEATABLE READ";                break;            case java.sql.Connection.TRANSACTION_SERIALIZABLE:                sql += (sybase) ? "3" : "SERIALIZABLE";                break;            case java.sql.Connection.TRANSACTION_NONE:                throw new SQLException(                        Messages.get("error.generic.optvalue",                                "TRANSACTION_NONE",                                "setTransactionIsolation"),                        "HY024");            default:                throw new SQLException(                        Messages.get("error.generic.badoption",                                Integer.toString(level),                                "level"),                        "HY092");        }        transactionIsolation = level;        baseTds.submitSQL(sql);    }    synchronized public void setAutoCommit(boolean autoCommit) throws SQLException {        checkOpen();        checkLocal("setAutoCommit");        if (this.autoCommit == autoCommit) {            // If we don't need to change the current auto commit mode, don't            // submit a request but...            if (!this.autoCommit) {                // If we're in manual commit mode the spec requires that we commit                // the transaction when setAutoCommit() is called                commit();            }            return;        }        StringBuffer sql = new StringBuffer(70);        //        if (!this.autoCommit) {            // If we're in manual commit mode the spec requires that we commit            // the transaction when setAutoCommit() is called            sql.append("IF @@TRANCOUNT > 0 COMMIT TRAN\r\n");        }        if (serverType == Driver.SYBASE) {            if (autoCommit) {                sql.append("SET CHAINED OFF");            } else {                sql.append("SET CHAINED ON");            }        } else {            if (autoCommit) {                sql.append("SET IMPLICIT_TRANSACTIONS OFF");            } else {                sql.append("SET IMPLICIT_TRANSACTIONS ON");            }        }        baseTds.submitSQL(sql.toString());        this.autoCommit = autoCommit;    }    public void setReadOnly(boolean readOnly) throws SQLException {        checkOpen();        this.readOnly = readOnly;    }    public String getCatalog() throws SQLException {        checkOpen();        return this.currentDatabase;    }    synchronized public void setCatalog(String catalog) throws SQLException {        checkOpen();        if (currentDatabase != null && currentDatabase.equals(catalog)) {            return;        }        if (catalog.length() > 32 || catalog.length() < 1) {            throw new SQLException(                    Messages.get("error.generic.badparam",                            catalog,                            "catalog"),                    "3D000");        }        String sql = tdsVersion >= Driver.TDS70                ? ("use [" + catalog + ']') : "use " + catalog;        baseTds.submitSQL(sql);    }    public DatabaseMetaData getMetaData() throws SQLException {        checkOpen();        return new JtdsDatabaseMetaData(this);    }    public SQLWarning getWarnings() throws SQLException {        checkOpen();        return messages.getWarnings();    }    public Savepoint setSavepoint() throws SQLException {        checkOpen();        notImplemented("Connection.setSavepoint()");        return null;    }    public void releaseSavepoint(Savepoint savepoint) throws SQLException {        checkOpen();        notImplemented("Connection.releaseSavepoint(Savepoint)");    }    public void rollback(Savepoint savepoint) throws SQLException {        checkOpen();        notImplemented("Connection.rollback(Savepoint)");    }    public Statement createStatement() throws SQLException {        checkOpen();        return createStatem

⌨️ 快捷键说明

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