Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Google Cloud Java Client for Datastore

Java idiomatic client for [Google Cloud Datastore] (https://cloud.google.com/datastore/).

Build Status Coverage Status Maven

Note: This client is a work-in-progress, and may occasionally make backwards-incompatible changes.

Quickstart

Add this to your pom.xml file

<dependency>
  <groupId>com.google.gcloud</groupId>
  <artifactId>gcloud-java-datastore</artifactId>
  <version>0.0.10</version>
</dependency>

Example Application

DatastoreExample is a simple command line interface for the Cloud Datastore. Read more about using the application on the gcloud-java-examples docs page.

Authentication

See the Authentication section in the base directory's README.

About Google Cloud Datastore

Google Cloud Datastore is a fully managed, schemaless database for storing non-relational data. Cloud Datastore automatically scales with your users and supports ACID transactions, high availability of reads and writes, strong consistency for reads and ancestor queries, and eventual consistency for all other queries.

See the Google Cloud Datastore docs for more details on how to activate Cloud Datastore for your project.

See the gcloud-java API datastore documentation to learn how to interact with the Cloud Datastore using this Client Library.

Here is a code snippet showing a simple usage example from within Compute/App Engine. Note that you must supply credentials and a project ID if running this snippet elsewhere.

import com.google.gcloud.datastore.Datastore;
import com.google.gcloud.datastore.DatastoreOptions;
import com.google.gcloud.datastore.DateTime;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;

Datastore datastore = DatastoreOptions.getDefaultInstance().service();
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND);
Key key = keyFactory.newKey(keyName);
Entity entity = datastore.get(key);
if (entity == null) {
  entity = Entity.builder(key)
      .set("name", "John Do")
      .set("age", 30)
      .set("access_time", DateTime.now())
      .build();
  datastore.put(entity);
} else {
  System.out.println("Updating access_time for " + entity.getString("name"));
  entity = Entity.builder(entity)
      .set("access_time", DateTime.now())
      .build();
  datastore.update(entity);
}

Java Versions

Java 7 or above is required for using this client.

Testing

This library has tools to help write tests for code that uses the Datastore.

See TESTING to read more about testing.

Versioning

This library follows [Semantic Versioning] (http://semver.org/).

It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.

Contributing

Contributions to this library are always welcome and highly encouraged.

See CONTRIBUTING for more information on how to get started.

License

Apache 2.0 - See LICENSE for more information.