Packages

trait TxMethods extends AnyRef

Transactional methods for bundled transactions and tx functions

Source
TxMethods.scala
Linear Supertypes
AnyRef, Any
Type Hierarchy
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. TxMethods
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. macro def debugTransact(txFnCall: Seq[Seq[Statement]], txMolecules: MoleculeBase*): Unit

    Debug tx function invocation

    Print transaction statements to output of a tx function invocation without affecting the live database.

    Debug tx function invocation

    Print transaction statements to output of a tx function invocation without affecting the live database.

    // Print debug info for tx function invocation
    debugTransact(transfer(fromAccount, toAccount, 20))
    
    // Prints produced tx statements to output:
    /*
    ## 1 ## TxReport
    ========================================================================
    1          ArrayBuffer(
      1          List(
        1          :db/add       17592186045445       :Account/balance    80        Card(1))
      2          List(
        1          :db/add       17592186045447       :Account/balance    720       Card(1)))
    ------------------------------------------------
    2          List(
      1    1     added: true ,   t: 13194139534345,   e: 13194139534345,   a: 50,   v: Thu Nov 22 16:23:09 CET 2018
    
      2    2     added: true ,   t: 13194139534345,   e: 17592186045445,   a: 64,   v: 80
           3     added: false,  -t: 13194139534345,  -e: 17592186045445,  -a: 64,  -v: 100
    
      3    4     added: true ,   t: 13194139534345,   e: 17592186045447,   a: 64,   v: 720
           5     added: false,  -t: 13194139534345,  -e: 17592186045447,  -a: 64,  -v: 700)
    ========================================================================
    */
    txFnCall

    Tx function invocation

    txMolecules

    Optional tx meta data molecules

  7. def debugTransact(stmtss: Seq[Seq[Statement]]*)(implicit conn: Conn): Unit

    Debug bundled transaction statements

    Add transaction statements from one or more molecule actions to debugTransact to see the bundled transaction statements.

    Debug bundled transaction statements

    Add transaction statements from one or more molecule actions to debugTransact to see the bundled transaction statements.

    debugTransact(
      // retract
      e1.getRetractTx,
      // save
      Ns.int(4).getSaveTx,
      // insert
      Ns.int.getInsertTx(List(5, 6)),
      // update
      Ns(e2).int(20).getUpdateTx
    )
    
    // Prints transaction data to output:
    /*
      ## 1 ## TxReport
      ========================================================================
      1          ArrayBuffer(
        1          List(
          1          :db.fn/retractEntity   17592186045445)
        2          List(
          1          :db/add       #db/id[:db.part/user -1000247]     :Ns/int          4           Card(1))
        3          List(
          1          :db/add       #db/id[:db.part/user -1000252]     :Ns/int          5           Card(1))
        4          List(
          1          :db/add       #db/id[:db.part/user -1000253]     :Ns/int          6           Card(1))
        5          List(
          1          :db/add       17592186045446                     :Ns/int          20          Card(1)))
      ------------------------------------------------
      2          List(
        1    1     added: true ,   t: 13194139534345,   e: 13194139534345,   a: 50,   v: Wed Nov 14 23:38:15 CET 2018
    
        2    2     added: false,  -t: 13194139534345,  -e: 17592186045445,  -a: 64,  -v: 1
    
        3    3     added: true ,   t: 13194139534345,   e: 17592186045450,   a: 64,   v: 4
    
        4    4     added: true ,   t: 13194139534345,   e: 17592186045451,   a: 64,   v: 5
    
        5    5     added: true ,   t: 13194139534345,   e: 17592186045452,   a: 64,   v: 6
    
        6    6     added: true ,   t: 13194139534345,   e: 17592186045446,   a: 64,   v: 20
             7     added: false,  -t: 13194139534345,  -e: 17592186045446,  -a: 64,  -v: 2)
      ========================================================================
    */
    stmtss

    Statement's from multiple molecule operations

    conn

    Implicit Conn value in scope

  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. macro def transact(txFnCall: Seq[Seq[Statement]], txMolecules: MoleculeBase*): TxReport

    Transact tx function invocation

    Macro that takes a tx function invocation itself as its argument.

    Transact tx function invocation

    Macro that takes a tx function invocation itself as its argument. The tx function is analyzed by the macro and the necessary transaction preparations done at compile time.

    At runtime, the returned statements from the tx function is transacted as one atomic transaction.

    val txReport = transact(transfer(fromAccount, toAccount, 20))

    Transaction meta data molecules can be added

    // Add tx meta data that John did the transfer and that it is a scheduled transfer
    transact(
      transfer(fromAccount, toAccount, 20),
      Person.name("John"),
      UseCase.name("Scheduled transfer"))
    
    // Query multiple Tx meta data molecules
    Account(fromAccount).balance
      .Tx(Person.name_("John"))
      .Tx(UseCase.name_("Scheduled transfer")).get.head === 80
    Account(toAccount).balance
      .Tx(Person.name_("John"))
      .Tx(UseCase.name_("Scheduled transfer")).get.head === 720
    txFnCall

    Tx function invocation

    txMolecules

    Optional tx meta data molecules

    returns

    TxReport with result of transaction

  20. def transact(stmtss: Seq[Seq[Statement]]*)(implicit conn: Conn): TxReport

    Transact bundled transaction statements

    Supply transaction statements of one or more molecule actions to perform a single atomic transaction.

    Transact bundled transaction statements

    Supply transaction statements of one or more molecule actions to perform a single atomic transaction.

    transact(
      // retract entity
      e1.getRetractTx,
      // save new entity
      Ns.int(4).getSaveTx,
      // insert multiple new entities
      Ns.int.getInsertTx(List(5, 6)),
      // update entity
      Ns(e2).int(20).getUpdateTx
    )
    stmtss

    Statement's from multiple molecule operations

    conn

    Implicit Conn value in scope

    returns

    TxReport with result of transaction

  21. macro def transactAsync(txFnCall: Seq[Seq[Statement]], txMolecules: MoleculeBase*): TxReport

    Asynchronously transact tx function invocation

    Macro that takes a tx function invocation itself as its argument.

    Asynchronously transact tx function invocation

    Macro that takes a tx function invocation itself as its argument. The tx function is analyzed by the macro and the necessary transaction preparations done at compile time.

    At runtime, the returned statements from the tx function is asynchronously transacted as one atomic transaction using Datomic's asynchronous API.

    Await.result(
      transactAsync(transfer(fromAccount, toAccount, 20)) map { txReport =>
        Account(fromAccount).balance.get.head === 80 // (could be asynchronous too)
        Account(toAccount).balance.get.head === 720
      },
      2.seconds
    )

    Additional transaction meta data can be added

    Await.result(
      transactAsync(
        transfer(fromAccount, toAccount, 20),
        Person.name("John"),
        UseCase.name("Scheduled transfer")) map { txReport =>
          Account(fromAccount).balance
          .Tx(Person.name_("John"))
          .Tx(UseCase.name_("Scheduled transfer"))
          .get.head === 80 // (could be asynchronous too)
      },
      2.seconds
    )
    txFnCall

    Tx function invocation

    txMolecules

    Optional tx meta data molecules

    returns

    Future with TxReport with result of transaction

  22. def transactAsync(stmtss: Seq[Seq[Statement]]*)(implicit conn: Conn, ec: ExecutionContext): Future[TxReport]

    Asynchronously transact bundled transaction statements

    Asynchronously transact bundled transaction statements

    Supply transaction statements of one or more molecule actions to asynchronously transact a single atomic transaction.

    Await.result(
      transactAsync(
        e1.getRetractTx,
        Ns.int(4).getSaveTx,
        Ns.int.getInsertTx(List(5, 6)),
        Ns(e2).int(20).getUpdateTx
      ) map { bundleTx =>
        Ns.int.getAsync map { queryResult =>
          queryResult === List(3, 4, 5, 6, 20)
        }
      },
      2.seconds
    )
    stmtss

    Statement's from multiple molecule operations

    conn

    Implicit Conn value in scope

    returns

    Future with TxReport with result of transaction

  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Bundled transactions

Multiple molecule operations in one atomic transaction.

Transaction functions

Atomic transaction logic with access to tx database value.

Ungrouped