|
1 |
| -You could get [1.6.9](https://github.com/tarantool/tarantool-java/tree/connector-1.6.9) |
| 1 | +<a href="http://tarantool.org"> |
| 2 | + <img src="https://avatars2.githubusercontent.com/u/2344919?v=2&s=250" |
| 3 | +align="right"> |
| 4 | +</a> |
2 | 5 |
|
3 |
| -# Java Connector for Tarantool 1.7.4 |
| 6 | +# Java connector for Tarantool 1.7.4+ |
4 | 7 |
|
5 | 8 | [](https://gitter.im/tarantool/tarantool-java?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
6 | 9 |
|
7 |
| -## Problems & Questions |
8 |
| -http://stackoverflow.com/questions/ask/advice with tags `tarantool` and `java`. |
| 10 | +To get the Java connector for Tarantool 1.6.9, visit |
| 11 | +[this GitHub page](https://github.com/tarantool/tarantool-java/tree/connector-1.6.9). |
9 | 12 |
|
10 |
| -## Note |
11 |
| -Tarantool client is not supports name resolving for fields, indexes, space etc. I highly recommend to use server side lua to |
12 |
| -operate with named items. For example you could create dao object with simple CRUD functions. |
13 |
| -If you still need client name resolving for some reasons you could create function which will return required maps with name to id mappings. |
| 13 | +## Table of contents |
| 14 | +* [Getting started](#getting-started) |
| 15 | +* [Where to get help](#where-to-get-help) |
14 | 16 |
|
15 |
| -## How to start |
| 17 | +## Getting started |
| 18 | + |
| 19 | +1. Add a dependency to your `pom.xml` file. |
16 | 20 |
|
17 |
| -First you should add dependency to your pom file |
18 | 21 | ```xml
|
19 | 22 | <dependency>
|
20 | 23 | <groupId>org.tarantool</groupId>
|
21 | 24 | <artifactId>connector</artifactId>
|
22 | 25 | <version>1.7.4</version>
|
23 | 26 | </dependency>
|
24 | 27 | ```
|
25 |
| -Second configure TarantoolClientConfig. |
| 28 | + |
| 29 | +2. Configure `TarantoolClientConfig`. |
26 | 30 |
|
27 | 31 | ```java
|
28 |
| - TarantoolClientConfig config = new TarantoolClientConfig(); |
29 |
| - config.username = "test"; |
30 |
| - config.password = "test"; |
| 32 | +TarantoolClientConfig config = new TarantoolClientConfig(); |
| 33 | +config.username = "test"; |
| 34 | +config.password = "test"; |
31 | 35 | ```
|
32 | 36 |
|
33 |
| -Then implements your SocketChannelProvider. SocketChannelProvider should return connected SocketChannel. |
34 |
| -Here you also could implement some reconnect or fallback policy. Remember that TarantoolClient uses [fail fast |
35 |
| -policy](https://en.wikipedia.org/wiki/Fail-fast) when client is not connected. |
36 |
| - |
| 37 | +3. Implement your `SocketChannelProvider`. |
| 38 | + It should return a connected `SocketChannel`. |
37 | 39 |
|
38 | 40 | ```java
|
39 |
| - SocketChannelProvider socketChannelProvider = new SocketChannelProvider() { |
40 |
| - @Override |
41 |
| - public SocketChannel get(int retryNumber, Throwable lastError) { |
42 |
| - if (lastError != null) { |
43 |
| - lastError.printStackTrace(System.out); |
44 |
| - } |
45 |
| - try { |
46 |
| - return SocketChannel.open(new InetSocketAddress("localhost", 3301)); |
47 |
| - } catch (IOException e) { |
48 |
| - throw new IllegalStateException(e); |
49 |
| - } |
50 |
| - } |
51 |
| - }; |
| 41 | +SocketChannelProvider socketChannelProvider = new SocketChannelProvider() { |
| 42 | + @Override |
| 43 | + public SocketChannel get(int retryNumber, Throwable lastError) { |
| 44 | + if (lastError != null) { |
| 45 | + lastError.printStackTrace(System.out); |
| 46 | + } |
| 47 | + try { |
| 48 | + return SocketChannel.open(new InetSocketAddress("localhost", 3301)); |
| 49 | + } catch (IOException e) { |
| 50 | + throw new IllegalStateException(e); |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
52 | 54 | ```
|
53 | 55 |
|
54 |
| -Now you are ready to create client |
| 56 | +Here you could also implement some reconnection or fallback policy. |
| 57 | +Remember that `TarantoolClient` adopts a |
| 58 | +[fail-fast](https://en.wikipedia.org/wiki/Fail-fast) policy |
| 59 | +when a client is not connected. |
| 60 | + |
| 61 | +4. Create a client. |
| 62 | + |
55 | 63 | ```java
|
56 | 64 | TarantoolClient client = new TarantoolClientImpl(socketChannelProvider, config);
|
57 | 65 | ```
|
58 | 66 |
|
59 |
| -TarantoolClient is thread safe and async so you should use one client inside whole application. |
| 67 | +> **Notes:** |
| 68 | +> * `TarantoolClient` is thread-safe and asynchronous, so you should use one |
| 69 | +> client inside the whole application. |
| 70 | +> * `TarantoolClient` does not support name resolution for fields, indexes, |
| 71 | +> spaces and so on. We highly recommend to use server-side Lua when working |
| 72 | +> with named items. For example, you could create a data access object (DAO) |
| 73 | +> with simple CRUD functions. If, for some reason, you do need client name |
| 74 | +> resolution, you could create a function that returns necessary name-to-ID |
| 75 | +> mappings. |
60 | 76 |
|
61 |
| -TarantoolClient provides 3 interfaces to execute queries |
| 77 | +`TarantoolClient` provides three interfaces to execute queries: |
62 | 78 |
|
63 |
| -* SyncOps returns operation result |
64 |
| -* AsyncOps returns operation result Future |
65 |
| -* FireAndForgetOps returns query ID |
| 79 | +* `SyncOps` - returns the operation result |
| 80 | +* `AsyncOps` - returns the operation result as a `Future` |
| 81 | +* `FireAndForgetOps` - returns the query ID |
66 | 82 |
|
| 83 | +Feel free to override any method of `TarantoolClientImpl`. For example, to hook |
| 84 | +all the results, you could override this: |
67 | 85 |
|
68 |
| -Feel free to override any method of TarantoolClientImpl. For example you |
69 |
| -could override |
70 | 86 | ```java
|
71 | 87 | protected void complete(long code, FutureImpl<List> q);
|
72 | 88 | ```
|
73 |
| -to hook all results. |
74 |
| - |
75 |
| - |
76 | 89 |
|
| 90 | +## Where to get help |
77 | 91 |
|
| 92 | +Got problems or questions? Post them on |
| 93 | +[Stack Overflow](http://stackoverflow.com/questions/ask/advice) with the |
| 94 | +`tarantool` and `java` tags, or use these tags to search the existing knowledge |
| 95 | +base for possible answers and solutions. |
0 commit comments