diff --git a/README.md b/README.md
index e43387695..098cc8f2a 100644
--- a/README.md
+++ b/README.md
@@ -232,6 +232,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-datastore/tre
| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
+| Native Image Datastore Sample | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java) |
| Quickstart Sample | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/example/datastore/QuickstartSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/datastore/QuickstartSample.java) |
| Task List | [source code](https://github.com/googleapis/java-datastore/blob/main/samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-datastore&page=editor&open_in_editor=samples/snippets/src/main/java/com/google/datastore/snippets/TaskList.java) |
diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml
index e0031c993..e8b47534e 100644
--- a/samples/native-image-sample/pom.xml
+++ b/samples/native-image-sample/pom.xml
@@ -91,7 +91,7 @@
org.graalvm.buildtools
junit-platform-native
- 0.9.9
+ 0.9.10
test
diff --git a/samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java b/samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java
index 54d27985e..7ce5c900a 100644
--- a/samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java
+++ b/samples/native-image-sample/src/main/java/com/example/datastore/NativeImageDatastoreSample.java
@@ -28,9 +28,7 @@
import java.time.Instant;
import java.util.UUID;
-/**
- * Sample Datastore Application.
- */
+/** Sample Datastore Application. */
public class NativeImageDatastoreSample {
/* Datastore namespace where entities will be created. */
@@ -39,9 +37,7 @@ public class NativeImageDatastoreSample {
/* Datastore kind used. */
private static final String TEST_KIND = "test-kind";
- /**
- * Entrypoint to the Datastore sample application.
- */
+ /** Entrypoint to the Datastore sample application. */
public static void main(String[] args) {
Instant startTime = Instant.now();
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
@@ -64,9 +60,7 @@ public static void main(String[] args) {
static void addEntity(Datastore datastore, String id) {
Key key = createKey(datastore, id);
- Entity entity = Entity.newBuilder(key)
- .set("description", "hello world")
- .build();
+ Entity entity = Entity.newBuilder(key).set("description", "hello world").build();
datastore.add(entity);
System.out.println("Successfully added entity.");
}
@@ -90,32 +84,35 @@ static void deleteEntity(Datastore datastore, String id) {
}
static void runTransactionCallable(Datastore datastore, Key entityKey) {
- datastore.runInTransaction(client -> {
- Entity entity = Entity.newBuilder(entityKey)
- .set("description", "hello world")
- .build();
- datastore.add(entity);
-
- StructuredQuery query =
- Query.newEntityQueryBuilder()
- .setNamespace(TEST_NAMESPACE)
- .setKind(TEST_KIND)
- .build();
-
- QueryResults results = datastore.run(query);
- while (results.hasNext()) {
- Entity result = results.next();
- String name = result.getKey().getName();
- String kind = result.getKey().getKind();
- String namespace = result.getKey().getNamespace();
- System.out.println(
- "Found entity:" + "\n\t\tname=" + name + "\n\t\tkind=" + kind + "\n\t\tnamespace="
- + namespace + "\n\t\tproperties=" + result.getProperties().toString());
- }
-
- datastore.delete(entityKey);
- return null;
- });
+ datastore.runInTransaction(
+ client -> {
+ Entity entity = Entity.newBuilder(entityKey).set("description", "hello world").build();
+ datastore.add(entity);
+
+ StructuredQuery query =
+ Query.newEntityQueryBuilder().setNamespace(TEST_NAMESPACE).setKind(TEST_KIND).build();
+
+ QueryResults results = datastore.run(query);
+ while (results.hasNext()) {
+ Entity result = results.next();
+ String name = result.getKey().getName();
+ String kind = result.getKey().getKind();
+ String namespace = result.getKey().getNamespace();
+ System.out.println(
+ "Found entity:"
+ + "\n\t\tname="
+ + name
+ + "\n\t\tkind="
+ + kind
+ + "\n\t\tnamespace="
+ + namespace
+ + "\n\t\tproperties="
+ + result.getProperties().toString());
+ }
+
+ datastore.delete(entityKey);
+ return null;
+ });
System.out.println("Ran transaction callable.");
}
@@ -129,9 +126,6 @@ private static void runTransaction(Datastore datastore) {
}
static Key createKey(Datastore datastore, String id) {
- return datastore.newKeyFactory()
- .setNamespace(TEST_NAMESPACE)
- .setKind(TEST_KIND)
- .newKey(id);
+ return datastore.newKeyFactory().setNamespace(TEST_NAMESPACE).setKind(TEST_KIND).newKey(id);
}
-}
\ No newline at end of file
+}
diff --git a/samples/native-image-sample/src/test/java/com/example/datastore/ITNativeImageDatastoreSample.java b/samples/native-image-sample/src/test/java/com/example/datastore/ITNativeImageDatastoreSample.java
index 315ecd909..710f18367 100644
--- a/samples/native-image-sample/src/test/java/com/example/datastore/ITNativeImageDatastoreSample.java
+++ b/samples/native-image-sample/src/test/java/com/example/datastore/ITNativeImageDatastoreSample.java
@@ -27,9 +27,7 @@
import org.junit.Before;
import org.junit.Test;
-/**
- * Tests for {@link com.example.datastore.NativeImageDatastoreSample}
- */
+/** Tests for {@link com.example.datastore.NativeImageDatastoreSample} */
public class ITNativeImageDatastoreSample {
private Datastore datastore;
@@ -42,7 +40,6 @@ public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
-
}
@Test
@@ -51,8 +48,7 @@ public void testAddAndGetEntity() {
String testId = "test-id-" + UUID.randomUUID();
NativeImageDatastoreSample.addEntity(datastore, testId);
NativeImageDatastoreSample.getEntity(datastore, testId);
- assertThat(bout.toString()).contains(
- "Reading entity: " + testId);
+ assertThat(bout.toString()).contains("Reading entity: " + testId);
NativeImageDatastoreSample.deleteEntity(datastore, testId);
}
@@ -63,13 +59,17 @@ public void testRunTransactionalCallable() {
String testId = "test-id-" + UUID.randomUUID();
Key key = NativeImageDatastoreSample.createKey(datastore, testId);
NativeImageDatastoreSample.runTransactionCallable(datastore, key);
- assertThat(bout.toString()).contains(
- "Found entity:" + "\n\t\tname=" + testId + "\n\t\tkind=test-kind"
- + "\n\t\tnamespace=nativeimage-test-namespace"
- + "\n\t\tproperties={description=StringValue{valueType=STRING, excludeFromIndexes=false,"
- + " meaning=0, value=hello world}}\n"
- + "Ran transaction callable.");
+ assertThat(bout.toString())
+ .contains(
+ "Found entity:"
+ + "\n\t\tname="
+ + testId
+ + "\n\t\tkind=test-kind"
+ + "\n\t\tnamespace=nativeimage-test-namespace"
+ + "\n\t\tproperties={description=StringValue{valueType=STRING, excludeFromIndexes=false,"
+ + " meaning=0, value=hello world}}\n"
+ + "Ran transaction callable.");
NativeImageDatastoreSample.deleteEntity(datastore, "test-id");
}
-}
\ No newline at end of file
+}