Skip to content

Replace TConnection with TClientImpl in JDBC #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,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 @@ -67,4 +69,9 @@ public class TarantoolClientConfig {
*/
public int retryCount = 3;

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

}
Loading