Mentions légales du service

Skip to content
Snippets Groups Projects
Transaction 985 B
class Transaction {

  // Transaction id
  private transactionId: TxnId

  // The version vector at which the transaction has started
  private begin: VersionVector

  Transaction(tid: TxnId, body: TransactionBody) {
    this.begin = ActiveSession.txnEnv.getState()
    this.transactionId = ActiveSession.txnEnv.tickTransaction()

    try {
      // call the body function
      body()
      // if everything goes well commit
      this.commit()
    } catch {
      // If there is an exception abort
      this.abort()
    }
  }

  // c_abort_txn
  fun abort() {
    for obj in ActiveSession.dirtyObjects {
      obj.txnAbort()
    }
    ActiveSession.dirtyObjects.clear()
  }

  // c_commit_txn
  fun commit() {
    SERVICE.beginTransaction(this.transactionId)
    for obj in ActiveSession.dirtyObjects {
      SERVICE.pushObject(obj.crdt.getDelta(this.begin))
      obj.txnCommit()
    }
    SERVICE.commitTransaction(this.transactionId)
    ActiveSession.dirtyObjects.clear()
  }
}