public abstract class CloudDatastoreRemoteServiceConfig
extends java.lang.Object
Code not running in App Engine Standard can use the Cloud Datastore API by making a single
call to setConfig(com.google.appengine.api.datastore.CloudDatastoreRemoteServiceConfig)
before accessing any other classes from com.google.appengine.api
. For example:
public static void main(Strings[] args) { CloudDatastoreRemoteServiceConfig config = CloudDatastoreRemoteServiceConfig.builder() .appId(AppId.create(Location.US_CENTRAL, "my-project-id")) .build(); CloudDatastoreRemoteServiceConfig.setConfig(config); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); ... }Outside of tests, the config should not be cleared once it has been set. In tests, the config can be cleared by calling
clear()
:
@Before public void before() { CloudDatastoreRemoteServiceConfig config = CloudDatastoreRemoteServiceConfig.builder() .appId(AppId.create(Location.US_CENTRAL, "my-project-id")) .emulatorHost(...) .build(); CloudDatastoreRemoteServiceConfig.setConfig(config); } @After public void after() { CloudDatastoreRemoteServiceConfig.clear(); }By default, this configuration uses application-default credentials.
Modifier and Type | Class and Description |
---|---|
static class |
CloudDatastoreRemoteServiceConfig.AppId
An App Engine application ID.
|
static class |
CloudDatastoreRemoteServiceConfig.Builder
Builder for
CloudDatastoreRemoteServiceConfig . |
Constructor and Description |
---|
CloudDatastoreRemoteServiceConfig() |
Modifier and Type | Method and Description |
---|---|
static CloudDatastoreRemoteServiceConfig.Builder |
builder()
Returns a
CloudDatastoreRemoteServiceConfig.Builder . |
static void |
clear()
Clears the
CloudDatastoreRemoteServiceConfig instance (if one has been set) as well as
the ApiProxy 's ApiProxy.EnvironmentFactory and the ApiProxy.Environment for the current
thread. |
static void |
setConfig(CloudDatastoreRemoteServiceConfig config)
Sets the
CloudDatastoreRemoteServiceConfig instance. |
public static void setConfig(CloudDatastoreRemoteServiceConfig config)
CloudDatastoreRemoteServiceConfig
instance.java.lang.IllegalStateException
- if the CloudDatastoreRemoteServiceConfig
instance has
already been set and clear()
has not been calledjava.lang.IllegalStateException
- if the provided CloudDatastoreRemoteServiceConfig
is not
supported in this environmentpublic static void clear()
CloudDatastoreRemoteServiceConfig
instance (if one has been set) as well as
the ApiProxy
's ApiProxy.EnvironmentFactory
and the ApiProxy.Environment
for the current
thread.
This method should only be called in tests.
public static CloudDatastoreRemoteServiceConfig.Builder builder()
CloudDatastoreRemoteServiceConfig.Builder
.