This application uses the Google Cloud Datastore client library and is compatible with Native Image compilation.
This sample runs through some basic operations of creating/deleting entities, running queries, and running transaction code.
-
Follow the GCP Project and Native Image Setup Instructions.
-
If you wish to run the application against the Datastore emulator, ensure that you have the Google Cloud SDK installed.
In a new terminal window, start the emulator via
gcloud
:gcloud beta emulators datastore start --host-port=localhost:9010
Leave the emulator running in this terminal for now. In the next section, we will run the sample application against the Datastore emulator instance.
-
Navigate to this directory and compile the application with the Native Image compiler.
mvn package -P native
-
(Optional) If you're using the emulator, export the
DATASTORE_EMULATOR_HOST
as an environment variable in your terminal.export DATASTORE_EMULATOR_HOST=localhost:9010
The Datastore Client Libraries will detect this environment variable and automatically connect to the emulator instance if this variable is set.
-
Run the application.
./target/datastore-sample
-
The application will run through some basic Datastore operations and log some output statements.
Successfully added entity. Reading entity: f806384f-259d-4d04-8c69-1ae0d83c063c Successfully deleted entity: f806384f-259d-4d04-8c69-1ae0d83c063c Run dummy transaction code. Found entity: Entity{key=Key{projectId=my-kubernetes-codelab-217414, namespace=graalvm-test-namespace, path=[PathElement{kind=test-kind, id=null, name=2cbd912e-8074-4430-802d-32e60102afb2}]}, properties={description=StringValue{valueType=STRING, excludeFromIndexes=false, meaning=0, value=hello world}}} Ran transaction callable.