public interface Database extends java.lang.AutoCloseable, TransactionContext
Transaction
s are used to manipulate data within a single
Database
-- multiple, concurrent
Transaction
s on a Database
enforce ACID properties.TransactionContext
interface. When used on a Database
these
methods will call Transaction#commit()
after user code has been
executed. These methods will not return successfully until commit()
has
returned successfully.Database
objects must be closed
when no longer
in use in order to free any associated resources.Modifier and Type | Method and Description |
---|---|
void |
close()
Close the
Database object and release any associated resources. |
default Transaction |
createTransaction()
Creates a
Transaction that operates on this Database .Note: Java transactions automatically set the TransactionOptions.setUsedDuringCommitProtectionDisable()
option. |
Transaction |
createTransaction(java.util.concurrent.Executor e)
Creates a
Transaction that operates on this Database with the given Executor
for asynchronous callbacks. |
DatabaseOptions |
options()
Returns a set of options that can be set on a
Database |
default <T> T |
read(java.util.function.Function<? super ReadTransaction,T> retryable)
Runs a read-only transactional function against this
Database with retry logic. |
<T> T |
read(java.util.function.Function<? super ReadTransaction,T> retryable,
java.util.concurrent.Executor e)
Runs a read-only transactional function against this
Database with retry logic. |
default <T> java.util.concurrent.CompletableFuture<T> |
readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)
Runs a read-only transactional function against this
Database with retry logic. |
<T> java.util.concurrent.CompletableFuture<T> |
readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable,
java.util.concurrent.Executor e)
Runs a read-only transactional function against this
Database with retry logic. |
default <T> T |
run(java.util.function.Function<? super Transaction,T> retryable)
Runs a transactional function against this
Database with retry logic. |
<T> T |
run(java.util.function.Function<? super Transaction,T> retryable,
java.util.concurrent.Executor e)
Runs a transactional function against this
Database with retry logic. |
default <T> java.util.concurrent.CompletableFuture<T> |
runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)
Runs a transactional function against this
Database with retry logic. |
<T> java.util.concurrent.CompletableFuture<T> |
runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable,
java.util.concurrent.Executor e)
Runs a transactional function against this
Database with retry logic. |
getExecutor
default Transaction createTransaction()
Transaction
that operates on this Database
.TransactionOptions.setUsedDuringCommitProtectionDisable()
option. This is because the Java bindings disallow use of Transaction
objects after
Transaction.onError(java.lang.Throwable)
is called.Transaction
that reads from and writes to this Database
.Transaction createTransaction(java.util.concurrent.Executor e)
Transaction
that operates on this Database
with the given Executor
for asynchronous callbacks.e
- the Executor
to use when executing asynchronous callbacks for the databaseTransaction
that reads from and writes to this Database
.DatabaseOptions options()
Database
Database
default <T> T read(java.util.function.Function<? super ReadTransaction,T> retryable)
Database
with retry logic.
apply(ReadTransaction)
will be called on the
supplied Function
until a non-retryable
FDBException
(or any Throwable
other than an FDBException
)
is thrown. This call is blocking -- this
method will not return until the Function
has been called and completed without error.read
in interface ReadTransactionContext
T
- the return type of retryable
retryable
- the block of logic to execute in a Transaction
against
this databaseretryable
<T> T read(java.util.function.Function<? super ReadTransaction,T> retryable, java.util.concurrent.Executor e)
Database
with retry logic. Use
this formulation of read(Function)
if one wants to set a custom Executor
for the transaction when run.T
- the return type of retryable
retryable
- the block of logic to execute in a Transaction
against
this databasee
- the Executor
to use for asynchronous callbacksretryable
read(Function)
default <T> java.util.concurrent.CompletableFuture<T> readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)
Database
with retry logic.
apply(ReadTransaction)
will be called on the
supplied Function
until a non-retryable
FDBException
(or any Throwable
other than an FDBException
)
is thrown. This call is non-blocking -- this
method will return immediately and with a CompletableFuture
that will be
set when the Function
has been called and completed without error.retryable
, or received from the
database, will be set on the returned CompletableFuture
.readAsync
in interface ReadTransactionContext
T
- the return type of retryable
retryable
- the block of logic to execute in a ReadTransaction
against
this databaseCompletableFuture
that will be set to the value returned by the last call
to retryable
<T> java.util.concurrent.CompletableFuture<T> readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable, java.util.concurrent.Executor e)
Database
with retry logic.
Use this version of readAsync(Function)
if one wants to set a custom
Executor
for the transaction when run.T
- the return type of retryable
retryable
- the block of logic to execute in a ReadTransaction
against
this databasee
- the Executor
to use for asynchronous callbacksCompletableFuture
that will be set to the value returned by the last call
to retryable
readAsync(Function)
default <T> T run(java.util.function.Function<? super Transaction,T> retryable)
Database
with retry logic.
apply(Transaction)
will be called on the
supplied Function
until a non-retryable
FDBException
(or any Throwable
other than an FDBException
)
is thrown or commit()
,
when called after apply()
, returns success. This call is blocking -- this
method will not return until commit()
has been called and returned success.run
in interface TransactionContext
T
- the return type of retryable
retryable
- the block of logic to execute in a Transaction
against
this databaseretryable
<T> T run(java.util.function.Function<? super Transaction,T> retryable, java.util.concurrent.Executor e)
Database
with retry logic.
Use this formulation of run(Function)
if one would like to set a
custom Executor
for the transaction when run.T
- the return type of retryable
retryable
- the block of logic to execute in a Transaction
against
this databasee
- the Executor
to use for asynchronous callbacksretryable
default <T> java.util.concurrent.CompletableFuture<T> runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)
Database
with retry logic.
apply(Transaction)
will be called on the
supplied Function
until a non-retryable
FDBException
(or any Throwable
other than an FDBException
)
is thrown or commit()
,
when called after apply()
, returns success. This call is non-blocking -- this
method will return immediately and with a CompletableFuture
that will be
set when commit()
has been called and returned success.retryable
, or received from the
database, will be set on the returned CompletableFuture
.runAsync
in interface TransactionContext
T
- the return type of retryable
retryable
- the block of logic to execute in a Transaction
against
this databaseCompletableFuture
that will be set to the value returned by the last call
to retryable
<T> java.util.concurrent.CompletableFuture<T> runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable, java.util.concurrent.Executor e)
Database
with retry logic. Use
this formulation of the non-blocking runAsync(Function)
if one wants
to set a custom Executor
for the transaction when run.T
- the return type of retryable
retryable
- the block of logic to execute in a Transaction
against
this databasee
- the Executor
to use for asynchronous callbacksCompletableFuture
that will be set to the value returned by the last call
to retryable
run(Function)
void close()
Database
object and release any associated resources. This must be called at
least once after the Database
object is no longer in use. This can be called multiple
times, but care should be taken that it is not in use in another thread at the time of the call.close
in interface java.lang.AutoCloseable