From 87ecbb7c3b1d109d6cfb65e77b678e822b939c0f Mon Sep 17 00:00:00 2001 From: Eugene R Date: Wed, 20 Dec 2023 10:55:32 +0200 Subject: [PATCH] FMWK-289 Return JDBC version 4.2 in metadata (#60) * FMWK-289 Return JDBC version 4.2 in metadata * return proper driver versions --- .../jdbc/AerospikeDatabaseMetadata.java | 15 ++++++++---- .../com/aerospike/jdbc/AerospikeDriver.java | 6 +++-- .../com/aerospike/jdbc/util/Constants.java | 10 ++++++++ .../aerospike/jdbc/DatabaseMetadataTest.java | 23 ++++++++++++------- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/aerospike/jdbc/AerospikeDatabaseMetadata.java b/src/main/java/com/aerospike/jdbc/AerospikeDatabaseMetadata.java index 2477bfa..c509550 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikeDatabaseMetadata.java +++ b/src/main/java/com/aerospike/jdbc/AerospikeDatabaseMetadata.java @@ -30,6 +30,11 @@ import static com.aerospike.jdbc.util.AerospikeUtils.getCatalogIndexes; import static com.aerospike.jdbc.util.AerospikeUtils.getClusterInfo; +import static com.aerospike.jdbc.util.Constants.DRIVER_MAJOR_VERSION; +import static com.aerospike.jdbc.util.Constants.DRIVER_MINOR_VERSION; +import static com.aerospike.jdbc.util.Constants.DRIVER_VERSION; +import static com.aerospike.jdbc.util.Constants.JDBC_MAJOR_VERSION; +import static com.aerospike.jdbc.util.Constants.JDBC_MINOR_VERSION; import static com.aerospike.jdbc.util.Constants.PRIMARY_KEY_COLUMN_NAME; import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; @@ -155,17 +160,17 @@ public String getDriverName() { @Override public String getDriverVersion() { - return "NA"; + return DRIVER_VERSION; } @Override public int getDriverMajorVersion() { - return 1; + return DRIVER_MAJOR_VERSION; } @Override public int getDriverMinorVersion() { - return 0; + return DRIVER_MINOR_VERSION; } @Override @@ -1126,12 +1131,12 @@ private int parseVersion(String str) { @Override public int getJDBCMajorVersion() { - return 4; + return JDBC_MAJOR_VERSION; } @Override public int getJDBCMinorVersion() { - return 0; + return JDBC_MINOR_VERSION; } @Override diff --git a/src/main/java/com/aerospike/jdbc/AerospikeDriver.java b/src/main/java/com/aerospike/jdbc/AerospikeDriver.java index 6bb5849..ea3a252 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikeDriver.java +++ b/src/main/java/com/aerospike/jdbc/AerospikeDriver.java @@ -14,6 +14,8 @@ import java.util.Properties; import java.util.logging.Logger; +import static com.aerospike.jdbc.util.Constants.DRIVER_MAJOR_VERSION; +import static com.aerospike.jdbc.util.Constants.DRIVER_MINOR_VERSION; import static java.util.stream.Collectors.toList; public class AerospikeDriver implements Driver { @@ -55,11 +57,11 @@ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) { } public int getMajorVersion() { - return 1; + return DRIVER_MAJOR_VERSION; } public int getMinorVersion() { - return 0; + return DRIVER_MINOR_VERSION; } public boolean jdbcCompliant() { diff --git a/src/main/java/com/aerospike/jdbc/util/Constants.java b/src/main/java/com/aerospike/jdbc/util/Constants.java index ddb7d4e..1994a59 100644 --- a/src/main/java/com/aerospike/jdbc/util/Constants.java +++ b/src/main/java/com/aerospike/jdbc/util/Constants.java @@ -7,6 +7,16 @@ public final class Constants { public static final String UNSUPPORTED_QUERY_TYPE_MESSAGE = "Unsupported query type"; + // Driver version + public static final String DRIVER_VERSION = "1.7.5"; + public static final int DRIVER_MAJOR_VERSION = 1; + public static final int DRIVER_MINOR_VERSION = 7; + + // JDBC specification + public static final String JDBC_VERSION = "4.2"; + public static final int JDBC_MAJOR_VERSION = JDBC_VERSION.charAt(0) - '0'; + public static final int JDBC_MINOR_VERSION = JDBC_VERSION.charAt(2) - '0'; + private Constants() { } } diff --git a/src/test/java/com/aerospike/jdbc/DatabaseMetadataTest.java b/src/test/java/com/aerospike/jdbc/DatabaseMetadataTest.java index 62963ee..1e53edb 100644 --- a/src/test/java/com/aerospike/jdbc/DatabaseMetadataTest.java +++ b/src/test/java/com/aerospike/jdbc/DatabaseMetadataTest.java @@ -53,7 +53,7 @@ public void tearDown() throws SQLException { @Test public void testGetTables() throws SQLException { DatabaseMetaData databaseMetaData = connection.getMetaData(); - ResultSet tables = databaseMetaData.getTables(namespace, namespace, tableName, null); + ResultSet tables = databaseMetaData.getTables(namespace, "", tableName, null); if (tables.next()) { assertEquals(tables.getString("TABLE_NAME"), tableName); @@ -66,13 +66,12 @@ public void testGetTables() throws SQLException { public void testGetSchemas() throws SQLException { ResultSet schemas = connection.getMetaData().getSchemas(); - if (schemas.next()) { - String schemaName = schemas.getString(1); - String catalogName = schemas.getString(2); - assertEquals(schemas.getString("TABLE_SCHEM"), schemaName); - assertEquals(schemas.getString("TABLE_CATALOG"), catalogName); - assertFalse(schemas.next()); - } + assertTrue(schemas.next()); + String schemaName = schemas.getString(1); + String catalogName = schemas.getString(2); + assertEquals(schemas.getString("TABLE_SCHEM"), schemaName); + assertEquals(schemas.getString("TABLE_CATALOG"), catalogName); + assertFalse(schemas.next()); TestUtil.closeQuietly(schemas); } @@ -86,4 +85,12 @@ public void testGetCatalogs() throws SQLException { assertFalse(catalogs.next()); TestUtil.closeQuietly(catalogs); } + + @Test + public void testJDBCVersion() throws SQLException { + DatabaseMetaData metadata = connection.getMetaData(); + + assertEquals(metadata.getJDBCMajorVersion(), 4); + assertEquals(metadata.getJDBCMinorVersion(), 2); + } }