File tree

5 files changed

+152
-60
lines changed

5 files changed

+152
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
custom_content: |
2+
#### Calling Cloud Spanner
3+
Here is a code snippet showing a simple usage example. Add the following imports
4+
at the top of your file:
5+
6+
```java
7+
import com.google.cloud.spanner.DatabaseClient;
8+
import com.google.cloud.spanner.DatabaseId;
9+
import com.google.cloud.spanner.ResultSet;
10+
import com.google.cloud.spanner.Spanner;
11+
import com.google.cloud.spanner.SpannerOptions;
12+
import com.google.cloud.spanner.Statement;
13+
14+
```
15+
16+
Then, to make a query to Spanner, use the following code:
17+
```java
18+
// Instantiates a client
19+
SpannerOptions options = SpannerOptions.newBuilder().build();
20+
Spanner spanner = options.getService();
21+
String instance = "my-instance";
22+
String database = "my-database";
23+
try {
24+
// Creates a database client
25+
DatabaseClient dbClient = spanner.getDatabaseClient(
26+
DatabaseId.of(options.getProjectId(), instance, database));
27+
// Queries the database
28+
try (ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1"))) {
29+
// Prints the results
30+
while (resultSet.next()) {
31+
System.out.printf("%d\n", resultSet.getLong(0));
32+
}
33+
}
34+
} finally {
35+
// Closes the client which will free up the resources used
36+
spanner.close();
37+
}
38+
```
39+
40+
#### Complete source code
41+
42+
In [DatabaseSelect.java](https://.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/DatabaseSelect.java) we put together all the code shown above in a single program.
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
"name_pretty": "Cloud Spanner",
44
"product_documentation": "https://cloud.google.com/spanner/docs/",
55
"client_documentation": "https://googleapis.dev/java/google-cloud-spanner/latest/",
6+
"api_description": "is a fully managed, mission-critical, \nrelational database service that offers transactional consistency at global scale, \nschemas, SQL (ANSI 2011 with extensions), and automatic, synchronous replication \nfor high availability.\n\nBe sure to activate the Cloud Spanner API on the Developer's Console to\nuse Cloud Spanner from your project.",
67
"issue_tracker": "https://issuetracker.google.com/issues?q=componentid:190851%2B%20status:open",
78
"release_level": "ga",
89
"language": "java",
910
"repo": "googleapis/java-spanner",
1011
"repo_short": "java-spanner",
1112
"distribution_name": "com.google.cloud:google-cloud-spanner",
12-
"api_id": "spanner.googleapis.com"
13+
"api_id": "spanner.googleapis.com",
14+
"transport": "grpc",
15+
"requires_billing": true
1316
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
1-
# Google Cloud Java Client for Spanner
1+
# Google Cloud Spanner Client for Java
22

3-
Java idiomatic client for [Cloud Spanner][cloud-spanner].
3+
Java idiomatic client for [Cloud Spanner][product-docs].
44

5-
[![Kokoro CI](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.svg)](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.html)
6-
[![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg)
7-
[![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java)
5+
[![Maven][maven-version-image]][maven-version-link]
6+
![Stability][stability-image]
87

9-
- [Product Documentation][spanner-product-docs]
10-
- [Client Library Documentation][spanner-client-lib-docs]
8+
- [Product Documentation][product-docs]
9+
- [Client Library Documentation][javadocs]
1110

1211
## Quickstart
13-
If you are using Maven with a BOM, add this to your pom.xml file.
12+
13+
If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file
1414
```xml
1515
<dependencyManagement>
16-
<dependencies>
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.google.cloud</groupId>
19+
<artifactId>libraries-bom</artifactId>
20+
<version>5.1.0</version>
21+
<type>pom</type>
22+
<scope>import</scope>
23+
</dependency>
24+
</dependencies>
25+
</dependencyManagement>
26+
27+
<dependencies>
1728
<dependency>
1829
<groupId>com.google.cloud</groupId>
19-
<artifactId>libraries-bom</artifactId>
20-
<version>3.0.0</version>
21-
<type>pom</type>
22-
<scope>import</scope>
23-
</dependency>
24-
</dependencies>
25-
</dependencyManagement>
30+
<artifactId>google-cloud-spanner</artifactId>
31+
</dependency>
2632

27-
<dependency>
28-
<groupId>com.google.cloud</groupId>
29-
<artifactId>google-cloud-spanner</artifactId>
30-
</dependency>
3133
```
32-
[//]: # ({x-version-update-start:google-cloud-spanner:released})
33-
If you are using Maven without a BOM, add this to your dependencies.
34+
35+
If you are using Maven without BOM, add this to your dependencies:
36+
3437
```xml
3538
<dependency>
3639
<groupId>com.google.cloud</groupId>
3740
<artifactId>google-cloud-spanner</artifactId>
38-
<version>1.53.0</version>
41+
<version>1.52.0</version>
3942
</dependency>
43+
4044
```
45+
46+
[//]: # ({x-version-update-start:google-cloud-spanner:released})
47+
4148
If you are using Gradle, add this to your dependencies
4249
```Groovy
4350
compile 'com.google.cloud:google-cloud-spanner:1.53.0'
@@ -50,27 +57,37 @@ libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "1.53.0"
5057

5158
## Authentication
5259

53-
See the
54-
[Authentication](https://.com/googleapis/google-cloud-java#authentication)
55-
section in the base directory's README.
60+
See the [Authentication][authentication] section in the base directory's README.
61+
62+
## Getting Started
63+
64+
### Prerequisites
65+
66+
You will need a [Google Cloud Platform Console][developer-console] project with the Cloud Spanner [API enabled][enable-api].
67+
You will need to [enable billing][enable-billing] to use Google Cloud Spanner.
68+
[Follow these instructions][create-project] to get your project set up. You will also need to set up the local development environment by
69+
[installing the Google Cloud SDK][cloud-sdk] and running the following commands in command line:
70+
`gcloud auth login` and `gcloud config set project [YOUR PROJECT ID]`.
71+
72+
### Installation and setup
73+
74+
You'll need to obtain the `google-cloud-spanner` library. See the [Quickstart](#quickstart) section
75+
to add `google-cloud-spanner` as a dependency in your code.
5676

5777
## About Cloud Spanner
5878

59-
[Cloud Spanner][cloud-spanner] is a fully managed, mission-critical,
79+
80+
[Cloud Spanner][product-docs] is a fully managed, mission-critical,
6081
relational database service that offers transactional consistency at global scale,
6182
schemas, SQL (ANSI 2011 with extensions), and automatic, synchronous replication
6283
for high availability.
6384

6485
Be sure to activate the Cloud Spanner API on the Developer's Console to
6586
use Cloud Spanner from your project.
6687

67-
See the [Spanner client lib docs][spanner-client-lib-docs] to learn how to
68-
interact with Cloud Spanner using this Client Library.
88+
See the [Cloud Spanner client library docs][javadocs] to learn how to
89+
use this Cloud Spanner Client Library.
6990

70-
## Getting Started
71-
#### Prerequisites
72-
Please refer to the [getting
73-
started](https://cloud.google.com/spanner/docs/getting-started/java/) guide.
7491

7592
#### Calling Cloud Spanner
7693
Here is a code snippet showing a simple usage example. Add the following imports
@@ -112,48 +129,79 @@ try {
112129

113130
#### Complete source code
114131

115-
In [DatabaseSelect.java](../../google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/DatabaseSelect.java) we put together all the code shown above in a single program.
132+
In [DatabaseSelect.java](https://.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/DatabaseSelect.java) we put together all the code shown above in a single program.
116133

117-
## Troubleshooting
118134

119-
To get help, follow the instructions in the [shared Troubleshooting
120-
document](https://.com/googleapis/google-cloud-common/blob/master/troubleshooting/readme.md#troubleshooting).
121135

122-
Transport
123-
---------
124-
Spanner uses gRPC for the transport layer.
125136

126-
## Java Versions
127137

128-
Java 7 or above is required for using this client.
138+
## Troubleshooting
129139

130-
## Testing
140+
To get help, follow the instructions in the [shared Troubleshooting document][troubleshooting].
131141

132-
This library has tools to help make tests for code using Cloud Spanner.
142+
## Transport
133143

134-
See [TESTING] to read more about testing.
144+
Cloud Spanner uses gRPC for the transport layer.
145+
146+
## Java Versions
147+
148+
Java 7 or above is required for using this client.
135149

136150
## Versioning
137151

152+
138153
This library follows [Semantic Versioning](http://semver.org/).
139154

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

143156
## Contributing
144157

158+
145159
Contributions to this library are always welcome and highly encouraged.
146160

147-
See [CONTRIBUTING] for more information on how to get started.
161+
See [CONTRIBUTING][contributing] for more information how to get started.
148162

149-
## License
163+
Please note that this project is released with a Contributor Code of Conduct. By participating in
164+
this project you agree to abide by its terms. See [Code of Conduct][code-of-conduct] for more
165+
information.
150166

151-
Apache 2.0 - See [LICENSE] for more information.
167+
## License
152168

153-
[CONTRIBUTING]:https://.com/googleapis/google-cloud-java/blob/master/CONTRIBUTING.md
154-
[LICENSE]: https://.com/googleapis/google-cloud-java/blob/master/LICENSE
155-
[TESTING]: https://.com/googleapis/google-cloud-java/blob/master/TESTING.md#testing-code-that-uses-cloud-spanner
156-
[cloud-platform]: https://cloud.google.com/
157-
[cloud-spanner]: https://cloud.google.com/spanner/
158-
[spanner-product-docs]: https://cloud.google.com/spanner/docs/
159-
[spanner-client-lib-docs]: https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/spanner/package-summary.html
169+
Apache 2.0 - See [LICENSE][license] for more information.
170+
171+
## CI Status
172+
173+
Java Version | Status
174+
------------ | ------
175+
Java 7 | [![Kokoro CI][kokoro-badge-image-1]][kokoro-badge-link-1]
176+
Java 8 | [![Kokoro CI][kokoro-badge-image-2]][kokoro-badge-link-2]
177+
Java 8 OSX | [![Kokoro CI][kokoro-badge-image-3]][kokoro-badge-link-3]
178+
Java 8 Windows | [![Kokoro CI][kokoro-badge-image-4]][kokoro-badge-link-4]
179+
Java 11 | [![Kokoro CI][kokoro-badge-image-5]][kokoro-badge-link-5]
180+
181+
[product-docs]: https://cloud.google.com/spanner/docs/
182+
[javadocs]: https://googleapis.dev/java/google-cloud-spanner/latest/
183+
[kokoro-badge-image-1]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java7.svg
184+
[kokoro-badge-link-1]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java7.html
185+
[kokoro-badge-image-2]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java8.svg
186+
[kokoro-badge-link-2]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java8.html
187+
[kokoro-badge-image-3]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java8-osx.svg
188+
[kokoro-badge-link-3]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java8-osx.html
189+
[kokoro-badge-image-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java8-win.svg
190+
[kokoro-badge-link-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java8-win.html
191+
[kokoro-badge-image-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.svg
192+
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
193+
[stability-image]: https://img.shields.io/badge/stability-ga-green
194+
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
195+
[maven-version-link]: https://search.maven.org/search?q=g:com.google.cloud%20AND%20a:google-cloud-spanner&core=gav
196+
[authentication]: https://.com/googleapis/google-cloud-java#authentication
197+
[developer-console]: https://console.developers.google.com/
198+
[create-project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects
199+
[cloud-sdk]: https://cloud.google.com/sdk/
200+
[troubleshooting]: https://.com/googleapis/google-cloud-common/blob/master/troubleshooting/readme.md#troubleshooting
201+
[contributing]: https://.com/googleapis/java-spanner/blob/master/CONTRIBUTING.md
202+
[code-of-conduct]: https://.com/googleapis/java-spanner/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct
203+
[license]: https://.com/googleapis/java-spanner/blob/master/LICENSE
204+
[enable-billing]: https://cloud.google.com/apis/docs/getting-started#enabling_billing
205+
[enable-api]: https://console.cloud.google.com/flows/enableapi?apiid=spanner.googleapis.com
206+
[libraries-bom]: https://.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM
207+
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"git": {
2020
"name": "synthtool",
2121
"remote": "https://.com/googleapis/synthtool.git",
22-
"sha": "52638600f387deb98efb5f9c85fec39e82aa9052"
22+
"sha": "716f741f2d307b48cbe8a5bc3bc883571212344a"
2323
}
2424
}
2525
],
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
java.format_code('proto-google-cloud-spanner-admin-instance-v1/src')
7777

7878
java.common_templates(excludes=[
79-
'README.md',
8079
'.kokoro/continuous/common.cfg',
8180
'.kokoro/nightly/common.cfg',
8281
'.kokoro/presubmit/common.cfg',

0 commit comments

Comments
 (0)