Class Session

  • All Implemented Interfaces:
    AutoCloseable

    public class Session
    extends Object
    implements AutoCloseable
    A session represents a transactional context for a Nitrite database. It provides methods to create a new transaction.

    A session should be closed after use to release any resources associated with it.

    If a session is closed and the transaction is not committed, all opened transactions will get rolled back and all volatile data gets discarded for the session.

    Since:
    4.0
    Author:
    Anindya Chatterjee
    • Constructor Detail

      • Session

        public Session​(Nitrite nitrite,
                       org.dizitart.no2.common.concurrent.LockService lockService)
        Instantiates a new Session.
        Parameters:
        nitrite - the nitrite
        lockService - the lock service
    • Method Detail

      • beginTransaction

        public Transaction beginTransaction()
        Begins a new transaction.
        Returns:
        the new transaction.
      • checkState

        public void checkState()
        Checks state of the session. If the session is not active, it will throw a TransactionException.
        Throws:
        TransactionException - when the session is not active, and a transaction is initiated in this session.