Interface Transaction

All Superinterfaces:
AutoCloseable

public interface Transaction extends AutoCloseable
Represents a transaction in Nitrite database. It provides methods to perform transactional operations on Nitrite database collections and repositories.

A transaction can be committed or rolled back. Once a transaction is committed, all changes made during the transaction are persisted to the underlying store. If a transaction is rolled back, all changes made during the transaction are discarded.

NOTE: Certain operations are auto-committed in Nitrite database. Those operations are not part of a transaction and cannot be rolled back. The following operations are auto-committed:

Since:
4.0
Author:
Anindya Chatterjee
  • Method Details

    • getId

      String getId()
      Gets the unique identifier of the transaction.
      Returns:
      the unique identifier of the transaction.
    • getState

      TransactionState getState()
      Returns the current state of the transaction.
      Returns:
      the current state of the transaction.
    • getCollection

      NitriteCollection getCollection(String name)
      Gets a NitriteCollection to perform transactional operations on it.
      Parameters:
      name - the name
      Returns:
      the collection
    • getRepository

      <T> ObjectRepository<T> getRepository(Class<T> type)
      Gets an ObjectRepository to perform transactional operations on it.
      Type Parameters:
      T - the type parameter
      Parameters:
      type - the type
      Returns:
      the repository
    • getRepository

      <T> ObjectRepository<T> getRepository(Class<T> type, String key)
      Gets an ObjectRepository to perform transactional operations on it.
      Type Parameters:
      T - the type parameter
      Parameters:
      type - the type
      key - the key
      Returns:
      the repository
    • getRepository

      <T> ObjectRepository<T> getRepository(EntityDecorator<T> entityDecorator)
      Gets an ObjectRepository to perform transactional operations on it.
      Type Parameters:
      T - the type parameter
      Parameters:
      entityDecorator - the entityDecorator
      Returns:
      the repository
    • getRepository

      <T> ObjectRepository<T> getRepository(EntityDecorator<T> entityDecorator, String key)
      Gets an ObjectRepository to perform transactional operations on it.
      Type Parameters:
      T - the type parameter
      Parameters:
      entityDecorator - the entityDecorator
      key - the key
      Returns:
      the repository
    • commit

      void commit()
      Completes the transaction and commits the data to the underlying store.
    • rollback

      void rollback()
      Rolls back the transaction, discarding any changes made during the transaction.
    • close

      void close()
      Closes this Transaction.
      Specified by:
      close in interface AutoCloseable