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

📄 session.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    return emptyUpdateCount;                }                default : {                    return new Result(                        Trace.runtimeError(                            Trace.UNSUPPORTED_INTERNAL_OPERATION,                            "Session.execute()"), null);                }            }        }    }    private Result performPostExecute(Result r) {        try {            if (database != null) {                database.schemaManager.logSequences(this, database.logger);                if (isAutoCommit) {                    clearIndexRoots();                    database.logger.synchLog();                }            }            return r;        } catch (Exception e) {            return new Result(e, null);        } finally {            if (database != null && database.logger.needsCheckpoint()) {                try {                    database.logger.checkpoint(false);                } catch (HsqlException e) {                    database.logger.appLog.logContext(                        SimpleLog.LOG_ERROR, "checkpoint did not complete");                }            }        }    }    public Result sqlExecuteDirectNoPreChecks(String sql) {        synchronized (database) {            return dbCommandInterpreter.execute(sql);        }    }    Result sqlExecuteCompiledNoPreChecks(CompiledStatement cs,                                         Object[] pvals) {        return compiledStatementExecutor.execute(cs, pvals);    }    private Result sqlExecuteBatch(Result cmd) {        int               csid;        Record            record;        Result            out;        CompiledStatement cs;        Expression[]      parameters;        int[]             updateCounts;        int               count;        csid = cmd.getStatementID();        cs   = database.compiledStatementManager.getStatement(this, csid);        if (cs == null) {            // invalid sql has been removed already            return new Result(                Trace.runtimeError(Trace.INVALID_PREPARED_STATEMENT, null),                null);        }        parameters   = cs.parameters;        count        = 0;        updateCounts = new int[cmd.getSize()];        record       = cmd.rRoot;        while (record != null) {            Result   in;            Object[] pvals = record.data;            in = sqlExecuteCompiledNoPreChecks(cs, pvals);            // On the client side, iterate over the vals and throw            // a BatchUpdateException if a batch status value of            // esultConstants.EXECUTE_FAILED is encountered in the result            if (in.mode == ResultConstants.UPDATECOUNT) {                updateCounts[count++] = in.updateCount;            } else if (in.isData()) {                // FIXME:  we don't have what it takes yet                // to differentiate between things like                // stored procedure calls to methods with                // void return type and select statements with                // a single row/column containg null                updateCounts[count++] = ResultConstants.SUCCESS_NO_INFO;            } else {                updateCounts = ArrayUtil.arraySlice(updateCounts, 0, count);                break;            }            record = record.next;        }        out = new Result(ResultConstants.SQLEXECUTE, updateCounts, 0);        return out;    }    private Result sqlExecuteBatchDirect(Result cmd) {        Record record;        Result out;        int[]  updateCounts;        int    count;        count        = 0;        updateCounts = new int[cmd.getSize()];        record       = cmd.rRoot;        while (record != null) {            Result in;            String sql = (String) record.data[0];            try {                in = dbCommandInterpreter.execute(sql);            } catch (Throwable t) {                in = new Result(ResultConstants.ERROR);                // if (t instanceof OutOfMemoryError) {                // System.gc();                // }                // "in" alread equals "err"                // maybe test for OOME and do a gc() ?                // t.printStackTrace();            }            // On the client side, iterate over the colType vals and throw            // a BatchUpdateException if a batch status value of            // ResultConstants.EXECUTE_FAILED is encountered            if (in.mode == ResultConstants.UPDATECOUNT) {                updateCounts[count++] = in.updateCount;            } else if (in.isData()) {                // FIXME:  we don't have what it takes yet                // to differentiate between things like                // stored procedure calls to methods with                // void return type and select statements with                // a single row/column containg null                updateCounts[count++] = ResultConstants.SUCCESS_NO_INFO;            } else {                updateCounts = ArrayUtil.arraySlice(updateCounts, 0, count);                break;            }            record = record.next;        }        out = new Result(ResultConstants.SQLEXECUTE, updateCounts, 0);        return out;    }    /**     * Retrieves the result of executing the prepared statement whose csid     * and parameter values/types are encapsulated by the cmd argument.     *     * @return the result of executing the statement     */    private Result sqlExecute(Result cmd) {        int csid = cmd.getStatementID();        CompiledStatement cs = compiledStatementManager.getStatement(this,            csid);        if (cs == null) {            // invalid sql has been removed already            return new Result(                Trace.runtimeError(Trace.INVALID_PREPARED_STATEMENT, null),                null);        }        Object[] pvals = cmd.getParameterData();        return sqlExecute(cs, pvals);    }    private Result sqlExecute(CompiledStatement cs, Object[] pvals) {        return sqlExecuteCompiledNoPreChecks(cs, pvals);    }// session DATETIME functions    long      currentDateTimeSCN;    long      currentMillis;    Date      currentDate;    Time      currentTime;    Timestamp currentTimestamp;    /**     * Returns the current date, unchanged for the duration of the current     * execution unit (statement).<p>     *     * SQL standards require that CURRENT_DATE, CURRENT_TIME and     * CURRENT_TIMESTAMP are all evaluated at the same point of     * time in the duration of each SQL statement, no matter how long the     * SQL statement takes to complete.<p>     *     * When this method or a corresponding method for CURRENT_TIME or     * CURRENT_TIMESTAMP is first called in the scope of a system change     * number, currentMillis is set to the current system time. All further     * CURRENT_XXXX calls in this scope will use this millisecond value.     * (fredt@users)     */    Date getCurrentDate() {        if (currentDateTimeSCN != actionTimestamp) {            currentDateTimeSCN = actionTimestamp;            currentMillis      = System.currentTimeMillis();            currentDate        = HsqlDateTime.getCurrentDate(currentMillis);            currentTime        = null;            currentTimestamp   = null;        } else if (currentDate == null) {            currentDate = HsqlDateTime.getCurrentDate(currentMillis);        }        return currentDate;    }    /**     * Returns the current time, unchanged for the duration of the current     * execution unit (statement)     */    Time getCurrentTime() {        if (currentDateTimeSCN != actionTimestamp) {            currentDateTimeSCN = actionTimestamp;            currentMillis      = System.currentTimeMillis();            currentDate        = null;            currentTime =                new Time(HsqlDateTime.getNormalisedTime(currentMillis));            currentTimestamp = null;        } else if (currentTime == null) {            currentTime =                new Time(HsqlDateTime.getNormalisedTime(currentMillis));        }        return currentTime;    }    /**     * Returns the current timestamp, unchanged for the duration of the current     * execution unit (statement)     */    Timestamp getCurrentTimestamp() {        if (currentDateTimeSCN != actionTimestamp) {            currentDateTimeSCN = actionTimestamp;            currentMillis      = System.currentTimeMillis();            currentDate        = null;            currentTime        = null;            currentTimestamp   = HsqlDateTime.getTimestamp(currentMillis);        } else if (currentTimestamp == null) {            currentTimestamp = HsqlDateTime.getTimestamp(currentMillis);        }        return currentTimestamp;    }    Result getAttributes() {        Result   r   = Result.newSessionAttributesResult();        Object[] row = new Object[] {            database.getURI(), getUsername(), ValuePool.getInt(sessionId),            ValuePool.getInt(isolationMode),            ValuePool.getBoolean(isAutoCommit),            ValuePool.getBoolean(database.databaseReadOnly),            ValuePool.getBoolean(isReadOnly)        };        r.add(row);        return r;    }    Result setAttributes(Result r) {        Object[] row = r.rRoot.data;        for (int i = 0; i < row.length; i++) {            Object value = row[i];            if (value == null) {                continue;            }            try {                switch (i) {                    case SessionInterface.INFO_AUTOCOMMIT : {                        this.setAutoCommit(((Boolean) value).booleanValue());                        break;                    }                    case SessionInterface.INFO_CONNECTION_READONLY :                        this.setReadOnly(((Boolean) value).booleanValue());                        break;                }            } catch (HsqlException e) {                return new Result(e, null);            }        }        return emptyUpdateCount;    }    // DatabaseMetaData.getURL should work as specified for    // internal connections too.    public String getInternalConnectionURL() {        return DatabaseURL.S_URL_PREFIX + database.getURI();    }    boolean isProcessingScript() {        return isProcessingScript;    }    boolean isProcessingLog() {        return isProcessingLog;    }    boolean isSchemaDefintion() {        return oldSchema != null;    }    void startSchemaDefinition(String schema) throws HsqlException {        if (isProcessingScript) {            setSchema(schema);            return;        }        oldSchema = currentSchema;        setSchema(schema);    }    void endSchemaDefinition() throws HsqlException {        if (oldSchema == null) {            return;        }        currentSchema = oldSchema;        oldSchema     = null;        database.logger.writeToLog(this,                                   "SET SCHEMA "                                   + currentSchema.statementName);    }    // schema object methods    public void setSchema(String schema) throws HsqlException {        currentSchema = database.schemaManager.getSchemaHsqlName(schema);    }    /**     * If schemaName is null, return the current schema name, else return     * the HsqlName object for the schema. If schemaName does not exist,     * throw.     */    HsqlName getSchemaHsqlName(String name) throws HsqlException {        return name == null ? currentSchema                            : database.schemaManager.getSchemaHsqlName(name);    }    /**     * Same as above, but return string     */    public String getSchemaName(String name) throws HsqlException {        return name == null ? currentSchema.name                            : database.schemaManager.getSchemaName(name);    }    /**     * If schemaName is null, return the current schema name, else return     * the HsqlName object for the schema. If schemaName does not exist, or     * schema readonly, throw.     */    HsqlName getSchemaHsqlNameForWrite(String name) throws HsqlException {        HsqlName schema = getSchemaHsqlName(name);        if (database.schemaManager.isSystemSchema(schema)) {            throw Trace.error(Trace.INVALID_SCHEMA_NAME_NO_SUBCLASS);        }        return schema;    }    /**     * Same as above, but return string     */    public String getSchemaNameForWrite(String name) throws HsqlException {        HsqlName schema = getSchemaHsqlNameForWrite(name);        return schema.name;    }    /**     * get the root for a temp table index     */    Node getIndexRoot(HsqlName index, boolean preserve) {        if (preserve) {            if (indexArrayKeepMap == null) {                return null;            }            return (Node) indexArrayKeepMap.get(index.hashCode());        } else {            if (indexArrayMap == null) {                return null;            }            return (Node) indexArrayMap.get(index.hashCode());        }    }    /**     * set the root for a temp table index     */    void setIndexRoot(HsqlName index, boolean preserve, Node root) {        if (preserve) {            if (indexArrayKeepMap == null) {                if (root == null) {                    return;                }                indexArrayKeepMap = new IntKeyHashMap();            }            indexArrayKeepMap.put(index.hashCode(), root);        } else {            if (indexArrayMap == null) {                if (root == null) {                    return;                }                indexArrayMap = new IntKeyHashMap();            }            indexArrayMap.put(index.hashCode(), root);        }    }    void dropIndex(HsqlName index, boolean preserve) {        if (preserve) {            if (indexArrayKeepMap != null) {                indexArrayKeepMap.remove(index.hashCode());            }        } else {            if (indexArrayMap != null) {                indexArrayMap.remove(index.hashCode());            }        }    }    /**     * clear default temp table contents for this session     */    void clearIndexRoots() {        if (indexArrayMap != null) {            indexArrayMap.clear();        }    }    /**     * clear ON COMMIT PRESERVE temp table contents for this session     */    void clearIndexRootsKeep() {        if (indexArrayKeepMap != null) {            indexArrayKeepMap.clear();        }    }}

⌨️ 快捷键说明

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