Skip to content

Commit b43f64a

Browse files
committed
Refactor factories and mappers
1 parent 376f706 commit b43f64a

20 files changed

+260
-231
lines changed

src/main/java/io/tarantool/driver/core/space/ProxyTarantoolSpace.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public ProxyTarantoolSpace(
7878

7979
@Override
8080
public CompletableFuture<R> delete(Conditions conditions) throws TarantoolClientException {
81-
return delete(conditions, tupleResultMapper(), ProxyDeleteOptions.create()
81+
return delete(conditions, rowsMetadataTupleResultMapper(), ProxyDeleteOptions.create()
8282
.withTimeout(config.getRequestTimeout())
8383
);
8484
}
@@ -88,7 +88,7 @@ public CompletableFuture<R> delete(Conditions conditions, DeleteOptions options)
8888
if (options == null) {
8989
throw new IllegalArgumentException("Options should not be null");
9090
}
91-
return delete(conditions, tupleResultMapper(), options);
91+
return delete(conditions, rowsMetadataTupleResultMapper(), options);
9292
}
9393

9494
private CompletableFuture<R> delete(
@@ -113,7 +113,7 @@ private CompletableFuture<R> delete(
113113

114114
@Override
115115
public CompletableFuture<R> insert(T tuple) throws TarantoolClientException {
116-
return insert(tuple, tupleResultMapper(), ProxyInsertOptions.create()
116+
return insert(tuple, rowsMetadataTupleResultMapper(), ProxyInsertOptions.create()
117117
.withTimeout(config.getRequestTimeout())
118118
);
119119
}
@@ -123,7 +123,7 @@ public CompletableFuture<R> insert(T tuple, InsertOptions options) throws Tarant
123123
if (options == null) {
124124
throw new IllegalArgumentException("Options should not be null");
125125
}
126-
return insert(tuple, tupleResultMapper(), options);
126+
return insert(tuple, rowsMetadataTupleResultMapper(), options);
127127
}
128128

129129
private CompletableFuture<R> insert(
@@ -146,7 +146,7 @@ private CompletableFuture<R> insert(
146146

147147
@Override
148148
public CompletableFuture<R> insertMany(Collection<T> tuples) {
149-
return insertMany(tuples, tupleResultMapper(), ProxyInsertManyOptions.create()
149+
return insertMany(tuples, rowsMetadataTupleResultMapper(), ProxyInsertManyOptions.create()
150150
.withTimeout(config.getRequestTimeout())
151151
.withStopOnError(true)
152152
.withRollbackOnError(true)
@@ -159,7 +159,7 @@ public CompletableFuture<R> insertMany(Collection<T> tuples, InsertManyOptions o
159159
if (options == null) {
160160
throw new IllegalArgumentException("Options should not be null");
161161
}
162-
return insertMany(tuples, tupleResultMapper(), options);
162+
return insertMany(tuples, rowsMetadataTupleResultMapper(), options);
163163
}
164164

165165
private CompletableFuture<R> insertMany(
@@ -182,7 +182,7 @@ private CompletableFuture<R> insertMany(
182182

183183
@Override
184184
public CompletableFuture<R> replace(T tuple) throws TarantoolClientException {
185-
return replace(tuple, tupleResultMapper(), ProxyReplaceOptions.create()
185+
return replace(tuple, rowsMetadataTupleResultMapper(), ProxyReplaceOptions.create()
186186
.withTimeout(config.getRequestTimeout())
187187
);
188188
}
@@ -192,7 +192,7 @@ public CompletableFuture<R> replace(T tuple, ReplaceOptions options) throws Tara
192192
if (options == null) {
193193
throw new IllegalArgumentException("Options should not be null");
194194
}
195-
return replace(tuple, tupleResultMapper(), options);
195+
return replace(tuple, rowsMetadataTupleResultMapper(), options);
196196
}
197197

198198
private CompletableFuture<R> replace(
@@ -215,7 +215,7 @@ private CompletableFuture<R> replace(
215215

216216
@Override
217217
public CompletableFuture<R> replaceMany(Collection<T> tuples) throws TarantoolClientException {
218-
return replaceMany(tuples, tupleResultMapper(), ProxyReplaceManyOptions.create()
218+
return replaceMany(tuples, rowsMetadataTupleResultMapper(), ProxyReplaceManyOptions.create()
219219
.withTimeout(config.getRequestTimeout())
220220
.withStopOnError(true)
221221
.withRollbackOnError(true)
@@ -227,7 +227,7 @@ public CompletableFuture<R> replaceMany(Collection<T> tuples, ReplaceManyOptions
227227
if (options == null) {
228228
throw new IllegalArgumentException("Options should not be null");
229229
}
230-
return replaceMany(tuples, tupleResultMapper(), options);
230+
return replaceMany(tuples, rowsMetadataTupleResultMapper(), options);
231231
}
232232

233233
private CompletableFuture<R> replaceMany(
@@ -250,7 +250,7 @@ private CompletableFuture<R> replaceMany(
250250

251251
@Override
252252
public CompletableFuture<R> select(Conditions conditions) throws TarantoolClientException {
253-
return select(conditions, tupleResultMapper(), ProxySelectOptions.create()
253+
return select(conditions, rowsMetadataTupleResultMapper(), ProxySelectOptions.create()
254254
.withTimeout(config.getRequestTimeout())
255255
);
256256
}
@@ -262,7 +262,7 @@ public CompletableFuture<R> select(
262262
if (options == null) {
263263
throw new IllegalArgumentException("Options should not be null");
264264
}
265-
return select(conditions, tupleResultMapper(), options);
265+
return select(conditions, rowsMetadataTupleResultMapper(), options);
266266
}
267267

268268
private CompletableFuture<R> select(
@@ -286,7 +286,7 @@ private CompletableFuture<R> select(
286286

287287
@Override
288288
public CompletableFuture<R> update(Conditions conditions, T tuple) {
289-
return update(conditions, makeOperationsFromTuple(tuple), tupleResultMapper(), ProxyUpdateOptions.create()
289+
return update(conditions, makeOperationsFromTuple(tuple), rowsMetadataTupleResultMapper(), ProxyUpdateOptions.create()
290290
.withTimeout(config.getRequestTimeout())
291291
);
292292
}
@@ -296,7 +296,7 @@ public CompletableFuture<R> update(Conditions conditions, T tuple, UpdateOptions
296296
if (options == null) {
297297
throw new IllegalArgumentException("Options should not be null");
298298
}
299-
return update(conditions, makeOperationsFromTuple(tuple), tupleResultMapper(), options);
299+
return update(conditions, makeOperationsFromTuple(tuple), rowsMetadataTupleResultMapper(), options);
300300
}
301301

302302
/**
@@ -309,7 +309,7 @@ public CompletableFuture<R> update(Conditions conditions, T tuple, UpdateOptions
309309

310310
@Override
311311
public CompletableFuture<R> update(Conditions conditions, TupleOperations operations) {
312-
return update(conditions, operations, tupleResultMapper(), ProxyUpdateOptions.create()
312+
return update(conditions, operations, rowsMetadataTupleResultMapper(), ProxyUpdateOptions.create()
313313
.withTimeout(config.getRequestTimeout())
314314
);
315315
}
@@ -319,7 +319,7 @@ public CompletableFuture<R> update(Conditions conditions, TupleOperations operat
319319
if (options == null) {
320320
throw new IllegalArgumentException("Options should not be null");
321321
}
322-
return update(conditions, operations, tupleResultMapper(), options);
322+
return update(conditions, operations, rowsMetadataTupleResultMapper(), options);
323323
}
324324

325325
private CompletableFuture<R> update(
@@ -345,7 +345,7 @@ private CompletableFuture<R> update(
345345

346346
@Override
347347
public CompletableFuture<R> upsert(Conditions conditions, T tuple, TupleOperations operations) {
348-
return upsert(conditions, tuple, operations, tupleResultMapper(), ProxyUpsertOptions.create()
348+
return upsert(conditions, tuple, operations, rowsMetadataTupleResultMapper(), ProxyUpsertOptions.create()
349349
.withTimeout(config.getRequestTimeout())
350350
);
351351
}
@@ -357,7 +357,7 @@ public CompletableFuture<R> upsert(
357357
if (options == null) {
358358
throw new IllegalArgumentException("Options should not be null");
359359
}
360-
return upsert(conditions, tuple, operations, tupleResultMapper(), options);
360+
return upsert(conditions, tuple, operations, rowsMetadataTupleResultMapper(), options);
361361
}
362362

363363
private CompletableFuture<R> upsert(
@@ -404,7 +404,7 @@ public CompletableFuture<Void> truncate() throws TarantoolClientException {
404404
*
405405
* @return configured mapper with {@link ArrayValue} to {@code T} converter
406406
*/
407-
protected abstract CallResultMapper<R, SingleValueCallResult<R>> tupleResultMapper();
407+
protected abstract CallResultMapper<R, SingleValueCallResult<R>> rowsMetadataTupleResultMapper();
408408

409409
private CompletableFuture<R> executeOperation(ProxyOperation<R> operation) {
410410
return operation.execute();

src/main/java/io/tarantool/driver/core/space/ProxyTarantoolTupleSpace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ protected TupleOperations makeOperationsFromTuple(TarantoolTuple tuple) {
5252

5353
@Override
5454
protected CallResultMapper<TarantoolResult<TarantoolTuple>, SingleValueCallResult<TarantoolResult<TarantoolTuple>>>
55-
tupleResultMapper() {
55+
rowsMetadataTupleResultMapper() {
5656
return client.getResultMapperFactoryFactory().singleValueTupleResultMapperFactory()
57-
.withSingleValueTarantoolTupleResultMapper(config.getMessagePackMapper(), getMetadata());
57+
.withSingleValueRowsMetadataToTarantoolTupleResultMapper(config.getMessagePackMapper(), getMetadata());
5858
}
5959

6060
@Override

src/main/java/io/tarantool/driver/core/space/TarantoolSpace.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public TarantoolSpace(
6161

6262
@Override
6363
public CompletableFuture<R> delete(Conditions conditions) throws TarantoolClientException {
64-
return delete(conditions, tupleResultMapper());
64+
return delete(conditions, arrayTupleResultMapper());
6565
}
6666

6767
private CompletableFuture<R> delete(Conditions conditions, MessagePackValueMapper resultMapper)
@@ -83,7 +83,7 @@ private CompletableFuture<R> delete(Conditions conditions, MessagePackValueMappe
8383

8484
@Override
8585
public CompletableFuture<R> insert(T tuple) throws TarantoolClientException {
86-
return insert(tuple, tupleResultMapper());
86+
return insert(tuple, arrayTupleResultMapper());
8787
}
8888

8989
@Override
@@ -110,7 +110,7 @@ private CompletableFuture<R> insert(T tuple, MessagePackValueMapper resultMapper
110110

111111
@Override
112112
public CompletableFuture<R> replace(T tuple) throws TarantoolClientException {
113-
return replace(tuple, tupleResultMapper());
113+
return replace(tuple, arrayTupleResultMapper());
114114
}
115115

116116
@Override
@@ -137,7 +137,7 @@ private CompletableFuture<R> replace(T tuple, MessagePackValueMapper resultMappe
137137

138138
@Override
139139
public CompletableFuture<R> select(Conditions conditions) throws TarantoolClientException {
140-
return select(conditions, tupleResultMapper());
140+
return select(conditions, arrayTupleResultMapper());
141141
}
142142

143143
private CompletableFuture<R> select(Conditions conditions, MessagePackValueMapper resultMapper)
@@ -161,7 +161,7 @@ private CompletableFuture<R> select(Conditions conditions, MessagePackValueMappe
161161

162162
@Override
163163
public CompletableFuture<R> update(Conditions conditions, T tuple) {
164-
return update(conditions, makeOperationsFromTuple(tuple), tupleResultMapper());
164+
return update(conditions, makeOperationsFromTuple(tuple), arrayTupleResultMapper());
165165
}
166166

167167
/**
@@ -174,7 +174,7 @@ public CompletableFuture<R> update(Conditions conditions, T tuple) {
174174

175175
@Override
176176
public CompletableFuture<R> update(Conditions conditions, TupleOperations operations) {
177-
return update(conditions, operations, tupleResultMapper());
177+
return update(conditions, operations, arrayTupleResultMapper());
178178
}
179179

180180
private CompletableFuture<R> update(
@@ -207,7 +207,7 @@ private CompletableFuture<R> update(
207207

208208
@Override
209209
public CompletableFuture<R> upsert(Conditions conditions, T tuple, TupleOperations operations) {
210-
return upsert(conditions, tuple, operations, tupleResultMapper());
210+
return upsert(conditions, tuple, operations, arrayTupleResultMapper());
211211
}
212212

213213
private CompletableFuture<R> upsert(
@@ -234,7 +234,7 @@ private CompletableFuture<R> upsert(
234234

235235
@Override
236236
public CompletableFuture<Void> truncate() throws TarantoolClientException {
237-
return truncate(tupleResultMapper());
237+
return truncate(arrayTupleResultMapper());
238238
}
239239

240240
private CompletableFuture<Void> truncate(MessagePackValueMapper resultMapper)
@@ -257,7 +257,7 @@ private CompletableFuture<Void> truncate(MessagePackValueMapper resultMapper)
257257
*
258258
* @return configured mapper with {@link ArrayValue} to {@code T} converter
259259
*/
260-
protected abstract MessagePackValueMapper tupleResultMapper();
260+
protected abstract MessagePackValueMapper arrayTupleResultMapper();
261261

262262
private CompletableFuture<R> sendRequest(TarantoolRequest request, MessagePackValueMapper resultMapper) {
263263
return connectionManager.getConnection().thenCompose(c -> c.sendRequest(request, resultMapper));

src/main/java/io/tarantool/driver/core/space/TarantoolTupleSpace.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ protected TupleOperations makeOperationsFromTuple(TarantoolTuple tuple) {
5050
}
5151

5252
@Override
53-
protected MessagePackValueMapper tupleResultMapper() {
54-
return client.getResultMapperFactoryFactory().tupleResultMapperFactory()
55-
.withFlattenTupleMapper(config.getMessagePackMapper(), getMetadata());
53+
protected MessagePackValueMapper arrayTupleResultMapper() {
54+
return client.getResultMapperFactoryFactory().arrayTupleResultMapperFactory()
55+
.withArrayValueToTarantoolTupleResultConverter(config.getMessagePackMapper(), getMetadata());
5656
}
5757

5858
@Override
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
* @author Alexey Kuzin
1616
* @author Artyom Dubinin
1717
*/
18-
public class RowsMetadataStructureToTarantoolResultMapperFactory<T> extends TarantoolResultMapperFactory<T> {
18+
public class ArrayValueToTarantoolResultMapperFactory<T> extends TarantoolResultMapperFactory<T> {
1919

2020
private final MessagePackMapper messagePackMapper;
2121

2222
/**
2323
* Basic constructor
2424
*/
25-
public RowsMetadataStructureToTarantoolResultMapperFactory() {
25+
public ArrayValueToTarantoolResultMapperFactory() {
2626
this(DefaultMessagePackMapperFactory.getInstance().emptyMapper());
2727
}
2828

@@ -31,7 +31,7 @@ public RowsMetadataStructureToTarantoolResultMapperFactory() {
3131
*
3232
* @param messagePackMapper MessagePack-to-object mapper for tuple contents
3333
*/
34-
public RowsMetadataStructureToTarantoolResultMapperFactory(MessagePackMapper messagePackMapper) {
34+
public ArrayValueToTarantoolResultMapperFactory(MessagePackMapper messagePackMapper) {
3535
super();
3636
this.messagePackMapper = messagePackMapper;
3737
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package io.tarantool.driver.mappers.factories;
2+
3+
import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
4+
import io.tarantool.driver.api.tuple.TarantoolTuple;
5+
import io.tarantool.driver.mappers.MessagePackMapper;
6+
import io.tarantool.driver.mappers.MessagePackValueMapper;
7+
import io.tarantool.driver.mappers.TarantoolResultMapper;
8+
import io.tarantool.driver.mappers.converters.value.ArrayValueToTarantoolTupleConverter;
9+
import io.tarantool.driver.mappers.converters.value.ArrayValueToTarantoolTupleResultConverter;
10+
import org.msgpack.value.ValueType;
11+
12+
/**
13+
* Factory for {@link TarantoolResultMapper} instances used for handling results with tuples of array type
14+
*
15+
* @author Alexey Kuzin
16+
* @author Artyom Dubinin
17+
*/
18+
public class ArrayValueToTarantoolTupleResultMapperFactory
19+
extends ArrayValueToTarantoolResultMapperFactory<TarantoolTuple> {
20+
21+
private final MessagePackMapper messagePackMapper;
22+
23+
/**
24+
* Basic constructor
25+
*/
26+
public ArrayValueToTarantoolTupleResultMapperFactory() {
27+
this(DefaultMessagePackMapperFactory.getInstance().emptyMapper());
28+
}
29+
30+
/**
31+
* Basic constructor with mapper
32+
*
33+
* @param messagePackMapper MessagePack-to-object mapper for tuple contents
34+
*/
35+
public ArrayValueToTarantoolTupleResultMapperFactory(MessagePackMapper messagePackMapper) {
36+
super();
37+
this.messagePackMapper = messagePackMapper;
38+
}
39+
40+
public TarantoolResultMapper<TarantoolTuple> withArrayValueToTarantoolTupleResultConverter(
41+
MessagePackMapper messagePackMapper) {
42+
return withArrayValueToTarantoolTupleResultConverter(
43+
new ArrayValueToTarantoolTupleConverter(messagePackMapper, null));
44+
}
45+
46+
public TarantoolResultMapper<TarantoolTuple> withArrayValueToTarantoolTupleResultConverter(
47+
MessagePackMapper messagePackMapper, TarantoolSpaceMetadata spaceMetadata) {
48+
return withArrayValueToTarantoolTupleResultConverter(
49+
new ArrayValueToTarantoolTupleConverter(messagePackMapper, spaceMetadata));
50+
}
51+
52+
public TarantoolResultMapper<TarantoolTuple> withArrayValueToTarantoolTupleResultConverter(
53+
ArrayValueToTarantoolTupleConverter tupleConverter) {
54+
return withConverterWithoutTargetClass(
55+
messagePackMapper.copy(),
56+
ValueType.ARRAY,
57+
new ArrayValueToTarantoolTupleResultConverter(tupleConverter)
58+
);
59+
}
60+
61+
public TarantoolResultMapper<TarantoolTuple> withArrayValueToTarantoolTupleResultConverter(
62+
MessagePackValueMapper valueMapper,
63+
ArrayValueToTarantoolTupleConverter tupleConverter) {
64+
return withConverterWithoutTargetClass(
65+
valueMapper,
66+
ValueType.ARRAY,
67+
new ArrayValueToTarantoolTupleResultConverter(tupleConverter)
68+
);
69+
}
70+
}

src/main/java/io/tarantool/driver/mappers/factories/MultiValueWithTarantoolResultMapperFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
public class MultiValueWithTarantoolResultMapperFactory<T>
2020
extends MultiValueResultMapperFactory<T, TarantoolResult<T>> {
2121

22-
private final RowsMetadataStructureToTarantoolResultMapperFactory<T> tarantoolResultMapperFactory;
22+
private final ArrayValueToTarantoolResultMapperFactory<T> tarantoolResultMapperFactory;
2323

2424
/**
2525
* Basic constructor
2626
*/
2727
public MultiValueWithTarantoolResultMapperFactory() {
2828
super();
29-
tarantoolResultMapperFactory = new RowsMetadataStructureToTarantoolResultMapperFactory<>();
29+
tarantoolResultMapperFactory = new ArrayValueToTarantoolResultMapperFactory<>();
3030
}
3131

3232
/**
@@ -36,7 +36,7 @@ public MultiValueWithTarantoolResultMapperFactory() {
3636
*/
3737
public MultiValueWithTarantoolResultMapperFactory(MessagePackMapper messagePackMapper) {
3838
super(messagePackMapper);
39-
tarantoolResultMapperFactory = new RowsMetadataStructureToTarantoolResultMapperFactory<>();
39+
tarantoolResultMapperFactory = new ArrayValueToTarantoolResultMapperFactory<>();
4040
}
4141

4242
/**

0 commit comments

Comments
 (0)