Skip to content

Commit

Permalink
Merge pull request #1 from aerospike/develop
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
reugn authored May 6, 2021
2 parents d80a966 + 76e968f commit cec4766
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 170 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>aerospike-jdbc</name>
<description>A JDBC driver for the Aerospike database</description>
<url>https://github.com/aerospike/aerospike-jdbc</url>
<version>1.1.0</version>
<version>1.2.0</version>

<properties>
<skipTests>true</skipTests>
Expand All @@ -25,9 +25,9 @@
<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.0.5</aerospike-client.version>
<netty.version>4.1.58.Final</netty.version>
<jackson.version>2.12.0</jackson.version>
<aerospike-client.version>5.1.0</aerospike-client.version>
<netty.version>4.1.63.Final</netty.version>
<jackson.version>2.12.3</jackson.version>
<presto-parser.version>347</presto-parser.version>
</properties>

Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/aerospike/jdbc/AerospikeConnection.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.aerospike.jdbc;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Host;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.policy.Policy;
import com.aerospike.jdbc.sql.SimpleWrapper;
import com.aerospike.jdbc.sql.type.ByteArrayBlob;
import com.aerospike.jdbc.sql.type.StringClob;
import com.aerospike.jdbc.util.ConnectionParametersParser;
import com.aerospike.jdbc.util.URLParser;

