Skip to content

Commit

Permalink
FMWK-289 Return JDBC version 4.2 in metadata (#60)
Browse files Browse the repository at this point in the history
* FMWK-289 Return JDBC version 4.2 in metadata

* return proper driver versions
  • Loading branch information
reugn authored Dec 20, 2023
1 parent c1740df commit 87ecbb7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/main/java/com/aerospike/jdbc/AerospikeDatabaseMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/aerospike/jdbc/AerospikeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/aerospike/jdbc/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}
23 changes: 15 additions & 8 deletions src/test/java/com/aerospike/jdbc/DatabaseMetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
}
}

0 comments on commit 87ecbb7

Please sign in to comment.