public boolean commitTransaction() {
      depth--;
      if (depth < 0) {
        throw new PanicException("commitTransaction invoked when no transaction active.");
      }
      if (depth > 0) {
        throw new PanicException("commitTransaction invoked on nested transaction.");
      }
      if (depth == 0) {
        if (validate() && transaction.commit()) {
          committed++;
          runCommitHandlers();
          return true;
        }
        abortTransaction();
        return false;
      } else {
        return true;
      }
    }