Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-587 Return null for inapplicable URLs in driver connect #75

Merged
merged 2 commits into from
Oct 30, 2024
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
12 changes: 10 additions & 2 deletions src/main/java/com/aerospike/jdbc/AerospikeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class AerospikeDriver implements Driver {

private static final Logger logger = Logger.getLogger("com.aerospike.jdbc");
private static final String AEROSPIKE_URL_PREFIX = "jdbc:aerospike:";

static {
try {
Expand All @@ -33,12 +34,19 @@ public class AerospikeDriver implements Driver {
Log.setCallback(asLoggerCallback);
}

public Connection connect(String url, Properties info) {
public Connection connect(String url, Properties info) throws SQLException {
if (url == null) {
throw new SQLException("url is null");
}
if (!url.startsWith(AEROSPIKE_URL_PREFIX)) {
return null;
}

return new AerospikeConnection(url, info);
}

public boolean acceptsURL(String url) {
return Objects.nonNull(url) && url.startsWith("jdbc:aerospike:");
return Objects.nonNull(url) && url.startsWith(AEROSPIKE_URL_PREFIX);
}

public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;

public class ParseJdbcUrlTest {
Expand Down Expand Up @@ -70,6 +71,14 @@ public void testParseUrlParameters() throws Exception {
assertEquals(config.getDriverPolicy().getRecordSetTimeoutMs(), 7000);
}

@Test
public void testInapplicableUrl() throws Exception {
AerospikeDriver driver = (AerospikeDriver) Class.forName("com.aerospike.jdbc.AerospikeDriver")
.newInstance();
String url = "jdbc:postgresql://localhost:5432/sample";
assertNull(driver.connect(url, new Properties()));
}

private void assertTotalTimeoutAll(IAerospikeClient client, int timeout) {
assertEquals(client.getReadPolicyDefault().totalTimeout, timeout);
assertEquals(client.getWritePolicyDefault().totalTimeout, timeout);
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/aerospike/jdbc/RecordMetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void testSelectAllColumns() throws SQLException {
assertTrue(resultSet.next());
assertEquals(resultSet.getString(METADATA_DIGEST_COLUMN_NAME), "212ddf97ff3fe0f6dec5e1626d92a635a55171c2");
assertEquals(resultSet.getInt(METADATA_GEN_COLUMN_NAME), 1);
assertTrue(resultSet.getInt(METADATA_TTL_COLUMN_NAME) > 0);
assertFalse(resultSet.next());
} finally {
closeQuietly(statement);
Expand All @@ -119,7 +118,6 @@ public void testSelectMetadataColumns() throws SQLException {
assertTrue(resultSet.next());
assertNull(resultSet.getObject(METADATA_DIGEST_COLUMN_NAME));
assertEquals(resultSet.getInt(METADATA_GEN_COLUMN_NAME), 1);
assertTrue(resultSet.getInt(METADATA_TTL_COLUMN_NAME) > 0);
assertEquals(resultSet.getInt("int1"), 11100);
assertFalse(resultSet.next());
} finally {
Expand Down
Loading