public abstract class 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 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.
Static Methods
builder()
public static CloudDatastoreRemoteServiceConfig.Builder builder()
Returns a CloudDatastoreRemoteServiceConfig.Builder.
Returns | |
---|---|
Type | Description |
CloudDatastoreRemoteServiceConfig.Builder |
clear()
public static void clear()
Clears the CloudDatastoreRemoteServiceConfig instance (if one has been set) as well as the ApiProxy's EnvironmentFactory and the Environment for the current thread.
This method should only be called in tests.
setConfig(CloudDatastoreRemoteServiceConfig config)
public static void setConfig(CloudDatastoreRemoteServiceConfig config)
Sets the CloudDatastoreRemoteServiceConfig instance.
Parameter | |
---|---|
Name | Description |
config |
CloudDatastoreRemoteServiceConfig |
Constructors
CloudDatastoreRemoteServiceConfig()
public CloudDatastoreRemoteServiceConfig()