Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ public class JdbcDriver implements Driver {
private static final String JDBC_URL_FORMAT =
"jdbc:" + ConnectionOptions.Builder.SPANNER_URI_FORMAT;
private static final Pattern URL_PATTERN = Pattern.compile(JDBC_URL_FORMAT);
private static final String JDBC_EXTERNAL_HOST_FORMAT =
"jdbc:" + ConnectionOptions.Builder.EXTERNAL_HOST_FORMAT;
private static final String JDBC_SPANNER_OMNI_FORMAT =
"jdbc:" + ConnectionOptions.Builder.SPANNER_OMNI_FORMAT;

@VisibleForTesting
static final Pattern EXTERNAL_HOST_URL_PATTERN = Pattern.compile(JDBC_EXTERNAL_HOST_FORMAT);
static final Pattern SPANNER_OMNI_URL_PATTERN = Pattern.compile(JDBC_SPANNER_OMNI_FORMAT);

@InternalApi
public static String getClientLibToken() {
Expand Down Expand Up @@ -222,8 +222,8 @@ public Connection connect(String url, Properties info) throws SQLException {
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);
if (matcher.matches() || matcherExternalHost.matches()) {
Matcher matcherSpannerOmni = SPANNER_OMNI_URL_PATTERN.matcher(url);
if (matcher.matches() || matcherSpannerOmni.matches()) {
// strip 'jdbc:' from the URL, add any extra properties and pass on to the generic
// Connection API. Also set the user-agent if we detect that the connection
// comes from known framework like Hibernate, and there is no other user-agent set.
Expand Down Expand Up @@ -320,7 +320,7 @@ static String appendPropertiesToUrl(String url, Properties info) {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.cloud.spanner.jdbc;

import static com.google.cloud.spanner.jdbc.JdbcDriver.EXTERNAL_HOST_URL_PATTERN;
import static com.google.cloud.spanner.jdbc.JdbcDriver.SPANNER_OMNI_URL_PATTERN;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -227,29 +227,29 @@ public void testAcceptsURL() throws SQLException {
}

@Test
public void testJdbcExternalHostFormat() {
public void testJdbcSpannerOmniFormat() {
Matcher matcherWithoutInstance =
EXTERNAL_HOST_URL_PATTERN.matcher("jdbc:cloudspanner://localhost:15000/databases/test-db");
SPANNER_OMNI_URL_PATTERN.matcher("jdbc:cloudspanner://localhost:15000/databases/test-db");
Comment thread
sagnghos marked this conversation as resolved.
assertTrue(matcherWithoutInstance.matches());
assertEquals("test-db", matcherWithoutInstance.group("DATABASEGROUP"));
Matcher matcherWithProperty =
EXTERNAL_HOST_URL_PATTERN.matcher(
SPANNER_OMNI_URL_PATTERN.matcher(
"jdbc:cloudspanner://localhost:15000/instances/default/databases/singers-db?usePlainText=true");
assertTrue(matcherWithProperty.matches());
assertEquals("default", matcherWithProperty.group("INSTANCEGROUP"));
assertEquals("singers-db", matcherWithProperty.group("DATABASEGROUP"));
Matcher matcherWithoutPort =
EXTERNAL_HOST_URL_PATTERN.matcher(
SPANNER_OMNI_URL_PATTERN.matcher(
"jdbc:cloudspanner://localhost/instances/default/databases/test-db");
assertTrue(matcherWithoutPort.matches());
assertEquals("default", matcherWithoutPort.group("INSTANCEGROUP"));
assertEquals("test-db", matcherWithoutPort.group("DATABASEGROUP"));
Matcher matcherWithProject =
EXTERNAL_HOST_URL_PATTERN.matcher(
SPANNER_OMNI_URL_PATTERN.matcher(
"jdbc:cloudspanner://localhost:15000/projects/default/instances/default/databases/singers-db");
assertFalse(matcherWithProject.matches());
Matcher matcherWithoutHost =
EXTERNAL_HOST_URL_PATTERN.matcher(
SPANNER_OMNI_URL_PATTERN.matcher(
"jdbc:cloudspanner:/instances/default/databases/singers-db");
assertFalse(matcherWithoutHost.matches());
}
Expand Down
Loading