Skip to content

Commit

Permalink
Replace TConnection with TClientImpl in JDBC
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 basic 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 May 15, 2019
1 parent 0ee7b30 commit 769d0a8
Show file tree
Hide file tree
Showing 32 changed files with 1,289 additions and 958 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Remember that `TarantoolClient` adopts a
when a client is not connected.

The `TarantoolClient` will stop functioning if your implementation of a socket
channel provider raises an exception or returns a null. You will need a new
channel provider raises an exception. You will need a new
instance of client to recover. Hence, you should only throw in case you have
met unrecoverable error.

Expand Down Expand Up @@ -120,13 +120,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 769d0a8

Please sign in to comment.