Java 8 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Java 8
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Java
8 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Java.
BaseDatastoreService (Google App Engine API for Java)
Stay organized with collections
Save and categorize content based on your preferences.
-
-
Method Detail
-
prepare
PreparedQuery prepare(Query query)
Prepares a query for execution.
This method returns a PreparedQuery
which can be used to execute and retrieve
results from the datastore for query
.
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, use prepare(Transaction, Query)
.
- Parameters:
query
- a not null Query
.
- Returns:
- a not
null PreparedQuery
.
-
prepare
PreparedQuery prepare(Transaction txn,
Query query)
Exhibits the same behavior as
prepare(Query)
, but executes within the provided
transaction. It is up to the caller to commit or rollback. Transaction can be null.
- Throws:
java.lang.IllegalArgumentException
- If txn is not null and query is not an ancestor query
java.lang.IllegalStateException
- 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:
java.util.NoSuchElementException
- If there is no current transaction.
-
getCurrentTransaction
Transaction getCurrentTransaction(Transaction returnedIfNoTxn)
Returns the current transaction for this thread, or returns the parameter if there is no
current transaction. You can use
null
or provide your own object to represent null. See
getCurrentTransaction()
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
java.util.Collection<Transaction> getActiveTransactions()
- Returns:
- All
Transaction
s started by this thread upon which no attempt to commit or
rollback has been made.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003e\u003ccode\u003eBaseDatastoreService\u003c/code\u003e is an interface that provides methods common to both \u003ccode\u003eDatastoreService\u003c/code\u003e and \u003ccode\u003eAsyncDatastoreService\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe interface includes methods to manage transactions, such as \u003ccode\u003egetCurrentTransaction\u003c/code\u003e for retrieving the current transaction and \u003ccode\u003egetActiveTransactions\u003c/code\u003e for getting all active transactions.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eBaseDatastoreService\u003c/code\u003e offers \u003ccode\u003eprepare\u003c/code\u003e methods to prepare a query for execution, with one version operating within a specified transaction and another ignoring transactions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eprepare(Query query)\u003c/code\u003e method prepares a query for execution without using a transaction, whereas the \u003ccode\u003eprepare(Transaction txn, Query query)\u003c/code\u003e method prepares a query within the provided transaction.\u003c/p\u003e\n"],["\u003cp\u003eThe method \u003ccode\u003egetCurrentTransaction()\u003c/code\u003e returns the current transaction if there is one, throwing an exception if there is none, while \u003ccode\u003egetCurrentTransaction(Transaction returnedIfNoTxn)\u003c/code\u003e returns the provided parameter if no transaction is present.\u003c/p\u003e\n"]]],[],null,["# BaseDatastoreService (Google App Engine API for Java)\n\ncom.google.appengine.api.datastore\n\nInterface BaseDatastoreService\n------------------------------\n\n-\n\n All Known Subinterfaces:\n : [AsyncDatastoreService](../../../../../com/google/appengine/api/datastore/AsyncDatastoreService.html \"interface in com.google.appengine.api.datastore\"), [DatastoreService](../../../../../com/google/appengine/api/datastore/DatastoreService.html \"interface in com.google.appengine.api.datastore\")\n\n All Known Implementing Classes:\n : [AdminDatastoreService](../../../../../com/google/appengine/api/datastore/AdminDatastoreService.html \"class in com.google.appengine.api.datastore\")\n\n *** ** * ** ***\n\n \u003cbr /\u003e\n\n ```\n public interface BaseDatastoreService\n ``` \nMethods that are common between [`DatastoreService`](../../../../../com/google/appengine/api/datastore/DatastoreService.html \"interface in com.google.appengine.api.datastore\") and [`AsyncDatastoreService`](../../../../../com/google/appengine/api/datastore/AsyncDatastoreService.html \"interface in com.google.appengine.api.datastore\"). \n-\n -\n\n ### Method Summary\n\n-\n -\n\n ### Method Detail\n\n\n -\n\n #### prepare\n\n ```\n PreparedQuery prepare(Query query)\n ``` \n Prepares a query for execution.\n\n This method returns a [`PreparedQuery`](../../../../../com/google/appengine/api/datastore/PreparedQuery.html \"interface in com.google.appengine.api.datastore\") which can be used to execute and retrieve\n results from the datastore for `query`.\n\n This operation will not execute in a transaction even if there is a current transaction and\n the provided query is an ancestor query. This operation also ignores the [`ImplicitTransactionManagementPolicy`](../../../../../com/google/appengine/api/datastore/ImplicitTransactionManagementPolicy.html \"enum in com.google.appengine.api.datastore\"). If you are preparing an ancestory query and you want it\n to execute in a transaction, use [`prepare(Transaction, Query)`](../../../../../com/google/appengine/api/datastore/BaseDatastoreService.html#prepare-com.google.appengine.api.datastore.Transaction-com.google.appengine.api.datastore.Query-).\n\n \u003cbr /\u003e\n\n Parameters:\n : `query` - a not `null Query`.\n\n Returns:\n : a not `null PreparedQuery`.\n\n\n -\n\n #### prepare\n\n ```\n PreparedQuery prepare(Transaction txn,\n Query query)\n ``` \n Exhibits the same behavior as [`prepare(Query)`](../../../../../com/google/appengine/api/datastore/BaseDatastoreService.html#prepare-com.google.appengine.api.datastore.Query-), but executes within the provided transaction. It is up to the caller to commit or rollback. Transaction can be null.\n\n Throws:\n : `java.lang.IllegalArgumentException` - If txn is not null and query is not an ancestor query\n : `java.lang.IllegalStateException` - If txn is not null and the txn is not active\n\n\n -\n\n #### getCurrentTransaction\n\n ```\n Transaction getCurrentTransaction()\n ``` \n 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.\n\n Use this method for when you expect there to be a current transaction and consider it an\n error if there isn't.\n\n Returns:\n : The current transaction.\n\n Throws:\n : `java.util.NoSuchElementException` - If there is no current transaction.\n\n\n -\n\n #### getCurrentTransaction\n\n ```\n Transaction getCurrentTransaction(Transaction returnedIfNoTxn)\n ``` \n Returns the current transaction for this thread, or returns the parameter if there is no current transaction. You can use `null` or provide your own object to represent null. See [`getCurrentTransaction()`](../../../../../com/google/appengine/api/datastore/BaseDatastoreService.html#getCurrentTransaction--) for a definition of \"current transaction.\"\n\n Use this method when you're not sure if there is a current transaction.\n\n Parameters:\n : `returnedIfNoTxn` - The return value of this method if there is no current transaction. Can\n be null.\n\n Returns:\n : The current transaction, or the parameter that was passed in if there is no current\n transaction.\n\n\n -\n\n #### getActiveTransactions\n\n ```\n java.util.Collection\u003cTransaction\u003e getActiveTransactions()\n ```\n\n Returns:\n : All [`Transaction`](../../../../../com/google/appengine/api/datastore/Transaction.html \"interface in com.google.appengine.api.datastore\")s started by this thread upon which no attempt to commit or\n rollback has been made."]]