Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public JdbcDriver() {}

@Override
public Connection connect(String url, Properties info) throws SQLException {
if (url != null && url.startsWith("jdbc:cloudspanner")) {
if (url != null && (url.startsWith("jdbc:cloudspanner") || url.startsWith("jdbc:spanner"))) {
try {
Matcher matcher = URL_PATTERN.matcher(url);
Matcher matcherExternalHost = EXTERNAL_HOST_URL_PATTERN.matcher(url);
Expand Down Expand Up @@ -271,7 +271,7 @@ private String appendPropertiesToUrl(String url, Properties info) {

@Override
public boolean acceptsURL(String url) {
return URL_PATTERN.matcher(url).matches();
return URL_PATTERN.matcher(url).matches() || EXTERNAL_HOST_URL_PATTERN.matcher(url).matches();
}

@Override
Expand Down
26 changes: 19 additions & 7 deletions src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@ public void testRegister() throws SQLException {

@Test
public void testConnect() throws SQLException {
try (Connection connection =
DriverManager.getConnection(
String.format(
"jdbc:cloudspanner://localhost:%d/projects/some-company.com:test-project/instances/static-test-instance/databases/test-database;usePlainText=true;credentials=%s",
server.getPort(), TEST_KEY_PATH))) {
assertThat(connection.isClosed()).isFalse();
}
for (String prefix : new String[] {"cloudspanner", "spanner"})
try (Connection connection =
DriverManager.getConnection(
String.format(
"jdbc:%s://localhost:%d/projects/some-company.com:test-project/instances/static-test-instance/databases/test-database;usePlainText=true;credentials=%s",
prefix, server.getPort(), TEST_KEY_PATH))) {
assertThat(connection.isClosed()).isFalse();
}
}

@Test(expected = SQLException.class)
Expand Down Expand Up @@ -215,6 +216,17 @@ public void testLenient() throws SQLException {
}
}

@Test
public void testAcceptsURL() throws SQLException {
JdbcDriver driver = JdbcDriver.getRegisteredDriver();
assertTrue(
driver.acceptsURL(
"jdbc:cloudspanner:/projects/my-project/instances/my-instance/databases/my-database"));
assertTrue(
driver.acceptsURL(
"jdbc:spanner:/projects/my-project/instances/my-instance/databases/my-database"));
}

@Test
public void testJdbcExternalHostFormat() {
Matcher matcherWithoutInstance =
Expand Down