Skip to content

Commit

Permalink
Merge pull request #7 from aerospike/develop
Browse files Browse the repository at this point in the history
v1.4.0
  • Loading branch information
reugn authored Dec 23, 2021
2 parents ccbf7c1 + f3e01d5 commit dcc86cf
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
with:
java-version: 1.8

- name: Set up Aerospike Database
uses: reugn/github-action-aerospike@v1

- name: Maven cache and restore deps
uses: actions/cache@v1
with:
Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
<name>aerospike-jdbc</name>
<description>A JDBC driver for the Aerospike database</description>
<url>https://github.com/aerospike/aerospike-jdbc</url>
<version>1.3.0</version>
<version>1.4.0</version>

<properties>
<skipTests>true</skipTests>
<skipTests>false</skipTests>
<java.version>1.8</java.version>

<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
Expand All @@ -25,10 +25,10 @@
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>

<aerospike-client.version>5.1.3</aerospike-client.version>
<netty.version>4.1.65.Final</netty.version>
<jackson.version>2.12.3</jackson.version>
<trino-parser.version>358</trino-parser.version>
<aerospike-client.version>5.1.11</aerospike-client.version>
<netty.version>4.1.72.Final</netty.version>
<jackson.version>2.13.1</jackson.version>
<trino-parser.version>362</trino-parser.version>
</properties>

