-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add Spanner Leaderboard sample. #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Java Cloud Spanner Sample Leaderboard Application | ||
|
||
A leaderboard sample that uses the Cloud Spanner commit timestamp feature and demonstrates | ||
how to call the [Google Cloud Spanner API](https://cloud.google.com/spanner/docs/) | ||
using the [Google Cloud Client Library for Java](https://github.com/GoogleCloudPlatform/google-cloud-java). | ||
|
||
This sample requires [Java](https://www.java.com/en/download/) and [Maven](http://maven.apache.org/) for building the application. | ||
|
||
This sample includes extra directories `step5`, `step6`, and `step7` that contain partial versions of this sample application. These directories are intended to provide guidance as part of a separate Codelab walk-through where the application is built in the following stages | ||
that correspond to the steps in Codelab: | ||
|
||
* step5 - Create the sample database along with the tables Players and Scores. | ||
* step6 - Populate the Players and Scores tables with sample data. | ||
* step7 - Run sample queries including sorting the results by timestamp. | ||
|
||
If you only want to run the complete sample refer to the application in the `complete` directory. | ||
|
||
|
||
## Build and Run | ||
|
||
1. **Follow the set-up instructions in [the documentation](https://cloud.google.com/java/docs/setup).** | ||
|
||
2. Enable APIs for your project. | ||
[Click here](https://console.cloud.google.com/flows/enableapi?apiid=spanner.googleapis.com&showconfirmation=true) | ||
to visit Cloud Platform Console and enable the Google Cloud Spanner API. | ||
|
||
3. Create a Cloud Spanner instance via the Cloud Plaform Console's | ||
[Cloud Spanner section](http://console.cloud.google.com/spanner). | ||
|
||
4. In a terminal shell, change directory to the version of the application you want to run: | ||
``` | ||
cd complete | ||
``` | ||
|
||
5. Run the following Maven command to build the application: | ||
``` | ||
mvn install -DskipTests | ||
``` | ||
|
||
6. Change directory into the `target` directory where the application's jar file gets built to. | ||
``` | ||
cd target | ||
``` | ||
|
||
|
||
7. Run the Spanner Leaderboard sample with `java -jar leaderboard.jar` to see a list of available commands: | ||
``` | ||
@shell:~/.../target$ java -jar leaderboard.jar | ||
|
||
Leaderboard 1.0.0 | ||
Usage: | ||
java -jar leaderboard.jar <command> <instance_id> <database_id> [command_option] | ||
|
||
Examples: | ||
java -jar leaderboard.jar create my-instance example-db | ||
- Create a sample Cloud Spanner database along with sample tables in your project. | ||
|
||
java -jar leaderboard.jar insert my-instance example-db players | ||
- Insert 100 sample Player records into the database. | ||
|
||
java -jar leaderboard.jar insert my-instance example-db scores | ||
- Insert sample score data into Scores sample Cloud Spanner database table. | ||
|
||
java -jar leaderboard.jar query my-instance example-db | ||
- Query players with top ten scores of all time. | ||
|
||
java -jar leaderboard.jar query my-instance example-db 168 | ||
- Query players with top ten scores within a timespan specified in hours. | ||
|
||
java -jar leaderboard.jar delete my-instance example-db | ||
- Delete sample Cloud Spanner database. | ||
``` | ||
|
||
``` | ||
$ java -jar leaderboard.jar create my-instance my-database | ||
Created database [projects/arc-nl/instances/my-instance/databases/my-database] | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.google.codelabs</groupId> | ||
kurtisvg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<artifactId>leaderboard</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>leaderboard</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<!-- | ||
The parent pom defines common style checks and testing strategies for our samples. | ||
Removing or replacing it should not affect the execution of the samples in anyway. | ||
--> | ||
<parent> | ||
<groupId>com.google.cloud.samples</groupId> | ||
<artifactId>shared-configuration</artifactId> | ||
<version>1.0.10</version> | ||
</parent> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-bom</artifactId> | ||
<version>0.73.0-alpha</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<!-- Version auto-managed by BOM --> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-spanner</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13-beta-2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.truth</groupId> | ||
<artifactId>truth</artifactId> | ||
<version>0.42</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>2.5.5</version> | ||
<configuration> | ||
<finalName>leaderboard</finalName> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.google.codelabs.App</mainClass> | ||
</manifest> | ||
</archive> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<attach>false</attach> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>3.0.0-M3</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.0.0-M3</version> | ||
<configuration> | ||
<useSystemClassLoader>false</useSystemClassLoader> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.