File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
main/java/com/aerospike/jdbc
test/java/com/aerospike/jdbc Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 2121public class AerospikeDriver implements Driver {
2222
2323 private static final Logger logger = Logger .getLogger ("com.aerospike.jdbc" );
24+ private static final String AEROSPIKE_URL_PREFIX = "jdbc:aerospike:" ;
2425
2526 static {
2627 try {
@@ -33,12 +34,19 @@ public class AerospikeDriver implements Driver {
3334 Log .setCallback (asLoggerCallback );
3435 }
3536
36- public Connection connect (String url , Properties info ) {
37+ public Connection connect (String url , Properties info ) throws SQLException {
38+ if (url == null ) {
39+ throw new SQLException ("url is null" );
40+ }
41+ if (!url .startsWith (AEROSPIKE_URL_PREFIX )) {
42+ return null ;
43+ }
44+
3745 return new AerospikeConnection (url , info );
3846 }
3947
4048 public boolean acceptsURL (String url ) {
41- return Objects .nonNull (url ) && url .startsWith ("jdbc:aerospike:" );
49+ return Objects .nonNull (url ) && url .startsWith (AEROSPIKE_URL_PREFIX );
4250 }
4351
4452 public DriverPropertyInfo [] getPropertyInfo (String url , Properties info ) {
Original file line number Diff line number Diff line change 1111
1212import static org .testng .Assert .assertEquals ;
1313import static org .testng .Assert .assertFalse ;
14+ import static org .testng .Assert .assertNull ;
1415import static org .testng .Assert .assertTrue ;
1516
1617public class ParseJdbcUrlTest {
@@ -70,6 +71,14 @@ public void testParseUrlParameters() throws Exception {
7071 assertEquals (config .getDriverPolicy ().getRecordSetTimeoutMs (), 7000 );
7172 }
7273
74+ @ Test
75+ public void testInapplicableUrl () throws Exception {
76+ AerospikeDriver driver = (AerospikeDriver ) Class .forName ("com.aerospike.jdbc.AerospikeDriver" )
77+ .newInstance ();
78+ String url = "jdbc:postgresql://localhost:5432/sample" ;
79+ assertNull (driver .connect (url , new Properties ()));
80+ }
81+
7382 private void assertTotalTimeoutAll (IAerospikeClient client , int timeout ) {
7483 assertEquals (client .getReadPolicyDefault ().totalTimeout , timeout );
7584 assertEquals (client .getWritePolicyDefault ().totalTimeout , timeout );
You can’t perform that action at this time.
0 commit comments