<licenses>
Expand Down Expand Up @@ -103,21 +103,21 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.13.2</version>
<version>3.21.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<version>7.4.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-core</artifactId>
<version>3.17.0</version>
<version>3.24.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/aerospike/jdbc/util/URLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.aerospike.client.Host;
import com.aerospike.client.Value;
import com.aerospike.client.policy.AuthMode;
import com.aerospike.client.policy.ClientPolicy;
import com.aerospike.client.policy.ScanPolicy;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.jdbc.scan.EventLoopProvider;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;
import java.util.Properties;
import java.util.logging.Logger;
Expand Down Expand Up @@ -78,7 +81,18 @@ public static <T> T copy(Properties props, T object) {
Class<T> clazz = (Class<T>) object.getClass();
props.forEach((key, value) -> {
try {
clazz.getField((String) key).set(object, value);
Field field = clazz.getField((String) key);
if (field.getType().equals(Integer.TYPE)) {
field.set(object, Integer.valueOf(value.toString()));
} else if (field.getType().equals(Long.TYPE)) {
field.set(object, Long.valueOf(value.toString()));
} else if (field.getType().equals(Boolean.TYPE)) {
field.set(object, Boolean.valueOf(value.toString()));
} else if (field.getType().equals(AuthMode.class)) {
field.set(object, AuthMode.valueOf(value.toString().toUpperCase(Locale.ENGLISH)));
} else {
field.set(object, value);
}
} catch (ReflectiveOperationException e1) {
// ignore it; this property does not belong to the object
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/aerospike/jdbc/DatabaseMetadataTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aerospike.jdbc;

import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import java.sql.DatabaseMetaData;
Expand All @@ -11,6 +12,7 @@
public class DatabaseMetadataTest extends JdbcBaseTest {

@Test
@Ignore
public void testGetTables() throws SQLException {
DatabaseMetaData databaseMetaData = connection.getMetaData();

Expand Down
22 changes: 13 additions & 9 deletions src/test/java/com/aerospike/jdbc/JdbiQueriesTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aerospike.jdbc;

import org.jdbi.v3.core.Jdbi;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import java.util.Map;
Expand All @@ -11,20 +12,21 @@
public class JdbiQueriesTest extends JdbcBaseTest {

@Test
@Ignore
public void testJdbiInsertStringLiteral() {
String id = UUID.randomUUID().toString();
Jdbi jdbi = Jdbi.create(connection);
jdbi.withHandle(handle -> {
int rowsInserted = handle.createUpdate(String.format("INSERT INTO test.foo (PK, k1, k2, k3, k4) VALUES ('%s', i1, i2, i3, i4)", id))
int rowsInserted = handle.createUpdate(String.format("INSERT INTO test.foo (__key, k1, k2, k3, k4) VALUES ('%s', 'i1', 'i2', 'i3', 'i4')", id))
.execute();

assertEquals(rowsInserted, 1);

Map<String, Object> result = handle.createQuery(String.format("SELECT * FROM test.foo WHERE PK='%s'", id))
Map<String, Object> result = handle.createQuery(String.format("SELECT * FROM test.foo WHERE __key='%s'", id))
.mapToMap()
.first();

assertEquals(result.get("pk"), id);
assertEquals(result.get("__key").toString(), id);
assertEquals(result.get("k1"), "i1");
assertEquals(result.get("k2"), "i2");
assertEquals(result.get("k3"), "i3");
Expand All @@ -35,6 +37,7 @@ public void testJdbiInsertStringLiteral() {
}

@Test
@Ignore
public void testJdbiBindVariablesPositions() {
String id = UUID.randomUUID().toString();
String v1 = "v1";
Expand All @@ -43,7 +46,7 @@ public void testJdbiBindVariablesPositions() {
String v4 = "v4";
Jdbi jdbi = Jdbi.create(connection);
jdbi.withHandle(handle -> {
int rowsInserted = handle.createUpdate("INSERT INTO test.foo (PK, k1, k2, k3, k4) VALUES (?, ?, ?, ?, ?)")
int rowsInserted = handle.createUpdate("INSERT INTO test.foo (__key, k1, k2, k3, k4) VALUES (?, ?, ?, ?, ?)")
.bind(0, id)
.bind(1, v1)
.bind(2, v2)
Expand All @@ -53,12 +56,12 @@ public void testJdbiBindVariablesPositions() {

assertEquals(rowsInserted, 1);

Map<String, Object> result = handle.createQuery("SELECT * FROM test.foo WHERE PK=?")
Map<String, Object> result = handle.createQuery("SELECT * FROM test.foo WHERE __key=?")
.bind(0, id)
.mapToMap()
.first();

assertEquals(result.get("pk"), id);
assertEquals(result.get("__key").toString(), id);
assertEquals(result.get("k1"), v1);
assertEquals(result.get("k2"), v2);
assertEquals(result.get("k3"), v3);
Expand All @@ -69,6 +72,7 @@ public void testJdbiBindVariablesPositions() {
}

@Test
@Ignore
public void testJdbiBindVariablesNames() {
String id = UUID.randomUUID().toString();
String v1 = "v1";
Expand All @@ -77,7 +81,7 @@ public void testJdbiBindVariablesNames() {
String v4 = "v4";
Jdbi jdbi = Jdbi.create(connection);
jdbi.withHandle(handle -> {
int rowsInserted = handle.createUpdate("INSERT INTO test.foo (PK, k1, k2, k3, k4) VALUES (:id, :v1, :v2, :v3, :v4)")
int rowsInserted = handle.createUpdate("INSERT INTO test.foo (__key, k1, k2, k3, k4) VALUES (:id, :v1, :v2, :v3, :v4)")
.bind("id", id)
.bind("v1", v1)
.bind("v2", v2)
Expand All @@ -87,12 +91,12 @@ public void testJdbiBindVariablesNames() {

assertEquals(rowsInserted, 1);

Map<String, Object> result = handle.createQuery("SELECT * FROM test.foo WHERE PK=:id")
Map<String, Object> result = handle.createQuery("SELECT * FROM test.foo WHERE __key=:id")
.bind("id", id)
.mapToMap()
.first();

assertEquals(result.get("pk"), id);
assertEquals(result.get("__key").toString(), id);
assertEquals(result.get("k1"), v1);
assertEquals(result.get("k2"), v2);
assertEquals(result.get("k3"), v3);
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/aerospike/jdbc/ParseJdbcUrlTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.aerospike.jdbc;

import org.testng.annotations.Test;

import java.sql.DriverManager;

public class ParseJdbcUrlTest {

@Test
public void testParseUrlParameters() throws Exception {
Class.forName("com.aerospike.jdbc.AerospikeDriver").newInstance();
String url = String.format(
"jdbc:aerospike:%s:%d/%s?timeout=%d&useServicesAlternate=%b&maxRecords=%d&authMode=%s",
"localhost", 3000, "test", 512, true, 64L, "external_insecure"
);
DriverManager.getConnection(url);
}
}

0 comments on commit dcc86cf

Please sign in to comment.