Interface BaseDatastoreService
- All Known Subinterfaces:
AsyncDatastoreService
,DatastoreService
- All Known Implementing Classes:
AdminDatastoreService
public interface BaseDatastoreService
Methods that are common between
DatastoreService
and AsyncDatastoreService
.-
Method Summary
Modifier and TypeMethodDescriptionReturns allTransaction
s started by this thread upon which no attempt to commit or rollback has been made.Returns the current transaction for this thread, or throws an exception if there is no current transaction.getCurrentTransaction
(Transaction returnedIfNoTxn) Returns the current transaction for this thread, or returns the parameter if there is no current transaction.Prepares a query for execution.prepare
(Transaction txn, Query query) Exhibits the same behavior asprepare(Query)
, but executes within the provided transaction.
-
Method Details
-
prepare
Prepares a query for execution.This method returns a
PreparedQuery
which can be used to execute and retrieve results from the datastore forquery
.This operation will not execute in a transaction even if there is a current transaction and the provided query is an ancestor query. This operation also ignores the
ImplicitTransactionManagementPolicy
. If you are preparing an ancestory query and you want it to execute in a transaction, useprepare(Transaction, Query)
.- Parameters:
query
- a notnull Query
.- Returns:
- a not
null PreparedQuery
.
-
prepare
Exhibits the same behavior asprepare(Query)
, but executes within the provided transaction. It is up to the caller to commit or rollback. Transaction can be null.- Throws:
IllegalArgumentException
- If txn is not null and query is not an ancestor queryIllegalStateException
- If txn is not null and the txn is not active
-
getCurrentTransaction
Transaction getCurrentTransaction()Returns the current transaction for this thread, or throws an exception if there is no current transaction. The current transaction is defined as the result of the most recent, same-thread invocation of beginTransaction() that has not been committed or rolled back.Use this method for when you expect there to be a current transaction and consider it an error if there isn't.
- Returns:
- The current transaction.
- Throws:
NoSuchElementException
- If there is no current transaction.
-
getCurrentTransaction
Returns the current transaction for this thread, or returns the parameter if there is no current transaction. You can usenull
or provide your own object to represent null. SeegetCurrentTransaction()
for a definition of "current transaction."Use this method when you're not sure if there is a current transaction.
- Parameters:
returnedIfNoTxn
- The return value of this method if there is no current transaction. Can be null.- Returns:
- The current transaction, or the parameter that was passed in if there is no current transaction.
-
getActiveTransactions
Collection<Transaction> getActiveTransactions()Returns allTransaction
s started by this thread upon which no attempt to commit or rollback has been made.
-