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

📄 statement.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*   Derby - Class org.apache.derby.client.am.Statement   Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.*/package org.apache.derby.client.am;public class Statement implements java.sql.Statement, StatementCallbackInterface, UnitOfWorkListener {    // JDBC 3 constant indicating that the current ResultSet object    // should be closed when calling getMoreResults.    // Constant value matches that defined by JDBC 3 java.sql.Statement.CLOSE_CURRENT_RESULT    public final static int CLOSE_CURRENT_RESULT = 1;    // JDBC 3 constant indicating that the current ResultSet object    // should not be closed when calling getMoreResults.    // Constant value matches that defined by JDBC 3 java.sql.Statement.KEEP_CURRENT_RESULT    public final static int KEEP_CURRENT_RESULT = 2;    // JDBC 3 constant indicating that all ResultSet objects that    // have previously been kept open should be closed when calling getMoreResults.    // Constant value matches that defined by JDBC 3 java.sql.Statement.CLOSE_ALL_RESULTS    public final static int CLOSE_ALL_RESULTS = 3;    //---------------------navigational members-----------------------------------    public MaterialStatement materialStatement_ = null;    public Connection connection_;    private SqlWarning warnings_ = null;    public Section section_;    public Agent agent_;    public ResultSet resultSet_ = null;    // Use -1, if there is no update count returned, ie. when result set is returned. 0 is a valid update count for DDL.    int updateCount_ = -1;    int returnValueFromProcedure_;    // Enumeration of the flavors of statement execute call used.    static final int executeQueryMethod__ = 1;    static final int executeUpdateMethod__ = 2;    static final int executeMethod__ = 3;    // sqlMode_ will be moved to PS as soon as we remove the hack reference in completeExecute()    // Enumerated in Statement: S.sqlIsQuery__, S.sqlIsCall__, S.sqlIsUpdate__    // Determines whether sql_ starts with SELECT/VALUES, CALL, or other (assumed to be an update).    protected int sqlMode_ = 0;    // Enum for sqlMode_:    static final int isQuery__ = 0x1; // sql starts with SELECT.... or VALUES...    static final int isCall__ = 0x2; // sql starts with CALL ...    static final int isUpdate__ = 0x4; // All other sql is categorized as a update DML or DDL.    // sqlUpdateMode_ is only set when the sqlMode_ == isUpdate__    public int sqlUpdateMode_ = 0;    // Enum for sqlUpdateMode_:    public final static int isCommitSql__ = 0x1;    public final static int isRollbackSql__ = 0x2;    final static int isPositionedUpdateDeleteSql__ = 0x10;    final static int isInsertSql__ = 0x20;        // used to recognize "insert" for auto-generated keys    final static int isDeleteSql__ = 0x40;        // used to recognize "delete" for parsing cursorname    final static int isUpdateSql__ = 0x80;        // used to recognize "update" for parsing cursorname    public ColumnMetaData resultSetMetaData_; // type information for output sqlda    // these two are used during parsing of literals for call statement.    // please add a comment desribing what why you can't reuse inputs_ and parameterMetaData_    // members for the literal inputs    // Caching the Cursor object for reuse.    public Cursor cachedCursor_ = null;    public Cursor cachedSingletonRowData_ = null;    public boolean isPreparedStatement_ = false;    public boolean isCallableStatement_ = false; // we can get rid of this member once we define polymorphic reset() on S/PS/CS    //---------------------navigational cheat-links-------------------------------    // Cheat-links are for convenience only, and are not part of the conceptual model.    // Warning:    //   Cheat-links should only be defined for invariant state data.    //   That is, state data that is set by the constructor and never changes.    // Alias for connection_.databaseMetaData    public DatabaseMetaData databaseMetaData_;    //-----------------------------state------------------------------------------    // Jdbc 1 positioned updates are implemented via    // sql scan for "...where current of <users-cursor-name>",    // the addition of mappings from cursor names to query sections,    // and the subtitution of <users-cursor-name> with <canned-cursor-name> in the pass-thru sql string    // "...where current of <canned-cursor-name>" when user-defined cursor names are used.    // Both "canned" cursor names (from our jdbc package set) and user-defined cursor names are mapped.    // Statement.cursorName_ is initialized to null until the cursor name is requested or set.    // When set (s.setCursorName()) with a user-defined name, then it is added to the cursor map at that time;    // When requested (rs.getCursorName()), if the cursor name is still null,    // then is given the canned cursor name as defined by our jdbc package set and added to the cursor map.    // Still need to consider how positioned updates should interact with multiple result sets from a stored.    String cursorName_ = null;    // This means the client-side jdbc statement object is open.    // This value is set to true when the statement object is constructed, and will not change    // until statement.close() is called either directly or via connection.close(), finalizer, or other methods.    boolean openOnClient_ = true;    // This means a DERBY server-side section for this statement is in the prepared state.    // A client-side jdbc statement may remain open across commits (openOnClient=true),    // but the server-side DERBY section moves to an unprepared state (openOnServer=false) across commits,    // requiring an implicit re-prepare "under the covers" by the driver.    // Unprepared jdbc query statements still have prepared sections on the server.    // This openOnServer_ only has implications for preparedstatement    boolean openOnServer_ = false;    //private int indexOfCurrentResultSet_ = -1;    protected int indexOfCurrentResultSet_ = -1;    ResultSet[] resultSetList_ = null;   // array of ResultSet objects    int timeout_ = 0; // for query timeout in seconds, multiplied by 1000 when passed to java.util.Timer    int maxRows_ = 0;    int maxFieldSize_ = 0; // zero means that there is no limit to the size of a column.    boolean escapedProcedureCallWithResult_ = false;    // When this is false we skip autocommit for this PreparedStatement.    // This is needed when the PreparedStatement object is used internally by    // the driver and a commit is not desired, e.g., Blob/Clob API calls    public boolean isAutoCommittableStatement_ = true;    // The user has no control over the statement that owns a catalog query, and has no ability to close that statement.    // We need a special member variable on our internal catalog query statements so that    // when the catalog query is closed, the result set will know to close it's owning statement.    boolean isCatalogQuery_ = false;    // This collection is used for two different purposes:    //   For statement batching it contains the batched SQL strings.    //   For prepared statement batching it contains the batched input rows.    java.util.ArrayList batch_ = new java.util.ArrayList();    // Scrollable cursor attributes    public int resultSetType_ = java.sql.ResultSet.TYPE_FORWARD_ONLY;    public int resultSetConcurrency_ = java.sql.ResultSet.CONCUR_READ_ONLY;    public int resultSetHoldability_;    // This is ignored by the driver if this is zero.    // For the net forward-only result set, if fetchSize is unset, we let the server return however many rows will fit in a query block.    // For the net scrollable result set, then we use a default of 64 rows.    public int fetchSize_ = 0;    public int fetchDirection_ = java.sql.ResultSet.FETCH_FORWARD;    // Conceptually this doesn't belong in Statement, but belongs in PreparedStatement,    // since Statement doesn't know about params, so we're just putting it here perhaps temporarily,    // Used for callable statement OUT paramters.    public Cursor singletonRowData_ = null;    // number of invisible result sets returned from a stored procedure.    public int numInvisibleRS_ = 0;    // This is a cache of the attributes to be sent on prepare.    // Think about caching the entire prepare DDM string for the re-prepares    public String cursorAttributesToSendOnPrepare_ = null;    // The following members are for the exclusive use of prepared statements that require auto-generated keys to be returned    public PreparedStatement preparedStatementForAutoGeneratedKeys_;    public ResultSet generatedKeysResultSet_;    public String[] generatedKeysColumnNames_;    public int autoGeneratedKeys_ = java.sql.Statement.NO_GENERATED_KEYS;    // This flag makes sure that only one copy of this statement    // will be in connection_.commitListeners_.    //---------------------constructors/finalizer---------------------------------    private Statement() throws SqlException {        initStatement();    }    private void resetStatement() throws SqlException {        initStatement();    }    private void initStatement() throws SqlException {        materialStatement_ = null;        connection_ = null;        agent_ = null;        databaseMetaData_ = null;        resultSetType_ = java.sql.ResultSet.TYPE_FORWARD_ONLY;        resultSetConcurrency_ = java.sql.ResultSet.CONCUR_READ_ONLY;        resultSetHoldability_ = 0;        cursorAttributesToSendOnPrepare_ = null;        initResetStatement();    }    private void initResetStatement() throws SqlException {        initResetPreparedStatement();        //section_ = null; // don't set section to null because write piggyback command require a section        if (section_ != null) {            section_.free();        }        sqlMode_ = 0;        sqlUpdateMode_ = 0;        resultSetMetaData_ = null;    }    protected void initResetPreparedStatement() {        warnings_ = null;        //section_ = null;        resultSet_ = null;        updateCount_ = -1;        returnValueFromProcedure_ = 0;        cursorName_ = null;        openOnClient_ = true;        openOnServer_ = false;        indexOfCurrentResultSet_ = -1;        resultSetList_ = null;        timeout_ = 0;        maxRows_ = 0;        maxFieldSize_ = 0;        escapedProcedureCallWithResult_ = false;        isCatalogQuery_ = false;        isAutoCommittableStatement_ = true;        if (batch_ == null) {            batch_ = new java.util.ArrayList();        } else {            batch_.clear();        }        fetchSize_ = 0;        fetchDirection_ = java.sql.ResultSet.FETCH_FORWARD;        singletonRowData_ = null;        numInvisibleRS_ = 0;        preparedStatementForAutoGeneratedKeys_ = null;        generatedKeysResultSet_ = null;        generatedKeysColumnNames_ = null;        autoGeneratedKeys_ = java.sql.Statement.NO_GENERATED_KEYS;        // these members were not initialized        isPreparedStatement_ = false;    }    // If a dataSource is passed into resetClientConnection(), then we will assume    // properties on the dataSource may have changed, and we will need to go through    // the open-statement list on the connection and do a full reset on all statements,    // including preparedStatement's and callableStatement's.  This is because property    // change may influence the section we allocate for the preparedStatement, and    // also the cursor attributes, i.e. setCursorSensitivity().    // If no dataSource is passed into resetClientConnection(), then we will do the    // minimum reset required for preparedStatement's and callableStatement's.    public void reset(boolean fullReset) throws SqlException {        if (fullReset) {            connection_.resetStatement(this);        } else {            initResetStatement();            materialStatement_.reset_();        }    }    public Statement(Agent agent, Connection connection) throws SqlException {        this();        initStatement(agent, connection);    }    public void resetStatement(Agent agent, Connection connection) throws SqlException {        resetStatement();        initStatement(agent, connection);    }    private void initStatement(Agent agent, Connection connection) {        agent_ = agent;        connection_ = connection;        databaseMetaData_ = connection.databaseMetaData_;    }    // For jdbc 2 statements with scroll attributes    public Statement(Agent agent, Connection connection, int type, int concurrency, int holdability,                     int autoGeneratedKeys, String[] columnNames) throws SqlException {        this(agent, connection);        initStatement(type, concurrency, holdability, autoGeneratedKeys, columnNames);    }    public void resetStatement(Agent agent, Connection connection, int type, int concurrency, int holdability,                               int autoGeneratedKeys, String[] columnNames) throws SqlException {        resetStatement(agent, connection);        initStatement(type, concurrency, holdability, autoGeneratedKeys, columnNames);    }    private void initStatement(int type, int concurrency, int holdability,                               int autoGeneratedKeys, String[] columnNames) throws SqlException {        switch (type) {        case java.sql.ResultSet.TYPE_FORWARD_ONLY:        case java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE:        case java.sql.ResultSet.TYPE_SCROLL_SENSITIVE:            resultSetType_ = type;            break;        default:            throw new SqlException(agent_.logWriter_, "Invalid argument: " +                    "ResultSet Type " + type + " is invalid.");

⌨️ 快捷键说明

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