Package org.dizitart.no2.transaction
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:
PersistentCollection.createIndex(String...)
PersistentCollection.createIndex(IndexOptions, String...)
PersistentCollection.rebuildIndex(String...)
PersistentCollection.dropIndex(String...)
PersistentCollection.dropAllIndices()
PersistentCollection.clear()
PersistentCollection.drop()
PersistentCollection.close()
PersistentCollection.createIndex(String...)
PersistentCollection.createIndex(IndexOptions, String...)
PersistentCollection.rebuildIndex(String...)
PersistentCollection.dropIndex(String...)
PersistentCollection.dropAllIndices()
PersistentCollection.clear()
PersistentCollection.drop()
PersistentCollection.close()
- Since:
- 4.0
- Author:
- Anindya Chatterjee
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes thisTransaction
.void
commit()
Completes the transaction and commits the data to the underlying store.NitriteCollection
getCollection(String name)
Gets aNitriteCollection
to perform transactional operations on it.String
getId()
Gets the unique identifier of the transaction.<T> ObjectRepository<T>
getRepository(Class<T> type)
Gets anObjectRepository
to perform transactional operations on it.<T> ObjectRepository<T>
getRepository(Class<T> type, String key)
Gets anObjectRepository
to perform transactional operations on it.<T> ObjectRepository<T>
getRepository(EntityDecorator<T> entityDecorator)
Gets anObjectRepository
to perform transactional operations on it.<T> ObjectRepository<T>
getRepository(EntityDecorator<T> entityDecorator, String key)
Gets anObjectRepository
to perform transactional operations on it.TransactionState
getState()
Returns the current state of the transaction.void
rollback()
Rolls back the transaction, discarding any changes made during the transaction.
-
-
-
Method Detail
-
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 aNitriteCollection
to perform transactional operations on it.- Parameters:
name
- the name- Returns:
- the collection
-
getRepository
<T> ObjectRepository<T> getRepository(Class<T> type)
Gets anObjectRepository
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 anObjectRepository
to perform transactional operations on it.- Type Parameters:
T
- the type parameter- Parameters:
type
- the typekey
- the key- Returns:
- the repository
-
getRepository
<T> ObjectRepository<T> getRepository(EntityDecorator<T> entityDecorator)
Gets anObjectRepository
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 anObjectRepository
to perform transactional operations on it.- Type Parameters:
T
- the type parameter- Parameters:
entityDecorator
- the entityDecoratorkey
- 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 thisTransaction
.- Specified by:
close
in interfaceAutoCloseable
-
-