import java.sql.*;
import java.util.Map;
Expand All @@ -26,9 +25,7 @@ public class AerospikeConnection implements Connection, SimpleWrapper {

private static final Logger logger = Logger.getLogger(AerospikeConnection.class.getName());

private static final ConnectionParametersParser parser = new ConnectionParametersParser();
private final String url;
private final Properties props;
private final IAerospikeClient client;
private volatile boolean readOnly = false;
private final Properties clientInfo = new Properties();
Expand All @@ -39,10 +36,11 @@ public class AerospikeConnection implements Connection, SimpleWrapper {

public AerospikeConnection(String url, Properties props) {
this.url = url;
this.props = props;
Host[] hosts = parser.hosts(url);
client = new AerospikeClient(parser.policy(url, props), hosts);
schema.set(parser.schema(url)); // namespace
URLParser.parseUrl(url, props);
client = new AerospikeClient(
URLParser.getClientPolicy(), URLParser.getHosts()
);
schema.set(URLParser.getSchema()); // namespace
}

@Override
Expand Down Expand Up @@ -99,7 +97,7 @@ public boolean isClosed() {
@Override
public DatabaseMetaData getMetaData() {
logger.info("getMetaData request");
return new AerospikeDatabaseMetadata(url, props, client, this);
return new AerospikeDatabaseMetadata(url, client, this);
}

@Override
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/com/aerospike/jdbc/AerospikeDatabaseMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import com.aerospike.jdbc.schema.AerospikeSchemaBuilder;
import com.aerospike.jdbc.sql.ListRecordSet;
import com.aerospike.jdbc.sql.SimpleWrapper;
import com.aerospike.jdbc.util.ConnectionParametersParser;
import com.aerospike.jdbc.util.URLParser;

import java.io.IOException;
import java.io.StringReader;
import java.sql.*;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowIdLifetime;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
Expand All @@ -34,7 +39,6 @@ public class AerospikeDatabaseMetadata implements DatabaseMetaData, SimpleWrappe

private static final Logger logger = Logger.getLogger(AerospikeDatabaseMetadata.class.getName());

private final static ConnectionParametersParser parser = new ConnectionParametersParser();
private final String url;
private final Properties clientInfo;

Expand All @@ -47,11 +51,11 @@ public class AerospikeDatabaseMetadata implements DatabaseMetaData, SimpleWrappe
private final Map<String, Collection<String>> tables = new ConcurrentHashMap<>();
private final Map<String, Collection<IndexInfo>> indices = new ConcurrentHashMap<>();

public AerospikeDatabaseMetadata(String url, Properties info, IAerospikeClient client, Connection connection) {
public AerospikeDatabaseMetadata(String url, IAerospikeClient client, Connection connection) {
logger.info("Init AerospikeDatabaseMetadata");
AerospikeSchemaBuilder.cleanSchemaCache();
this.url = url;
clientInfo = parser.clientInfo(url, info);
clientInfo = URLParser.getClientInfo();
this.connection = connection;
infoPolicy = client.getInfoPolicyDefault();

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import com.aerospike.jdbc.util.IOUtils;
import io.prestosql.sql.parser.ParsingOptions;

import java.io.*;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
Expand All @@ -22,7 +27,7 @@
import java.util.Optional;
import java.util.logging.Logger;

import static com.aerospike.jdbc.util.PreparedStatementUtil.parseParameters;
import static com.aerospike.jdbc.util.PreparedStatement.parseParameters;
import static io.prestosql.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE;
import static java.lang.String.format;

Expand Down Expand Up @@ -54,7 +59,7 @@ public ResultSet executeQuery() {
}

@Override
public int executeUpdate() throws SQLException {
public int executeUpdate() {
logger.info("AerospikePreparedStatement executeUpdate");
return super.executeUpdate(sql);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/aerospike/jdbc/AerospikeStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ private AerospikeQuery parseQuery(String sql) {
}

@Override
public int executeUpdate(String sql) throws SQLException {
throw new SQLFeatureNotSupportedException("Update is not supported");
public int executeUpdate(String sql) {
executeQuery(sql);
return updateCount;
}

@Override
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static java.util.Collections.emptyList;

Expand All @@ -28,7 +27,8 @@ protected Bin[] getBins(AerospikeQuery query) {
List<Bin> bins = new ArrayList<>();
List<String> columns = query.getColumns();
for (int i = 0; i < columns.size(); i++) {
bins.add(new Bin(IOUtils.stripQuotes(columns.get(i)), getBinValue(query.getValues().get(i))));
bins.add(new Bin(IOUtils.stripQuotes(columns.get(i)),
getBinValue(query.getValues().get(i))));
}
return bins.toArray(new Bin[0]);
}
Expand All @@ -45,7 +45,11 @@ protected Value getBinValue(String strValue) {
return new Value.DoubleValue(Double.parseDouble(strValue));
} catch (NumberFormatException ignore) {
}
if (strValue.toLowerCase(Locale.ENGLISH).equals("null")) {
if (strValue.equalsIgnoreCase("true") ||
strValue.equalsIgnoreCase("false")) {
return Value.get(Boolean.parseBoolean(strValue));
}
if (strValue.equalsIgnoreCase("null")) {
return Value.NULL;
}
return Value.get(strValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Key;
import com.aerospike.client.Value;
import com.aerospike.client.policy.ScanPolicy;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.jdbc.model.AerospikeQuery;
Expand Down Expand Up @@ -33,7 +32,7 @@ public Pair<ResultSet, Integer> execute(AerospikeQuery query) {
Object keyObject = ExpressionBuilder.fetchPrimaryKey(query.getWhere());
final WritePolicy writePolicy = buildWritePolicy(query);
if (Objects.nonNull(keyObject)) {
Key key = new Key(query.getSchema(), query.getTable(), Value.get(keyObject));
Key key = new Key(query.getSchema(), query.getTable(), getBinValue(keyObject.toString()));
int count = client.delete(writePolicy, key) ? 1 : 0;

return new Pair<>(emptyRecordSet(query), count);
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/com/aerospike/jdbc/query/ExpressionBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aerospike.jdbc.query;

import com.aerospike.client.Value;
import com.aerospike.client.exp.Exp;
import com.aerospike.client.query.RegexFlag;
import com.aerospike.jdbc.model.OpType;
Expand All @@ -17,14 +16,10 @@ public final class ExpressionBuilder {
private ExpressionBuilder() {
}

public static Value fetchPrimaryKey(WhereExpression whereExpression) {
public static Object fetchPrimaryKey(WhereExpression whereExpression) {
if (Objects.nonNull(whereExpression) && !whereExpression.isWrapper()) {
if (whereExpression.getColumn().equals(defaultKeyName)) {
Object value = whereExpression.getValue();
if (isStringValue(value.toString())) {
return Value.get(stripQuotes(value.toString()));
}
return Value.get(value);
return whereExpression.getValue();
}
}
return null;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/aerospike/jdbc/query/PolicyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.aerospike.client.policy.ScanPolicy;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.jdbc.model.AerospikeQuery;
import com.aerospike.jdbc.util.URLParser;

import java.util.Objects;

Expand All @@ -14,7 +15,7 @@ private PolicyBuilder() {
}

public static ScanPolicy buildScanPolicy(AerospikeQuery query) {
ScanPolicy scanPolicy = new ScanPolicy();
ScanPolicy scanPolicy = new ScanPolicy(URLParser.getScanPolicy());
scanPolicy.maxRecords = Objects.isNull(query.getLimit()) ? 0 : query.getLimit();
Exp expression = ExpressionBuilder.buildExp(query.getWhere());
scanPolicy.filterExp = Objects.isNull(expression) ? null : Exp.build(expression);
Expand All @@ -28,7 +29,7 @@ public static ScanPolicy buildScanNoBinDataPolicy(AerospikeQuery query) {
}

public static WritePolicy buildWritePolicy(AerospikeQuery query) {
WritePolicy writePolicy = new WritePolicy();
WritePolicy writePolicy = new WritePolicy(URLParser.getWritePolicy());
writePolicy.sendKey = true;
return writePolicy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public SelectQueryHandler(IAerospikeClient client, Statement statement) {
@Override
public Pair<ResultSet, Integer> execute(AerospikeQuery query) {
columns = AerospikeSchemaBuilder.getSchema(query.getSchemaTable(), client);
Value pk = ExpressionBuilder.fetchPrimaryKey(query.getWhere());
Object keyObject = ExpressionBuilder.fetchPrimaryKey(query.getWhere());
Pair<ResultSet, Integer> result;
if (isCount(query)) {
result = executeCountQuery(query);
} else if (Objects.nonNull(pk)) {
result = executeSelectByPrimaryKey(query, pk);
} else if (Objects.nonNull(keyObject)) {
result = executeSelectByPrimaryKey(query, getBinValue(keyObject.toString()));
} else {
result = executeScanQuery(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.aerospike.client.Bin;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Key;
import com.aerospike.client.Value;
import com.aerospike.client.policy.ScanPolicy;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.jdbc.model.AerospikeQuery;
Expand Down Expand Up @@ -36,7 +35,7 @@ public Pair<ResultSet, Integer> execute(AerospikeQuery query) {
final Bin[] bins = getBins(query);
final WritePolicy writePolicy = buildUpdateOnlyPolicy(query);
if (Objects.nonNull(keyObject)) {
Key key = new Key(query.getSchema(), query.getTable(), Value.get(keyObject));
Key key = new Key(query.getSchema(), query.getTable(), getBinValue(keyObject.toString()));
try {
client.put(writePolicy, key, bins);
} catch (AerospikeException e) {
Expand Down
107 changes: 0 additions & 107 deletions src/main/java/com/aerospike/jdbc/util/ConnectionParametersParser.java

This file was deleted.

Loading

0 comments on commit cec4766

Please sign in to comment.