Skip to content

Commit 4a697a9

Browse files
authored
* Update SQL 1. Use filtering to set variables. 2. Update README I was unable to get SQL proxy working so we can’t really do IT testing yet.
1 parent b9ee31d commit 4a697a9

File tree

3 files changed

+63
-25
lines changed

3 files changed

+63
-25
lines changed

appengine/cloudsql/README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# Cloud SQL sample for Google App Engine
22
This sample demonstrates how to use [Cloud SQL](https://cloud.google.com/sql/) on Google App Engine
3+
34
## Setup
4-
Before you can run or deploy the sample, you will need to create a [Cloud SQL instance](https://cloud.google.com/sql/docs/create-instance)
5-
1. Create a new user and database for the application. The easiest way to do this is via the [Google Developers Console](https://console.developers.google.com/project/_/sql/instances/example-instance2/access-control/users). Alternatively, you can use MySQL tools such as the command line client or workbench.
5+
Before you can run or deploy the sample, you will need to create a [Cloud SQL instance)](https://cloud.google.com/sql/docs/create-instance)
6+
7+
1. Create a new user and database for the application. The easiest way to do this is via the [Google
8+
Developers Console](https://console.developers.google.com/sql/instances). Alternatively, you can use MySQL tools such as the command line client or workbench.
9+
2. Change the root password (under Access Control) and / or create a new user / password.
10+
3. Create a Database (under Databases) (or use MySQL with `gcloud sql connect <instance> --user=root`)
11+
4. Note the **Instance connection name** under Overview > properties
12+
(It will look like project:instance for v1 or project:region:zone for v2)
13+
14+
## Deploying
15+
16+
`$ mvn clean appengine:deploy -DINSTANCE_CONNECTION_NAME="instanceConnectionName" -Duser=root
17+
-Dpassword=myPassword -Ddatabase=myDatabase`
18+
19+
Or you can update the properties in `pom.xml` and
20+
621
## Running locally
722
1. You will need to be running a local instance of MySQL.
8-
1. Update the connection string in ``appengine-web.xml`` with your local MySQL instance values.
9-
<br/>`$ mvn clean appengine:devserver`
1023

11-
## Deploying
12-
1. Update the connection string in ``appengine-web.xml`` with your Cloud SQL instance values.
13-
<br/>`$ mvn clean appengine:update`
24+
`$ mvn clean appengine:run -Duser=root -Dpassword=myPassowrd -Ddatabase=myDatabase`
25+

appengine/cloudsql/pom.xml

+42-14
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,69 @@
2727
<relativePath>../..</relativePath>
2828
</parent>
2929

30+
<!-- [START properties] -->
31+
<properties>
32+
<!-- INSTANCE_CONNECTION_NAME from Cloud Console > SQL > Instance Details > Properties
33+
or gcloud sql instances describe <instance>
34+
project:region:instance for Cloud SQL v2 or
35+
project:instance for Cloud SQL v1
36+
-->
37+
<INSTANCE_CONNECTION_NAME></INSTANCE_CONNECTION_NAME>
38+
<user>root</user>
39+
<password></password>
40+
<database></database>
41+
42+
<!-- [START_EXCLUDE] -->
43+
<appengine.maven.plugin>1.0.0</appengine.maven.plugin>
44+
<maven.compiler.target>1.7</maven.compiler.target>
45+
<maven.compiler.source>1.7</maven.compiler.source>
46+
<!-- [END_EXCLUDE] -->
47+
</properties>
48+
<!-- [END properties] -->
3049
<dependencies>
31-
<dependency>
32-
<groupId>com.google.cloud.sql</groupId>
33-
<artifactId>mysql-socket-factory</artifactId>
34-
<version>1.0.2</version>
35-
</dependency>
3650
<dependency>
3751
<groupId>javax.servlet</groupId>
38-
<artifactId>javax.servlet-api</artifactId>
39-
<version>3.1.0</version>
40-
<type>jar</type>
52+
<artifactId>servlet-api</artifactId>
53+
<version>2.5</version>
4154
<scope>provided</scope>
4255
</dependency>
43-
<!-- [START dependencies] -->
44-
<dependency>
45-
<groupId>mysql</groupId>
46-
<artifactId>mysql-connector-java</artifactId>
47-
<version>6.0.5</version>
48-
</dependency>
56+
4957
<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
5058
<dependency>
5159
<groupId>com.google.appengine</groupId>
5260
<artifactId>appengine-api-1.0-sdk</artifactId>
5361
</dependency>
62+
63+
<!-- [START dependencies] -->
64+
<dependency> <!-- ONLY USED LOCALY -->
65+
<groupId>mysql</groupId>
66+
<artifactId>mysql-connector-java</artifactId>
67+
<version>5.1.40</version> <!-- v5.x.x is Java 7, v6.x.x is Java 8 -->
68+
</dependency>
5469
<!-- [END dependencies] -->
5570
</dependencies>
5671
<build>
5772
<!-- for hot reload of the web application -->
5873
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
74+
<resources>
75+
<resource>
76+
<directory>src/webapp/WEB-INF</directory>
77+
<filtering>true</filtering>
78+
</resource>
79+
</resources>
5980
<plugins>
81+
<plugin>
82+
<groupId>com.google.cloud.tools</groupId>
83+
<artifactId>appengine-maven-plugin</artifactId>
84+
<version>${appengine.maven.plugin}</version>
85+
</plugin>
86+
<!--
6087
<plugin>
6188
<groupId>com.google.appengine</groupId>
6289
<artifactId>appengine-maven-plugin</artifactId>
6390
<version>${appengine.sdk.version}</version>
6491
</plugin>
92+
-->
6593
</plugins>
6694
</build>
6795
</project>

appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
-->
1414
<!-- [START config] -->
1515
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
16-
<application>YOUR-PROJECT-ID</application>
17-
<version>YOUR-VERSION-ID</version>
1816
<threadsafe>true</threadsafe>
1917
<use-google-connector-j>true</use-google-connector-j>
2018
<system-properties>
21-
<property name="ae-cloudsql.cloudsql-database-url" value="jdbc:google:mysql://[INSTANCE_CONNECTION_NAME]/DATABASE-NAME?user=USERNAME&amp;password=PASSWORD" />
22-
<property name="ae-cloudsql.local-database-url" value="jdbc:mysql://localhost/DATABASE-NAME?user=USERNAME&amp;PASSWORD=password&amp;useSSL=false" />
19+
<property name="ae-cloudsql.cloudsql-database-url" value="jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&amp;password=${password}" />
20+
<property name="ae-cloudsql.local-database-url" value="jdbc:mysql://localhost/${database}?user=${user}&amp;PASSWORD=${password}&amp;useSSL=false" />
2321
</system-properties>
2422
</appengine-web-app>
2523
<!-- [END config] -->

0 commit comments

Comments
 (0)