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

📄 connection.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            }            xaState_ = saveXaState;        }    }    synchronized public void releaseSavepoint(java.sql.Savepoint savepoint) throws SqlException {        int saveXaState = xaState_;        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "releaseSavepoint", savepoint);        }        checkForClosedConnection();        if (savepoint == null) // Throw exception if savepoint is null        {            throw new SqlException(agent_.logWriter_, "Cannot release a null savepoint.");        } else if (autoCommit_) // Throw exception if auto-commit is on        {            throw new SqlException(agent_.logWriter_, "Cannot release a savepoint when in auto-commit mode.");        }         // Only allow to release a savepoint from the connection that create the savepoint.        try {            if (this != ((Savepoint) savepoint).agent_.connection_) {                throw new SqlException(agent_.logWriter_,                        "Cannot release a savepoint that was not created by this connection.");            }        } catch (java.lang.ClassCastException e) { // savepoint is not an instance of am.Savepoint            throw new SqlException(agent_.logWriter_,                    "Cannot release a savepoint that was not created by this connection.");        }        // Construct and flow a savepoint release statement to server.        Statement stmt = null;        try {            stmt = (Statement) createStatementX(java.sql.ResultSet.TYPE_FORWARD_ONLY,                    java.sql.ResultSet.CONCUR_READ_ONLY,                    holdability());            String savepointName;            try {                savepointName = ((Savepoint) savepoint).getSavepointName();            } catch (SqlException e) {                // generate the name for an un-named savepoint.                savepointName = dncGeneratedSavepointNamePrefix__ +                        ((Savepoint) savepoint).getSavepointId();            }            String sql = "RELEASE SAVEPOINT \"" + savepointName + "\"";            stmt.executeX(sql);        } finally {            if (stmt != null) {                try {                    stmt.closeX();                } catch (SqlException doNothing) {                }            }            xaState_ = saveXaState;        }    }    synchronized public java.sql.Statement createStatement(int resultSetType,                                                           int resultSetConcurrency,                                                           int resultSetHoldability) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "createStatement", resultSetType, resultSetConcurrency, resultSetHoldability);        }        Statement s = createStatementX(resultSetType, resultSetConcurrency, resultSetHoldability);        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "createStatement", s);        }        return s;    }    private Statement createStatementX(int resultSetType,                                       int resultSetConcurrency,                                       int resultSetHoldability) throws SqlException {        checkForClosedConnection();        resultSetType = downgradeResultSetType(resultSetType);        resultSetConcurrency = downgradeResultSetConcurrency(resultSetConcurrency, resultSetType);        // In an XA global transaction do not allow the        // holdability to be set to hold cursors across        // commits, as the engine does not support it.        // Downgrade the holdability to CLOSE_CURSORS_AT_COMMIT        // and attach a warning. This is specified in        // JDBC 4.0 (proposed final draft) section 16.1.3.1        // Similar code is not needed for PreparedStatement        // as the holdability gets pushed all the way to the        // engine and handled there.        if (this.isXAConnection_ && this.xaState_ == XA_T1_ASSOCIATED)        {            if (resultSetHoldability == ClientDataSource.HOLD_CURSORS_OVER_COMMIT) {                resultSetHoldability = ClientDataSource.CLOSE_CURSORS_AT_COMMIT;                accumulateWarning(new SqlWarning(agent_.logWriter_,                         "ResultSetHoldability restricted to ResultSet.CLOSE_CURSORS_AT_COMMIT for a global transaction.", "01J07"));            }        }        Statement s = newStatement_(resultSetType, resultSetConcurrency, resultSetHoldability);        s.cursorAttributesToSendOnPrepare_ = s.cacheCursorAttributesToSendOnPrepare();        openStatements_.put(s, null);        return s;    }    // not sure if holding on to cursorAttributesToSendOnPrepare and restoring it is the    // right thing to do here... because if property on the dataSource changes, we may have    // to send different attributes, i.e. SENSITIVE DYNAMIC, instead of SENSITIVE STATIC.    protected void resetStatement(Statement s) throws SqlException {        String cursorAttributesToSendOnPrepare = s.cursorAttributesToSendOnPrepare_;        resetStatement_(s, s.resultSetType_, s.resultSetConcurrency_, s.resultSetHoldability_);        s.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare;    }    synchronized public java.sql.PreparedStatement prepareStatement(String sql,                                                                    int resultSetType,                                                                    int resultSetConcurrency,                                                                    int resultSetHoldability) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "prepareStatement", sql, resultSetType, resultSetConcurrency, resultSetHoldability);        }        PreparedStatement ps = prepareStatementX(sql,                resultSetType,                resultSetConcurrency,                resultSetHoldability,                java.sql.Statement.NO_GENERATED_KEYS,                null);        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "prepareStatement", ps);        }        return ps;    }    // used by DBMD    PreparedStatement prepareStatementX(String sql,                                        int resultSetType,                                        int resultSetConcurrency,                                        int resultSetHoldability,                                        int autoGeneratedKeys,                                        String[] columnNames) throws SqlException {        checkForClosedConnection();        checkAutoGeneratedKeysParameters(autoGeneratedKeys, columnNames);        resultSetType = downgradeResultSetType(resultSetType);        resultSetConcurrency = downgradeResultSetConcurrency(resultSetConcurrency, resultSetType);        PreparedStatement ps = newPreparedStatement_(sql, resultSetType, resultSetConcurrency, resultSetHoldability, autoGeneratedKeys, columnNames);        ps.cursorAttributesToSendOnPrepare_ = ps.cacheCursorAttributesToSendOnPrepare();        ps.prepare();        openStatements_.put(ps,null);        return ps;    }    // not sure if holding on to cursorAttributesToSendOnPrepare and restoring it is the    // right thing to do here... because if property on the dataSource changes, we may have    // to send different attributes, i.e. SENSITIVE DYNAMIC, instead of SENSITIVE STATIC.    protected void resetPrepareStatement(PreparedStatement ps) throws SqlException {        String cursorAttributesToSendOnPrepare = ps.cursorAttributesToSendOnPrepare_;        resetPreparedStatement_(ps, ps.sql_, ps.resultSetType_, ps.resultSetConcurrency_, ps.resultSetHoldability_, ps.autoGeneratedKeys_, ps.generatedKeysColumnNames_);        ps.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare;        ps.prepare();    }    synchronized public java.sql.CallableStatement prepareCall(String sql,                                                               int resultSetType,                                                               int resultSetConcurrency,                                                               int resultSetHoldability) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "prepareCall", sql, resultSetType, resultSetConcurrency, resultSetHoldability);        }        CallableStatement cs = prepareCallX(sql, resultSetType, resultSetConcurrency, resultSetHoldability);        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "prepareCall", cs);        }        return cs;    }    private CallableStatement prepareCallX(String sql,                                           int resultSetType,                                           int resultSetConcurrency,                                           int resultSetHoldability) throws SqlException {        checkForClosedConnection();        resultSetType = downgradeResultSetType(resultSetType);        resultSetConcurrency = downgradeResultSetConcurrency(resultSetConcurrency, resultSetType);        CallableStatement cs = newCallableStatement_(sql, resultSetType, resultSetConcurrency, resultSetHoldability);        cs.cursorAttributesToSendOnPrepare_ = cs.cacheCursorAttributesToSendOnPrepare();        cs.prepare();        openStatements_.put(cs,null);        return cs;    }    protected void resetPrepareCall(CallableStatement cs) throws SqlException {        String cursorAttributesToSendOnPrepare = cs.cursorAttributesToSendOnPrepare_;        resetCallableStatement_(cs, cs.sql_, cs.resultSetType_, cs.resultSetConcurrency_, cs.resultSetHoldability_);        cs.cursorAttributesToSendOnPrepare_ = cursorAttributesToSendOnPrepare;        cs.prepare();    }    public java.sql.PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "prepareStatement", sql, autoGeneratedKeys);        }        PreparedStatement ps = prepareStatementX(sql,                java.sql.ResultSet.TYPE_FORWARD_ONLY,                java.sql.ResultSet.CONCUR_READ_ONLY,                holdability(),                autoGeneratedKeys,                null);        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "prepareStatement", ps);        }        return ps;    }    public java.sql.PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "prepareStatement", sql, columnIndexes);        }        checkForClosedConnection();        throw new SqlException(agent_.logWriter_, "Driver not capable");    }    public java.sql.PreparedStatement prepareStatement(String sql, String columnNames[]) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "prepareStatement", sql, columnNames);        }        PreparedStatement ps = prepareStatementX(sql,                java.sql.ResultSet.TYPE_FORWARD_ONLY,                java.sql.ResultSet.CONCUR_READ_ONLY,                holdability(),                java.sql.Statement.RETURN_GENERATED_KEYS,                columnNames);        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "prepareStatement", ps);        }        return ps;    }    // ---------------------------------------------------------------------------    protected abstract boolean allowCloseInUOW_();    protected abstract boolean doCloseStatementsOnClose_();    public abstract SectionManager newSectionManager(String collection,                                                     Agent agent,                                                     String databaseName);    //--------------------Abstract material factory methods-----------------    protected abstract Agent newAgent_(LogWriter logWriter, int loginTimeout, String serverName, int portNumber) throws SqlException;    protected abstract DatabaseMetaData newDatabaseMetaData_();    protected abstract Statement newStatement_(int type,                                               int concurrency,                                               int holdability) throws SqlException;    protected abstract void resetStatement_(Statement statement,                                            int type,                                            int concurrency,                                            int holdability) throws SqlException;    protected abstract PreparedStatement newPositionedUpdatePreparedStatement_(String sql, Section section) throws SqlException;    protected abstract PreparedStatement newPreparedStatement_(String sql,                                                               int type,                                                               int concurrency,                                                               int holdability,                                                               int autoGeneratedKeys,                                                               String[] columnNames) throws SqlException;    protected abstract void resetPreparedStatement_(PreparedStatement ps,                                                    String sql,                                                    int resultSetType,                                                    int resultSetConcurrency,                                                    int resultSetHoldability,                                                    int autoGeneratedKeys,                                                    String[] columnNames) throws SqlException;    protected abstract CallableStatement newCallableStatement_(String sql,                                                               int type,                                                               int concurrency,                                                               int holdability) throws SqlException;    protected abstract void resetCallableStatement_(CallableStatement cs,                                                    String sql,                                                    int resultSetType,                                                    int resultSetConcurrency,                                                    int resultSetHoldability) throws SqlException;    // ----------------------- abstract box car and callback methods ---------------------    // All callbacks must be client-side only operations.    public void completeConnect() throws SqlException {        open_ = true;        databaseMetaData_ = newDatabaseMetaData_();        agent_.sectionManager_ =                newSectionManager("NULLID",                        agent_,                        databaseName_);        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceConnectExit(this);        }    }    public abstract void writeCommitSubstitute_() throws SqlException;    public abstract void readCommitSubstitute_() throws SqlException;    public abstract void writeLocalXAStart_() throws SqlException;    public abstract void readLocalXAStart_() throws SqlException;    public abstract void 

⌨️ 快捷键说明

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