-
Notifications
You must be signed in to change notification settings - Fork 1.1k
spanner-jdbc: Step 01 - Create jdbc project #5805
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
olavloite
merged 2 commits into
googleapis:spanner-jdbc
from
olavloite:spanner-jdbc-01-create-project
Jul 23, 2019
Merged
Changes from all commits
Commits
Show all changes
2 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
124 changes: 124 additions & 0 deletions
124
google-cloud-clients/google-cloud-contrib/google-cloud-spanner-jdbc/README.md
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,124 @@ | ||
| #JDBC driver for Google Cloud Spanner | ||
|
|
||
| JDBC driver for | ||
| [Google Cloud Spanner](https://cloud.google.com/spanner/). | ||
|
|
||
| ## Quickstart | ||
|
|
||
| [//]: # ({x-version-update-start:google-cloud-spanner-jdbc:released}) | ||
| If you are using Maven, add this to your pom.xml file | ||
| ```xml | ||
| <dependency> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>google-cloud-spanner-jdbc</artifactId> | ||
| <version>0.1.0</version> | ||
| </dependency> | ||
| ``` | ||
| If you are using Gradle, add this to your dependencies | ||
| ```Groovy | ||
| compile 'com.google.cloud:google-cloud-spanner-jdbc:0.1.0' | ||
| ``` | ||
| If you are using SBT, add this to your dependencies | ||
| ```Scala | ||
| libraryDependencies += "com.google.cloud" % "google-cloud-spanner-jdbc" % "0.1.0" | ||
| ``` | ||
| [//]: # ({x-version-update-end}) | ||
|
|
||
| ## Getting Started | ||
| You can access Google Cloud Spanner through JDBC like this: | ||
|
|
||
| ```java | ||
| String url = "jdbc:cloudspanner:/projects/my_project_id/" | ||
| + "instances/my_instance_id/" | ||
| + "databases/my_database_name" | ||
| + "?credentials=/home/cloudspanner-keys/my-key.json" | ||
| + ";autocommit=false"; | ||
| try (Connection connection = DriverManager.getConnection(url)) { | ||
| try(ResultSet rs = connection.createStatement() | ||
| .executeQuery("SELECT SingerId, AlbumId, MarketingBudget FROM Albums")) { | ||
| while(rs.next()) { | ||
| Long singerId = rs.getLong(1); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Connection URL | ||
| The JDBC connection URL must be specified in the following format: | ||
|
|
||
| ``` | ||
| jdbc:cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\?property-name=property-value[;property-name=property-value]*]? | ||
| ``` | ||
|
|
||
| The property-value strings should be url-encoded. | ||
|
|
||
| The project-id part of the URI may be filled with the placeholder DEFAULT_PROJECT_ID. This | ||
| placeholder will be replaced by the default project id of the environment that is requesting a | ||
| connection. | ||
| The supported connection properties are: | ||
|
|
||
| * credentials (String): URL for the credentials file to use for the connection. If you do not specify any credentials, the default credentials of the environment as returned by {@link GoogleCredentials#getApplicationDefault()} will be used. | ||
| * autocommit (boolean): Sets the initial autocommit mode for the connection. Default is true. | ||
| * readonly (boolean): Sets the initial readonly mode for the connection. Default is false. | ||
| * retryAbortsInternally (boolean): Sets the initial retryAbortsInternally mode for the connection. Default is true. See | ||
| CloudSpannerJdbcConnection#setRetryAbortsInternally(boolean) for more information. | ||
|
|
||
| ### Authentication | ||
| The JDBC driver will either use the credentials that are specified in the connection URL, or if none specified, the default credentials of the environment. | ||
|
|
||
| See the | ||
| [Authentication](https://github.com/googleapis/google-cloud-java#authentication) | ||
| section in the base directory's README for more information. | ||
|
|
||
| ## Examples | ||
|
|
||
| The google-cloud-spanner-jdbc-examples project contains a number of examples on how to use the JDBC driver. These include: | ||
|
|
||
| * JdbcConnectExamples: Contains examples on how to obtain a JDBC connection for Cloud Spanner. | ||
| * JdbcAutocommitExamples: Contains examples on how to use a JDBC connection in autocommit mode. | ||
| * JdbcTransactionExamples: Contains examples on how to use the JDBC connection with read/write and read-only transactions. | ||
| * JdbcBatchExamples: Shows the batching capabilities of the Cloud Spanner JDBC driver. | ||
| * JdbcVariablesExamples: Shows how to use custom SQL statements to read and write variables from a JDBC connection. | ||
| * JdbcCustomMethodsExample: Shows how to use the custom methods that are exposed by the `com.google.cloud.spanner.jdbc.CloudSpannerJdbcConnection` interface. | ||
|
|
||
|
|
||
| ## Shaded JAR | ||
|
|
||
| You can build a shaded JAR of the JDBC driver to use with third-party tools using the following command: | ||
|
|
||
| ``` | ||
| mvn package -Pbuild-jdbc-driver | ||
| ``` | ||
|
|
||
| ## Java Versions | ||
|
|
||
| Java 7 or above is required for using this JDBC driver. | ||
|
|
||
| ## Versioning | ||
|
|
||
| This library follows [Semantic Versioning](http://semver.org/). | ||
|
|
||
| ## Contributing | ||
|
|
||
| Contributions to this library are always welcome and highly encouraged. | ||
|
|
||
| See `google-cloud`'s [CONTRIBUTING] documentation and the | ||
| [shared documentation](https://github.com/googleapis/google-cloud-common/blob/master/contributing/readme.md#how-to-contribute-to-gcloud) | ||
| for more information on how to get started. | ||
|
|
||
| Please note that this project is released with a Contributor Code of Conduct. | ||
| By participating in this project you agree to abide by its terms. See | ||
| [Code of Conduct][code-of-conduct] for more information. | ||
|
|
||
| ## License | ||
|
|
||
| Apache 2.0 - See [LICENSE] for more information. | ||
|
|
||
|
|
||
| [CONTRIBUTING]:https://github.com/googleapis/google-cloud-java/blob/master/CONTRIBUTING.md | ||
| [code-of-conduct]:https://github.com/googleapis/google-cloud-java/blob/master/CODE_OF_CONDUCT.md#contributor-code-of-conduct | ||
| [LICENSE]: https://github.com/googleapis/google-cloud-java/blob/master/LICENSE | ||
| [cloud-platform]: https://cloud.google.com/ | ||
|
|
||
| [cloud-spanner]: https://cloud.google.com/spanner/ | ||
| [cloud-spanner-docs]: https://cloud.google.com/spanner/docs/overview | ||
192 changes: 192 additions & 0 deletions
192
google-cloud-clients/google-cloud-contrib/google-cloud-spanner-jdbc/pom.xml
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,192 @@ | ||
| <?xml version="1.0"?> | ||
| <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> | ||
| <artifactId>google-cloud-spanner-jdbc</artifactId> | ||
| <version>0.1.0</version><!-- {x-version-update:google-cloud-spanner-jdbc:current} --> | ||
| <packaging>jar</packaging> | ||
| <name>Google Cloud Spanner JDBC</name> | ||
| <url>https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-contrib/google-cloud-spanner-jdbc</url> | ||
| <description> | ||
| JDBC driver for Google Cloud Spanner. | ||
| </description> | ||
| <parent> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>google-cloud-contrib</artifactId> | ||
| <version>0.101.0-alpha</version><!-- {x-version-update:google-cloud-contrib:current} --> | ||
| </parent> | ||
| <properties> | ||
| <site.installationModule>google-cloud-spanner-jdbc</site.installationModule> | ||
| </properties> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>google-cloud-spanner</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>google-cloud-storage</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>google-cloud-spanner</artifactId> | ||
| <version>1.28.0</version><!-- {x-version-update:google-cloud-spanner:current} --> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.api</groupId> | ||
| <artifactId>gax-grpc</artifactId> | ||
| <classifier>testlib</classifier> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.truth</groupId> | ||
| <artifactId>truth</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>1.9.5</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <version>2.5</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>test-jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>3.0.0-M3</version> | ||
| <configuration> | ||
| <excludedGroups>com.google.cloud.spanner.IntegrationTest,com.google.cloud.spanner.stresstest.StressTest</excludedGroups> | ||
| <reportNameSuffix>sponge_log</reportNameSuffix> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-failsafe-plugin</artifactId> | ||
| <version>3.0.0-M3</version> | ||
| <configuration> | ||
| <systemPropertyVariables> | ||
| <spanner.testenv.config.class>com.google.cloud.spanner.GceTestEnvConfig</spanner.testenv.config.class> | ||
| <spanner.testenv.instance>projects/gcloud-devel/instances/spanner-testing</spanner.testenv.instance> | ||
| </systemPropertyVariables> | ||
| <groups>com.google.cloud.spanner.IntegrationTest</groups> | ||
| <excludedGroups>com.google.cloud.spanner.FlakyTest,com.google.cloud.spanner.stresstest.StressTest</excludedGroups> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>integration-test</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <profiles> | ||
| <profile> | ||
| <!-- Profile for generating new sql test scripts. See ConnectionImplGeneratedSqlScriptTest | ||
| for more information. --> | ||
| <id>generate-test-sql-scripts</id> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>generateTestScripts</id> | ||
| <phase>compile</phase> | ||
| <goals> | ||
| <goal>java</goal> | ||
| </goals> | ||
| <configuration> | ||
| <mainClass>com.google.cloud.spanner.jdbc.SqlTestScriptsGenerator</mainClass> | ||
| <systemProperties> | ||
| <systemProperty> | ||
| <key>do_log_statements</key> | ||
| <value>true</value> | ||
| </systemProperty> | ||
| </systemProperties> | ||
| <classpathScope>test</classpathScope> | ||
| <skip>false</skip> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| <profile> | ||
| <!-- Profile for building a jar containing all dependencies and the | ||
| JDBC driver. This jar can then be used with third-party tools that support | ||
| generic JDBC drivers to connect to Cloud Spanner databases. --> | ||
| <id>build-jdbc-driver</id> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-shade-plugin</artifactId> | ||
| <version>3.2.1</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>shade</goal> | ||
| </goals> | ||
| <configuration> | ||
| <createSourcesJar>true</createSourcesJar> | ||
| <shadeSourcesContent>true</shadeSourcesContent> | ||
| <shadedArtifactAttached>false</shadedArtifactAttached> | ||
| <createDependencyReducedPom>false</createDependencyReducedPom> | ||
| <artifactSet> | ||
| <includes> | ||
| <include>*:*</include> | ||
| </includes> | ||
| <excludes> | ||
| <exclude>java:*</exclude> | ||
| <exclude>junit:*</exclude> | ||
| </excludes> | ||
| </artifactSet> | ||
| <transformers> | ||
| <transformer | ||
| implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> | ||
| <transformer | ||
| implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> | ||
| <resource>META-INF/services</resource> | ||
| <file>java.sql.Driver</file> | ||
| </transformer> | ||
| <transformer | ||
| implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> | ||
| <resource>com.google.cloud.spanner.jdbc</resource> | ||
| <file>ClientSideStatements.json</file> | ||
| </transformer> | ||
| <transformer | ||
| implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> | ||
| <resource>com.google.cloud.spanner.jdbc</resource> | ||
| <file>*.sql</file> | ||
| </transformer> | ||
| </transformers> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
| </project> |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for missing this - you can address this in the next commit, but this needs a space between the # and JDBC. Also, please capitalize Driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, NP.