From 35b06b02c6abf982ae61d8f515ed3d326352699b Mon Sep 17 00:00:00 2001 From: Simon Zhao Date: Fri, 19 Nov 2021 17:18:20 -0800 Subject: [PATCH 1/4] Report driver version in metadata --- .../neptune/gremlin/GremlinConnection.java | 2 +- .../gremlin/sql/SqlGremlinConnection.java | 2 +- .../software/aws/neptune/jdbc/Driver.java | 33 +++++++++++++++---- .../opencypher/OpenCypherConnection.java | 2 +- .../aws/neptune/sparql/SparqlConnection.java | 2 +- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java b/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java index 96437ce7..1e1a5314 100644 --- a/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java +++ b/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java @@ -59,6 +59,6 @@ public QueryExecutor getQueryExecutor() throws SQLException { @Override public String getDriverName() { - return "neptune:gremlin"; + return "Neptune:Gremlin"; } } diff --git a/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java b/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java index f252111b..6cbf0713 100644 --- a/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java +++ b/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java @@ -53,6 +53,6 @@ public QueryExecutor getQueryExecutor() throws SQLException { @Override public String getDriverName() { - return "neptune:sqlgremlin"; + return "Neptune:SQL-Gremlin"; } } diff --git a/src/main/java/software/aws/neptune/jdbc/Driver.java b/src/main/java/software/aws/neptune/jdbc/Driver.java index 56b3c6af..5275dcbe 100644 --- a/src/main/java/software/aws/neptune/jdbc/Driver.java +++ b/src/main/java/software/aws/neptune/jdbc/Driver.java @@ -20,6 +20,8 @@ import software.aws.neptune.jdbc.utilities.SqlError; import software.aws.neptune.jdbc.utilities.SqlState; import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.nio.charset.StandardCharsets; @@ -39,15 +41,33 @@ public abstract class Driver implements java.sql.Driver { public static final String DRIVER_VERSION; public static final String APP_NAME_SUFFIX; public static final String APPLICATION_NAME; + private static final String PROPERTIES_PATH = "/project.properties"; + private static final String MAJOR_VERSION_KEY = "driver.major.version"; + private static final String MINOR_VERSION_KEY = "driver.minor.version"; + private static final String VERSION_KEY = "driver.full.version"; private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Driver.class); static { APPLICATION_NAME = getApplicationName(); - // TODO: Get driver version, suffix - DRIVER_MAJOR_VERSION = 1; - DRIVER_MINOR_VERSION = 1; + // TODO: suffix APP_NAME_SUFFIX = "TODO"; - DRIVER_VERSION = "0.0.0"; + + int majorVersion = 0; + int minorVersion = 0; + String version = ""; + try (InputStream input = Driver.class.getResourceAsStream(PROPERTIES_PATH)) { + final Properties properties = new Properties(); + properties.load(input); + majorVersion = Integer.parseInt(properties.getProperty(MAJOR_VERSION_KEY)); + minorVersion = Integer.parseInt(properties.getProperty(MINOR_VERSION_KEY)); + version = properties.getProperty(VERSION_KEY); + } catch (IOException e) { + LOGGER.error("Error loading driver version: ", e); + } + + DRIVER_MAJOR_VERSION = majorVersion; + DRIVER_MINOR_VERSION = minorVersion; + DRIVER_VERSION = version; } /** @@ -101,15 +121,14 @@ public java.sql.DriverPropertyInfo[] getPropertyInfo(final String url, final Pro return new java.sql.DriverPropertyInfo[0]; } - // TODO: Fix functions below. @Override public int getMajorVersion() { - return 0; + return DRIVER_MAJOR_VERSION; } @Override public int getMinorVersion() { - return 0; + return DRIVER_MINOR_VERSION; } @Override diff --git a/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java b/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java index 4d60a680..c0587ee7 100644 --- a/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java +++ b/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java @@ -59,6 +59,6 @@ public QueryExecutor getQueryExecutor() throws SQLException { @Override public String getDriverName() { - return "neptune:opencypher"; + return "Neptune:openCypher"; } } diff --git a/src/main/java/software/aws/neptune/sparql/SparqlConnection.java b/src/main/java/software/aws/neptune/sparql/SparqlConnection.java index e2204e2f..395b482a 100644 --- a/src/main/java/software/aws/neptune/sparql/SparqlConnection.java +++ b/src/main/java/software/aws/neptune/sparql/SparqlConnection.java @@ -56,6 +56,6 @@ public QueryExecutor getQueryExecutor() throws SQLException { @Override public String getDriverName() { - return "neptune:sparql"; + return "Neptune:SPARQL"; } } From 24bdad7dbe9bde734e1f66d1be42099def60bafb Mon Sep 17 00:00:00 2001 From: Simon Zhao Date: Fri, 19 Nov 2021 18:09:45 -0800 Subject: [PATCH 2/4] Use "full version" instead of "version" --- .../software/aws/neptune/jdbc/DatabaseMetaData.java | 2 +- src/main/java/software/aws/neptune/jdbc/Driver.java | 10 +++++----- .../aws/neptune/jdbc/DatabaseMetaDataTest.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/software/aws/neptune/jdbc/DatabaseMetaData.java b/src/main/java/software/aws/neptune/jdbc/DatabaseMetaData.java index ec6f8ad8..81cfbc88 100644 --- a/src/main/java/software/aws/neptune/jdbc/DatabaseMetaData.java +++ b/src/main/java/software/aws/neptune/jdbc/DatabaseMetaData.java @@ -78,7 +78,7 @@ public int getDriverMinorVersion() { @Override public String getDriverVersion() { - return Driver.DRIVER_VERSION; + return Driver.DRIVER_FULL_VERSION; } @Override diff --git a/src/main/java/software/aws/neptune/jdbc/Driver.java b/src/main/java/software/aws/neptune/jdbc/Driver.java index 5275dcbe..dbd2bc67 100644 --- a/src/main/java/software/aws/neptune/jdbc/Driver.java +++ b/src/main/java/software/aws/neptune/jdbc/Driver.java @@ -38,13 +38,13 @@ public abstract class Driver implements java.sql.Driver { public static final int DRIVER_MAJOR_VERSION; public static final int DRIVER_MINOR_VERSION; - public static final String DRIVER_VERSION; + public static final String DRIVER_FULL_VERSION; public static final String APP_NAME_SUFFIX; public static final String APPLICATION_NAME; private static final String PROPERTIES_PATH = "/project.properties"; private static final String MAJOR_VERSION_KEY = "driver.major.version"; private static final String MINOR_VERSION_KEY = "driver.minor.version"; - private static final String VERSION_KEY = "driver.full.version"; + private static final String FULL_VERSION_KEY = "driver.full.version"; private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Driver.class); static { @@ -54,20 +54,20 @@ public abstract class Driver implements java.sql.Driver { int majorVersion = 0; int minorVersion = 0; - String version = ""; + String fullVersion = ""; try (InputStream input = Driver.class.getResourceAsStream(PROPERTIES_PATH)) { final Properties properties = new Properties(); properties.load(input); majorVersion = Integer.parseInt(properties.getProperty(MAJOR_VERSION_KEY)); minorVersion = Integer.parseInt(properties.getProperty(MINOR_VERSION_KEY)); - version = properties.getProperty(VERSION_KEY); + fullVersion = properties.getProperty(FULL_VERSION_KEY); } catch (IOException e) { LOGGER.error("Error loading driver version: ", e); } DRIVER_MAJOR_VERSION = majorVersion; DRIVER_MINOR_VERSION = minorVersion; - DRIVER_VERSION = version; + DRIVER_FULL_VERSION = fullVersion; } /** diff --git a/src/test/java/software/aws/neptune/jdbc/DatabaseMetaDataTest.java b/src/test/java/software/aws/neptune/jdbc/DatabaseMetaDataTest.java index b48d561f..8ba1a24d 100644 --- a/src/test/java/software/aws/neptune/jdbc/DatabaseMetaDataTest.java +++ b/src/test/java/software/aws/neptune/jdbc/DatabaseMetaDataTest.java @@ -192,7 +192,7 @@ void testDriverVersion() { .expectFunctionDoesntThrow(() -> databaseMetaData.getDriverMajorVersion(), Driver.DRIVER_MAJOR_VERSION); HelperFunctions .expectFunctionDoesntThrow(() -> databaseMetaData.getDriverMinorVersion(), Driver.DRIVER_MINOR_VERSION); - HelperFunctions.expectFunctionDoesntThrow(() -> databaseMetaData.getDriverVersion(), Driver.DRIVER_VERSION); + HelperFunctions.expectFunctionDoesntThrow(() -> databaseMetaData.getDriverVersion(), Driver.DRIVER_FULL_VERSION); } @Test From a5f6a8eee96d2c35ecd60a67e481886ff30bf649 Mon Sep 17 00:00:00 2001 From: Simon Zhao Date: Mon, 22 Nov 2021 11:17:02 -0800 Subject: [PATCH 3/4] Consolidate getDriverName --- .../java/software/aws/neptune/NeptuneDatabaseMetadata.java | 6 ++---- .../software/aws/neptune/gremlin/GremlinConnection.java | 5 ----- .../aws/neptune/gremlin/sql/SqlGremlinConnection.java | 5 ----- src/main/java/software/aws/neptune/jdbc/Connection.java | 7 ------- src/main/java/software/aws/neptune/jdbc/Driver.java | 3 --- .../aws/neptune/opencypher/OpenCypherConnection.java | 5 ----- .../java/software/aws/neptune/sparql/SparqlConnection.java | 5 ----- .../software/aws/neptune/jdbc/mock/MockConnection.java | 5 ----- 8 files changed, 2 insertions(+), 39 deletions(-) diff --git a/src/main/java/software/aws/neptune/NeptuneDatabaseMetadata.java b/src/main/java/software/aws/neptune/NeptuneDatabaseMetadata.java index 46ff7306..50d7ed41 100644 --- a/src/main/java/software/aws/neptune/NeptuneDatabaseMetadata.java +++ b/src/main/java/software/aws/neptune/NeptuneDatabaseMetadata.java @@ -16,12 +16,11 @@ package software.aws.neptune; -import software.aws.neptune.jdbc.Connection; import software.aws.neptune.jdbc.DatabaseMetaData; import java.sql.SQLException; public class NeptuneDatabaseMetadata extends DatabaseMetaData implements java.sql.DatabaseMetaData { - private final Connection connection; + private static final String DRIVER_NAME = "Amazon Neptune JDBC"; /** * NeptuneDatabaseMetadata constructor, initializes super class. @@ -30,7 +29,6 @@ public class NeptuneDatabaseMetadata extends DatabaseMetaData implements java.sq */ public NeptuneDatabaseMetadata(final java.sql.Connection connection) { super(connection); - this.connection = (Connection) connection; } @Override @@ -55,6 +53,6 @@ public String getCatalogSeparator() throws SQLException { @Override public String getDriverName() { - return connection.getDriverName(); + return DRIVER_NAME; } } diff --git a/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java b/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java index 1e1a5314..5f4f9ea0 100644 --- a/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java +++ b/src/main/java/software/aws/neptune/gremlin/GremlinConnection.java @@ -56,9 +56,4 @@ public DatabaseMetaData getMetaData() { public QueryExecutor getQueryExecutor() throws SQLException { return new GremlinQueryExecutor(getGremlinConnectionProperties()); } - - @Override - public String getDriverName() { - return "Neptune:Gremlin"; - } } diff --git a/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java b/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java index 6cbf0713..a7d97a48 100644 --- a/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java +++ b/src/main/java/software/aws/neptune/gremlin/sql/SqlGremlinConnection.java @@ -50,9 +50,4 @@ public DatabaseMetaData getMetaData() { public QueryExecutor getQueryExecutor() throws SQLException { return new SqlGremlinQueryExecutor(getGremlinConnectionProperties()); } - - @Override - public String getDriverName() { - return "Neptune:SQL-Gremlin"; - } } diff --git a/src/main/java/software/aws/neptune/jdbc/Connection.java b/src/main/java/software/aws/neptune/jdbc/Connection.java index fe3ab24f..8e37e4a6 100644 --- a/src/main/java/software/aws/neptune/jdbc/Connection.java +++ b/src/main/java/software/aws/neptune/jdbc/Connection.java @@ -71,13 +71,6 @@ protected Connection(@NonNull final ConnectionProperties connectionProperties) t */ public abstract QueryExecutor getQueryExecutor() throws SQLException; - /** - * Function to get Driver name as a String. - * - * @return Driver name as String. - */ - public abstract String getDriverName(); - protected ConnectionProperties getConnectionProperties() { return this.connectionProperties; } diff --git a/src/main/java/software/aws/neptune/jdbc/Driver.java b/src/main/java/software/aws/neptune/jdbc/Driver.java index dbd2bc67..ae74161c 100644 --- a/src/main/java/software/aws/neptune/jdbc/Driver.java +++ b/src/main/java/software/aws/neptune/jdbc/Driver.java @@ -39,7 +39,6 @@ public abstract class Driver implements java.sql.Driver { public static final int DRIVER_MAJOR_VERSION; public static final int DRIVER_MINOR_VERSION; public static final String DRIVER_FULL_VERSION; - public static final String APP_NAME_SUFFIX; public static final String APPLICATION_NAME; private static final String PROPERTIES_PATH = "/project.properties"; private static final String MAJOR_VERSION_KEY = "driver.major.version"; @@ -49,8 +48,6 @@ public abstract class Driver implements java.sql.Driver { static { APPLICATION_NAME = getApplicationName(); - // TODO: suffix - APP_NAME_SUFFIX = "TODO"; int majorVersion = 0; int minorVersion = 0; diff --git a/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java b/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java index c0587ee7..4195e92e 100644 --- a/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java +++ b/src/main/java/software/aws/neptune/opencypher/OpenCypherConnection.java @@ -56,9 +56,4 @@ public DatabaseMetaData getMetaData() { public QueryExecutor getQueryExecutor() throws SQLException { return new OpenCypherQueryExecutor(getOpenCypherConnectionProperties()); } - - @Override - public String getDriverName() { - return "Neptune:openCypher"; - } } diff --git a/src/main/java/software/aws/neptune/sparql/SparqlConnection.java b/src/main/java/software/aws/neptune/sparql/SparqlConnection.java index 395b482a..025291ef 100644 --- a/src/main/java/software/aws/neptune/sparql/SparqlConnection.java +++ b/src/main/java/software/aws/neptune/sparql/SparqlConnection.java @@ -53,9 +53,4 @@ public DatabaseMetaData getMetaData() throws SQLException { public QueryExecutor getQueryExecutor() throws SQLException { return new SparqlQueryExecutor(getSparqlConnectionProperties()); } - - @Override - public String getDriverName() { - return "Neptune:SPARQL"; - } } diff --git a/src/test/java/software/aws/neptune/jdbc/mock/MockConnection.java b/src/test/java/software/aws/neptune/jdbc/mock/MockConnection.java index fcf7300e..bc1d111b 100644 --- a/src/test/java/software/aws/neptune/jdbc/mock/MockConnection.java +++ b/src/test/java/software/aws/neptune/jdbc/mock/MockConnection.java @@ -43,11 +43,6 @@ public QueryExecutor getQueryExecutor() { return new MockQueryExecutor(); } - @Override - public String getDriverName() { - return "neptune:mock"; - } - @Override protected void doClose() { } From bba08c955b86826f8692b65c7a26b62d2bd33d5d Mon Sep 17 00:00:00 2001 From: Simon Zhao Date: Mon, 22 Nov 2021 11:57:36 -0800 Subject: [PATCH 4/4] Add unit test --- .../software/aws/neptune/jdbc/Driver.java | 3 +-- .../aws/neptune/NeptuneDriverTestBase.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/software/aws/neptune/jdbc/Driver.java b/src/main/java/software/aws/neptune/jdbc/Driver.java index ae74161c..4258e14f 100644 --- a/src/main/java/software/aws/neptune/jdbc/Driver.java +++ b/src/main/java/software/aws/neptune/jdbc/Driver.java @@ -47,8 +47,6 @@ public abstract class Driver implements java.sql.Driver { private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Driver.class); static { - APPLICATION_NAME = getApplicationName(); - int majorVersion = 0; int minorVersion = 0; String fullVersion = ""; @@ -65,6 +63,7 @@ public abstract class Driver implements java.sql.Driver { DRIVER_MAJOR_VERSION = majorVersion; DRIVER_MINOR_VERSION = minorVersion; DRIVER_FULL_VERSION = fullVersion; + APPLICATION_NAME = getApplicationName(); } /** diff --git a/src/test/java/software/aws/neptune/NeptuneDriverTestBase.java b/src/test/java/software/aws/neptune/NeptuneDriverTestBase.java index 09f5087a..a999f220 100644 --- a/src/test/java/software/aws/neptune/NeptuneDriverTestBase.java +++ b/src/test/java/software/aws/neptune/NeptuneDriverTestBase.java @@ -19,11 +19,15 @@ import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import software.aws.neptune.jdbc.Driver; import software.aws.neptune.jdbc.helpers.HelperFunctions; import software.aws.neptune.jdbc.utilities.AuthScheme; import software.aws.neptune.jdbc.utilities.SqlError; import software.aws.neptune.opencypher.OpenCypherConnection; import software.aws.neptune.opencypher.mock.MockOpenCypherDatabase; + +import java.io.IOException; +import java.io.InputStream; import java.sql.DriverManager; import java.sql.SQLException; import java.util.List; @@ -32,6 +36,10 @@ public abstract class NeptuneDriverTestBase { private static MockOpenCypherDatabase database; private static String validEndpoint; + private static final String PROPERTIES_PATH = "/project.properties"; + private static final String MAJOR_VERSION_KEY = "driver.major.version"; + private static final String MINOR_VERSION_KEY = "driver.minor.version"; + private static final String FULL_VERSION_KEY = "driver.full.version"; private final List invalidUrls = ImmutableList.of( "jbdc:neptune:opencyher://;", "jdbc:netune:opencyher://;", "jdbc:neptune:openyher://;", "jdbc:neptune:opencyher//;", "jdbc:neptune:opencypher:/"); @@ -136,4 +144,20 @@ void testDriverManagerGetDriver(final boolean useEncryption) throws SQLException void testDriverProperties() { HelperFunctions.expectFunctionThrows(SqlError.FEATURE_NOT_SUPPORTED, () -> driver.getParentLogger()); } + + @Test + void testDriverVersion() { + try (InputStream input = Driver.class.getResourceAsStream(PROPERTIES_PATH)) { + final Properties properties = new Properties(); + properties.load(input); + Assertions.assertEquals(driver.getMajorVersion(), Integer.parseInt(properties.getProperty(MAJOR_VERSION_KEY))); + Assertions.assertEquals(driver.getMinorVersion(), Integer.parseInt(properties.getProperty(MINOR_VERSION_KEY))); + + // Ensure the version did not default + Assertions.assertNotEquals(driver.getMajorVersion(), 0); + Assertions.assertTrue(properties.containsKey(FULL_VERSION_KEY)); + } catch (IOException e) { + Assertions.fail(e.getMessage()); + } + } }