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

📄 session.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                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();        Object[]          pvals = cmd.getParameterData();        CompiledStatement cs    = compiledStatementManager.getStatement(csid);        Expression[]      parameters;        if (cs == null ||!cs.isValid) {            cs = recompileStatement(cs, csid);            if (cs == null) {                // invalid sql has been removed already                return new Result(                    Trace.runtimeError(                        Trace.INVALID_PREPARED_STATEMENT, null), null);            }        }        parameters = cs.parameters;        // Don't bother with array length or type checks...trust the client        // to send pvals with length at least as long        // as parameters array and with each pval already converted to the        // correct internal representation corresponding to the type        try {            for (int i = 0; i < parameters.length; i++) {                parameters[i].bind(pvals[i]);            }        } catch (Throwable t) {            return new Result(t, cs.sql);        }        return compiledStatementExecutor.execute(cs);    }    /**     * Recompile a prepard statement or free it if no longer valid     */    private CompiledStatement recompileStatement(CompiledStatement cs,            int csid) {        String sql = compiledStatementManager.getSql(csid);        if (sql == null) {            // invalid sql has been removed already            return null;        }        Result r = sqlPrepare(sql);        if (r.mode == ResultConstants.ERROR) {            // sql is invalid due to DDL changes            compiledStatementManager.freeStatement(csid, sessionId);            return null;        }        return compiledStatementManager.getStatement(csid);    }    /**     * Retrieves the result of freeing the statement with the given id.     *     * @param csid the numeric identifier of the statement     */    private Result sqlFreeStatement(int csid) {        Result result;        compiledStatementManager.freeStatement(csid, sessionId);        result             = new Result(ResultConstants.UPDATECOUNT);        result.updateCount = 1;        return result;    }// 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 != sessionSCN) {            currentDateTimeSCN = sessionSCN;            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 != sessionSCN) {            currentDateTimeSCN = sessionSCN;            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 != sessionSCN) {            currentDateTimeSCN = sessionSCN;            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(isolation), 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 (indexArrayMap == null) {            return null;        }        Node node = preserve ? (Node) indexArrayKeepMap.get(index.hashCode())                             : (Node) indexArrayMap.get(index.hashCode());        return node;    }    /**     * 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();        } 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 + -