Class CloudDatastoreRemoteServiceConfig
java.lang.Object
com.google.appengine.api.datastore.CloudDatastoreRemoteServiceConfig
User-configurable global properties of Cloud Datastore.
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():
{@literal @}Before
public void before() {
CloudDatastoreRemoteServiceConfig config = CloudDatastoreRemoteServiceConfig.builder()
.appId(AppId.create(Location.US_CENTRAL, "my-project-id"))
.emulatorHost(...)
.build();
CloudDatastoreRemoteServiceConfig.setConfig(config);
}
{@literal @}After
public void after() {
CloudDatastoreRemoteServiceConfig.clear();
}
By default, this configuration uses application-default
credentials.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn App Engine application ID.static classBuilder forCloudDatastoreRemoteServiceConfig. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Returns aCloudDatastoreRemoteServiceConfig.Builder.static voidclear()Clears theCloudDatastoreRemoteServiceConfiginstance (if one has been set) as well as theApiProxy'sApiProxy.EnvironmentFactoryand theApiProxy.Environmentfor the current thread.static voidSets theCloudDatastoreRemoteServiceConfiginstance.
-
Constructor Details
-
CloudDatastoreRemoteServiceConfig
public CloudDatastoreRemoteServiceConfig()
-
-
Method Details
-
setConfig
Sets theCloudDatastoreRemoteServiceConfiginstance.- Throws:
IllegalStateException- if theCloudDatastoreRemoteServiceConfiginstance has already been set andclear()has not been calledIllegalStateException- if the providedCloudDatastoreRemoteServiceConfigis not supported in this environment
-
clear
public static void clear()Clears theCloudDatastoreRemoteServiceConfiginstance (if one has been set) as well as theApiProxy'sApiProxy.EnvironmentFactoryand theApiProxy.Environmentfor the current thread.This method should only be called in tests.
-
builder
Returns aCloudDatastoreRemoteServiceConfig.Builder.
-