📄 session.java
字号:
table.removeRowFromStore(row); } return false; } /** * Adds a single-row inssertion step to the transaction UNDO buffer. * * @param table the table into which the row was inserted * @param row the inserted row * @throws HsqlException */ boolean addTransactionInsert(Table table, Row row) throws HsqlException { if (!isAutoCommit || isNestedTransaction) { Transaction t = new Transaction(false, table, row, sessionSCN); transactionList.add(t); database.txManager.addTransaction(this, t); return true; } else { table.commitRowToStore(row); } return false; } /** * Setter for the autocommit attribute. * * @param autocommit the new value * @throws HsqlException */ public void setAutoCommit(boolean autocommit) { if (isClosed) { return; } synchronized (database) { if (autocommit != isAutoCommit) { commit(); isAutoCommit = autocommit; try { database.logger.writeToLog(this, getAutoCommitStatement()); } catch (HsqlException e) {} } } } /** * Commits any uncommited transaction this Session may have open * * @throws HsqlException */ public void commit() { if (isClosed) { return; } synchronized (database) { if (!transactionList.isEmpty()) { try { database.logger.writeCommitStatement(this); } catch (HsqlException e) {} } database.txManager.commit(this); clearIndexRoots(); } } /** * Rolls back any uncommited transaction this Session may have open. * * @throws HsqlException */ public void rollback() { if (isClosed) { return; } synchronized (database) { if (transactionList.size() != 0) { try { database.logger.writeToLog(this, Token.T_ROLLBACK); } catch (HsqlException e) {} } database.txManager.rollback(this); clearIndexRoots(); } } /** * No-op in this implementation */ public void resetSession() throws HsqlException { throw new HsqlException("", "", 0); } /** * Implements a transaction SAVEPOINT. A new SAVEPOINT with the * name of an existing one replaces the old SAVEPOINT. * * @param name of the savepoint * @throws HsqlException if there is no current transaction */ void savepoint(String name) throws HsqlException { savepoints.remove(name); savepoints.add(name, ValuePool.getInt(transactionList.size())); try { database.logger.writeToLog(this, Token.T_SAVEPOINT + " " + name); } catch (HsqlException e) {} } /** * Implements a partial transaction ROLLBACK. * * @param name Name of savepoint that was marked before by savepoint() * call * @throws HsqlException */ void rollbackToSavepoint(String name) throws HsqlException { if (isClosed) { return; } try { database.logger.writeToLog(this, Token.T_ROLLBACK + " " + Token.T_TO + " " + Token.T_SAVEPOINT + " " + name); } catch (HsqlException e) {} database.txManager.rollbackSavepoint(this, name); } /** * Implements release of named SAVEPOINT. * * @param name Name of savepoint that was marked before by savepoint() * call * @throws HsqlException if name does not correspond to a savepoint */ void releaseSavepoint(String name) throws HsqlException { // remove this and all later savepoints int index = savepoints.getIndex(name); Trace.check(index >= 0, Trace.SAVEPOINT_NOT_FOUND, name); while (savepoints.size() > index) { savepoints.remove(savepoints.size() - 1); } } /** * Starts a nested transaction. * * @throws HsqlException */ void beginNestedTransaction() throws HsqlException { if (isNestedTransaction) { Trace.doAssert(false, "beginNestedTransaction"); } nestedOldTransIndex = transactionList.size(); isNestedTransaction = true; } /** * @todo -- fredt 20050604 - if this method is called after an out of memory * error during update, the next block might throw out of memory too and as * a result inNestedTransaction remains true and no further update * is possible. The session must be closed at that point by the user * application. */ /** * Ends a nested transaction. * * @param rollback true to roll back or false to commit the nested transaction * @throws HsqlException */ void endNestedTransaction(boolean rollback) throws HsqlException { if (!isNestedTransaction) { Trace.doAssert(false, "endNestedTransaction"); } if (rollback) { database.txManager.rollbackTransactions(this, nestedOldTransIndex, true); } // reset after the rollback isNestedTransaction = false; if (isAutoCommit == true) { database.txManager.commit(this); } } /** * Setter for readonly attribute. * * @param readonly the new value */ public void setReadOnly(boolean readonly) throws HsqlException { if (!readonly && database.databaseReadOnly) { throw Trace.error(Trace.DATABASE_IS_READONLY); } isReadOnly = readonly; } /** * Getter for readonly attribute. * * @return the current value */ public boolean isReadOnly() { return isReadOnly; } /** * Getter for nestedTransaction attribute. * * @return the current value */ boolean isNestedTransaction() { return isNestedTransaction; } /** * Getter for autoCommit attribute. * * @return the current value */ public boolean isAutoCommit() { return isAutoCommit; } /** * A switch to set scripting on the basis of type of statement executed. * A method in DatabaseCommandInterpreter.java sets this value to false * before other methods are called to act on an SQL statement, which may * set this to true. Afterwards the method reponsible for logging uses * getScripting() to determine if logging is required for the executed * statement. (fredt@users) * * @param script The new scripting value */ void setScripting(boolean script) { this.script = script; } /** * Getter for scripting attribute. * * @return scripting for the last statement. */ boolean getScripting() { return script; } public String getAutoCommitStatement() { return isAutoCommit ? "SET AUTOCOMMIT TRUE" : "SET AUTOCOMMIT FALSE"; } /** * Retrieves an internal Connection object equivalent to the one * that created this Session. * * @return internal connection. */ jdbcConnection getInternalConnection() throws HsqlException { if (intConnection == null) { intConnection = new jdbcConnection(this); } return intConnection; }// boucherb@users 20020810 metadata 1.7.2//---------------------------------------------------------------- private final long connectTime = System.currentTimeMillis();// more effecient for MetaData concerns than checkAdmin /** * Getter for admin attribute. * * @ return the current value */ boolean isAdmin() { return user.isAdmin(); } /** * Getter for connectTime attribute. * * @return the value */ long getConnectTime() { return connectTime; } /** * Getter for transactionSise attribute. * * @return the current value */ int getTransactionSize() { return transactionList.size(); } /** * Retrieves whether the database object identifier by the dbobject * argument is accessible by the current Session User. * * @return true if so, else false */ boolean isAccessible(Object dbobject) throws HsqlException { return user.isAccessible(dbobject); }// boucherb@users 20030417 - patch 1.7.2 - compiled statement support//------------------------------------------------------------------- DatabaseCommandInterpreter dbCommandInterpreter; CompiledStatementExecutor compiledStatementExecutor; CompiledStatementManager compiledStatementManager; private CompiledStatement sqlCompileStatement(String sql) throws HsqlException { parser.reset(sql); CompiledStatement cs; int brackets = 0; String token = tokenizer.getString(); int cmd = Token.get(token); switch (cmd) { case Token.OPENBRACKET : { brackets = Parser.parseOpenBrackets(tokenizer) + 1; tokenizer.getThis(Token.T_SELECT); } case Token.SELECT : { cs = parser.compileSelectStatement(brackets); break; } case Token.INSERT : { cs = parser.compileInsertStatement(); break; } case Token.UPDATE : { cs = parser.compileUpdateStatement(); break; } case Token.DELETE : { cs = parser.compileDeleteStatement(); break; } case Token.CALL : { cs = parser.compileCallStatement(); break; } default : {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -