日期:2014-05-16 浏览次数:20754 次
我们看看insert语句的执行过程,
如果cs.isTransactionStatement()是true,则表示启动事务执行,
public Result executeCompiledStatement(Statement cs, Object[] pvals) {
Result r;
if (abortTransaction) {
rollback(false);
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
if (sessionContext.depth > 0) {
if (sessionContext.noSQL.booleanValue()
|| cs.isAutoCommitStatement()) {
return Result.newErrorResult(Error.error(ErrorCode.X_46000));
}
}
if (cs.isAutoCommitStatement()) {
if (isReadOnly()) {
return Result.newErrorResult(Error.error(ErrorCode.X_25006));
}
try {
/** special autocommit for backward compatibility */
commit(false);
} catch (HsqlException e) {
database.logger.logInfoEvent("Exception at commit");
}
}
sessionContext.currentStatement = cs;
boolean isTX = cs.isTransactionStatement();
if (!isTX) {
if (database.logger.getSqlEventLogLevel()
>= SimpleLog.LOG_NORMAL) {
sessionContext.setDynamicArguments(pvals);
database.logger.logStatementEvent(this, cs, pvals,
SimpleLog.LOG_NORMAL);
}
r = cs.execute(this);
sessionContext.currentStatement = null;
return r;
}
while (true) {
actionIndex = rowActionList.size();
database.txManager.beginAction(this, cs);
cs = sessionContext.currentStatement;
if (cs == null) {
return Result.newErrorResult(Error.error(ErrorCode.X_07502));
}
if (abortTransaction) {
rollback(false);
sessionContext.currentStatement = null;
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
try {
latch.await();
} catch (InterruptedException e) {
abortTransaction = true;
}
if (abortTransaction) {
rollback(false);
sessionContext.currentStatement = null;
return Result.newErrorResult(Error.error(ErrorCode.X_40001));
}
database.txManager.beginActionResume(this);
// tempActionHistory.add("sql execute " + cs.sql + " " + actionTimestamp + " " + rowActionList.size());
sessionContext.setDynamicArguments(pvals);
if (database.logger.getSqlEventLogLevel()
>= SimpleLog.LOG_NORMAL) {
database.logger.logStatementEvent(this, cs, pvals,
SimpleLog.L