Skip to content

Commit

Permalink
Remove TarantoolConnection
Browse files Browse the repository at this point in the history
Replace obsolete TarantoolConnection with TarantoolClient to have an
ability to perform async operations.

Update SQLDriver URL parameters. Add init and operation timeouts.
Remove socket timeout and replace socket provider with socket channel
provider options (according to TarantoolConnection-to-TarantoolClient
transfer written above).

Add operation timeout capability to TarantoolClientImpl. It also affects
the cluster client which no more needs its own expirable operations.

Add base support for SQLStatement (setQueryTimeout) to execute requests
with timeout using new TarantoolClient operation timeout.

Remove deprecated JDBCBridge. SQLConnection accepted the responsibility
for producing raw SQL results.

Update README doc with respect to JDBC driver options changes.

Closes: #163
Follows on: #75, #155
  • Loading branch information
nicktorwald committed Apr 30, 2019
1 parent 3420575 commit 97220b4
Show file tree
Hide file tree
Showing 26 changed files with 795 additions and 1,005 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,22 @@ Feel free to override any method of `TarantoolClientImpl`. For example, to hook
all the results, you could override this:

```java
protected void complete(long code, CompletableFuture<?> q);
protected void complete(TarantoolPacket packet, TarantoolOp<?> future);
```

## Spring NamedParameterJdbcTemplate usage example

To configure sockets you should implements SQLSocketProvider and add socketProvider=abc.xyz.MySocketProvider to connect url.
For example tarantool://localhost:3301?user=test&password=test&socketProvider=abc.xyz.MySocketProvider
The JDBC driver uses `TarantoolClient` implementation to provide a communication with server.
To configure socket channel provider you should implements SocketChannelProvider and add
`socketChannelProvider=abc.xyz.MySocketChannelProvider` to connect url.

For example:

```
tarantool://localhost:3301?user=test&password=test&socketProvider=abc.xyz.MySocketProvider
```

Here is an example how you can use the driver covered by Spring `DriverManagerDataSource`:

```java
NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(new DriverManagerDataSource("tarantool://localhost:3301?user=test&password=test"));
Expand Down
85 changes: 0 additions & 85 deletions src/main/java/org/tarantool/JDBCBridge.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/org/tarantool/SqlProtoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

public abstract class SqlProtoUtils {
public static List<Map<String, Object>> readSqlResult(TarantoolPacket pack) {
List<List<?>> data = (List<List<?>>) pack.getBody().get(Key.DATA.getId());
List<List<Object>> data = getSQLData(pack);
List<SQLMetaData> metaData = getSQLMetadata(pack);

List<Map<String, Object>> values = new ArrayList<>(data.size());
List<SQLMetaData> metaData = getSQLMetadata(pack);
for (List row : data) {
LinkedHashMap<String, Object> value = new LinkedHashMap<>();
for (int i = 0; i < row.size(); i++) {
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/tarantool/TarantoolBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

public abstract class TarantoolBase<Result> extends AbstractTarantoolOps<Integer, List<?>, Object, Result> {
protected String serverVersion;

/**
* Connection state.
*/
protected MsgPackLite msgPackLite = MsgPackLite.INSTANCE;
protected AtomicLong syncId = new AtomicLong();
protected int initialRequestSize = 4096;
Expand All @@ -25,7 +21,7 @@ public TarantoolBase() {
public TarantoolBase(String username, String password, Socket socket) {
super();
try {
TarantoolGreeting greeting = ProtoUtils.connect(socket, username, password);
TarantoolGreeting greeting = ProtoUtils.connect(socket, username, password, msgPackLite);
this.serverVersion = greeting.getServerVersion();
} catch (IOException e) {
throw new CommunicationException("Couldn't connect to tarantool", e);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/tarantool/TarantoolClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface TarantoolClient {

boolean isAlive();

boolean isClosed();

void waitAlive() throws InterruptedException;

boolean waitAlive(long timeout, TimeUnit unit) throws InterruptedException;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/tarantool/TarantoolClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class TarantoolClientConfig {

public static final int DEFAULT_OPERATION_EXPIRY_TIME_MILLIS = 1000;

/**
* Auth-related data.
*/
Expand Down Expand Up @@ -48,4 +50,9 @@ public class TarantoolClientConfig {
public long initTimeoutMillis = 60 * 1000L;
public long writeTimeoutMillis = 60 * 1000L;

/**
* Operation expiration period.
*/
public int operationExpiryTimeMillis = DEFAULT_OPERATION_EXPIRY_TIME_MILLIS;

}
Loading

0 comments on commit 97220b4

Please sign in to comment.