Class DaxBase

java.lang.Object
com.github.sttk.sabi.DaxBase
All Implemented Interfaces:
Dax, AutoCloseable

public class DaxBase extends Object implements Dax, AutoCloseable
DaxBase is the class that defines the methods to manage DaxSrc(s). And this class defines private methods to process a transaction.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    CreatedDaxConnIsNull is the error reason which indicates that a DaxSrc created a DaxConn interface but it is null.
    static final record 
    DaxSrcIsNotFound is the error reason which indicates that a specified DaxSrc is not found.
    static final record 
    FailToCommitDaxConn is the error reason which indicates that some connections failed to commit.
    static final record 
    FailToCreateDaxConn is the error reason which indicates that it is failed to create a new connection to a data store.
    static final record 
    FailToRunLogic is the error reason which indicates that a logic failed to run.
    static final record 
    FailToSetupGlobalDaxSrcs is the error reason which indicates that some DaxSrc(s) failed to set up.
    static final record 
    FailToSetupLocalDaxSrc is the error reason which indicates a local DaxSrc failed to set up.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Begins a transaction processing.
    void
    Closes and frees all local DaxSrc(s).
    protected void
    Commits updates in a transaction processing.
    void
    Closes and removes a local DaxSrc specified by the argument name.
    protected void
    end()
    Ends a transaction.
    <C extends DaxConn>
    C
    Gets a DaxConn instance associated with the argument name.
    protected void
    Rollbacks all updates in a transaction.
    final <D> void
    txn(Logic<D>... logics)
    Executes logics in a transaction.
    void
    uses(String name, DaxSrc ds)
    Registers and sets up a local DaxSrc with an argument name.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DaxBase

      public DaxBase()
      The default constructor.
  • Method Details

    • close

      public void close()
      Closes and frees all local DaxSrc(s).
      Specified by:
      close in interface AutoCloseable
    • uses

      public void uses(String name, DaxSrc ds) throws Err
      Registers and sets up a local DaxSrc with an argument name.
      Parameters:
      name - The name for the DaxSrc to be registered.
      ds - The DaxSrc instance to be registered.
      Throws:
      Err - If an exception occuers by either of the following reasons:
    • disuses

      public void disuses(String name)
      Closes and removes a local DaxSrc specified by the argument name.
      Parameters:
      name - The name of the local DaxSrc to be removed.
    • begin

      protected void begin()
      Begins a transaction processing. This method forbids registration of more local DaxSrc(s) while a transaction processing.
    • commit

      protected void commit() throws Err
      Commits updates in a transaction processing.
      Throws:
      Err - If an exception occuers by either of the following reasons:
    • rollback

      protected void rollback()
      Rollbacks all updates in a transaction.
    • end

      protected void end()
      Ends a transaction. This method closes all DaxConn and removes them from this DaxBase..
    • getDaxConn

      public <C extends DaxConn> C getDaxConn(String name) throws Err
      Gets a DaxConn instance associated with the argument name. The name is same as what was registered with DaxSrc using Sabi.uses(java.lang.String, com.github.sttk.sabi.DaxSrc) method.
      Specified by:
      getDaxConn in interface Dax
      Type Parameters:
      C - The type of a DaxConn.
      Parameters:
      name - A name of a DaxConn.
      Returns:
      A DaxConn instance.
      Throws:
      Err - If getting a DaxConn fails.
    • txn

      @SafeVarargs public final <D> void txn(Logic<D>... logics) throws Err
      Executes logics in a transaction. First, this method casts the argument DaxBase to the type specified as a logic's argument. Next, this method begins the transaction, and executes the argument logics. Then, if no error occurs, this method commits all updates in the transaction, otherwise rollbaks them. If there are commit errors after some DaxConn(s) are committed, or there are DaxConn(s) which don't have rollback mechanism, this method executes DaxConn.forceBack(com.github.sttk.sabi.AsyncGroup) methods of these DaxConn(s). And after that, this method ends the transaction. During a transaction, it is denied to add or remove any local DaxSrc(s).
      Throws:
      Err