You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
@@ -240,6 +240,9 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-spanner/tree/
| Database Operations |[source code](https://github.com/googleapis/java-spanner/blob/main/samples/native-image/src/main/java/com/example/spanner/DatabaseOperations.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/native-image/src/main/java/com/example/spanner/DatabaseOperations.java)|
244
+
| Instance Operations |[source code](https://github.com/googleapis/java-spanner/blob/main/samples/native-image/src/main/java/com/example/spanner/InstanceOperations.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/native-image/src/main/java/com/example/spanner/InstanceOperations.java)|
245
+
| Native Image Spanner Sample |[source code](https://github.com/googleapis/java-spanner/blob/main/samples/native-image/src/main/java/com/example/spanner/NativeImageSpannerSample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/native-image/src/main/java/com/example/spanner/NativeImageSpannerSample.java)|
243
246
| Add Json Column Sample |[source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/AddJsonColumnSample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/AddJsonColumnSample.java)|
244
247
| Add Numeric Column Sample |[source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/AddNumericColumnSample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/AddNumericColumnSample.java)|
245
248
| Async Dml Example |[source code](https://github.com/googleapis/java-spanner/blob/main/samples/snippets/src/main/java/com/example/spanner/AsyncDmlExample.java)|[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-spanner&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/spanner/AsyncDmlExample.java)|
This is a sample application which uses the Cloud Spanner client libraries and demonstrates compatibility with Native Image compilation.
4
+
5
+
The application creates a new Spanner instance and database, and it runs basic operations including queries and Spanner mutations.
6
+
7
+
## Setup Instructions
8
+
9
+
You will need to follow these prerequisite steps in order to run these samples:
10
+
11
+
1. If you have not already, [create a Google Cloud Platform Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project).
12
+
13
+
2. Install the [Google Cloud SDK](https://cloud.google.com/sdk/) which will allow you to run the sample with your project's credentials.
14
+
15
+
Once installed, log in with Application Default Credentials using the following command:
16
+
17
+
```
18
+
gcloud auth application-default login
19
+
```
20
+
21
+
**Note:** Authenticating with Application Default Credentials is convenient to use during development, but we recommend [alternate methods of authentication](https://cloud.google.com/docs/authentication/production) during production use.
22
+
23
+
3. Install the GraalVM compiler.
24
+
25
+
You can follow the [official installation instructions](https://www.graalvm.org/docs/getting-started-with-graalvm/#install-graalvm) from the GraalVM website.
26
+
After following the instructions, ensure that you install the Native Image extension installed by running:
27
+
28
+
```
29
+
gu install native-image
30
+
```
31
+
32
+
Once you finish following the instructions, verify that the default version of Java is set to the GraalVM version by running `java -version` in a terminal.
33
+
34
+
You will see something similar to the below output:
35
+
36
+
```
37
+
$ java -version
38
+
39
+
openjdk version "11.0.15" 2022-04-19
40
+
OpenJDK Runtime Environment GraalVM CE 22.1.0 (build 11.0.15+10-jvmci-22.1-b06)
41
+
OpenJDK 64-Bit Server VM GraalVM CE 22.1.0 (build 11.0.15+10-jvmci-22.1-b06, mixed mode, sharing)
42
+
43
+
```
44
+
## Run with Native Image Compilation
45
+
46
+
1. **(Optional)** If you wish to run the application against the [Spanner emulator](https://cloud.google.com/spanner/docs/emulator), make sure that you have the [Google Cloud SDK](https://cloud.google.com/sdk) installed.
47
+
48
+
In a new terminal window, start the emulator via `gcloud`:
49
+
50
+
```
51
+
gcloud beta emulators spanner start
52
+
```
53
+
54
+
You may leave the emulator running for now.
55
+
In the next section, we will run the sample application against the Spanner emulator instsance.
56
+
57
+
2. Navigate to this directory and compile the application with the Native Image compiler.
58
+
59
+
```
60
+
mvn package -P native -DskipTests
61
+
```
62
+
63
+
3. **(Optional)** If you're using the emulator, export the `SPANNER_EMULATOR_HOST` as an environment variable in your terminal.
64
+
65
+
```
66
+
export SPANNER_EMULATOR_HOST=localhost:9010
67
+
```
68
+
69
+
The Spanner Client Libraries will detect this environment variable and will automatically connect to the emulator instance if this variable is set.
70
+
71
+
4. Run the application.
72
+
73
+
```
74
+
./target/native-image
75
+
```
76
+
77
+
5. The application will run through some basic Spanner operations and log some output statements.
78
+
79
+
```
80
+
Running the Spanner Sample.
81
+
Singers Registered in Spanner:
82
+
Bob Loblaw
83
+
Virginia Watson
84
+
```
85
+
86
+
## Sample Integration test with Native Image Support
87
+
88
+
In order to run the sample integration test as a native image, call the following command:
0 commit comments