Skip to content

Commit

Permalink
FMWK-587 Return null for inapplicable URLs in driver connect
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Oct 30, 2024
1 parent 5fb1b8c commit c4a0e7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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

0 comments on commit c4a0e7e

Please sign in to comment.