Skip to content

Commit

Permalink
Syntax highlight Java code snippet.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrukman committed Feb 17, 2015
1 parent 946090c commit 083acf4
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,28 @@ consistency for all other queries.
Follow the [activation instructions][cloud-datastore-activation] to use the Google
Cloud Datastore API with your project.

import com.google.gcloud.datastore.DatastoreService;
import com.google.gcloud.datastore.DatastoreServiceFactory;
import com.google.gcloud.datastore.DatastoreServiceOptions;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;

DatastoreServiceOptions options = DatastoreServiceOptions.builder().dataset("...").build();
DatastoreService datastore = DatastoreServiceFactory.getDefault(options);
KeyFactory keyFactory = new KeyFactory(datastore).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("updated", false)
.build();
datastore.put(entity);
}
```java
import com.google.gcloud.datastore.DatastoreService;
import com.google.gcloud.datastore.DatastoreServiceFactory;
import com.google.gcloud.datastore.DatastoreServiceOptions;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
import com.google.gcloud.datastore.KeyFactory;

DatastoreServiceOptions options = DatastoreServiceOptions.builder().dataset("...").build();
DatastoreService datastore = DatastoreServiceFactory.getDefault(options);
KeyFactory keyFactory = new KeyFactory(datastore).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("updated", false)
.build();
datastore.put(entity);
}
```

## Contributing

Expand Down

0 comments on commit 083acf4

Please sign in to comment.