Skip to content

Commit 058f5e0

Browse files
committed
Refactor mappers and split TResultConverters
Closes #301
1 parent c0f6f2b commit 058f5e0

File tree

91 files changed

+1278
-643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1278
-643
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
- Refactor mappers and split TarantoolResultConverter ([#301](https://github.com/tarantool/cartridge-java/pull/301))
6+
57
## [0.9.2] - 2022-11-15
68

79
- Adding default mapper for long arrays ([#290](https://github.com/tarantool/cartridge-java/pull/290))

src/main/java/io/tarantool/driver/api/TarantoolCallOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.tarantool.driver.mappers.CallResultMapper;
55
import io.tarantool.driver.mappers.MessagePackMapper;
66
import io.tarantool.driver.mappers.MessagePackObjectMapper;
7-
import io.tarantool.driver.mappers.ResultMapperFactoryFactory;
7+
import io.tarantool.driver.mappers.factories.ResultMapperFactoryFactory;
88
import io.tarantool.driver.mappers.converters.ValueConverter;
99
import org.msgpack.value.Value;
1010

src/main/java/io/tarantool/driver/api/TarantoolClientBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.tarantool.driver.auth.TarantoolCredentials;
88
import io.tarantool.driver.mappers.DefaultMessagePackMapper;
99
import io.tarantool.driver.mappers.MessagePackMapper;
10+
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory;
1011

1112
import java.net.InetSocketAddress;
1213
import java.util.List;
@@ -112,7 +113,7 @@ public interface TarantoolClientBuilder extends TarantoolClientConfigurator<Tara
112113
* <p>
113114
* This method takes a lambda as an argument, where the mapperBuilder is {@link DefaultMessagePackMapper.Builder}.
114115
* </p>
115-
* see {@link io.tarantool.driver.mappers.DefaultMessagePackMapperFactory}.
116+
* see {@link DefaultMessagePackMapperFactory}.
116117
*
117118
* @param mapperBuilder builder provider instance, e.g. a lambda function taking the builder
118119
* for {@link MessagePackMapper} instance
@@ -127,7 +128,7 @@ public interface TarantoolClientBuilder extends TarantoolClientConfigurator<Tara
127128
* The mapper contains converters for simple and complex tuple field types and for the entire tuples into custom
128129
* Java objects. This mapper is used by default if a custom mapper is not passed to a specific operation.
129130
* You may build and pass here your custom mapper or add some converters to a default one,
130-
* see {@link io.tarantool.driver.mappers.DefaultMessagePackMapperFactory}.
131+
* see {@link DefaultMessagePackMapperFactory}.
131132
*
132133
* @param mapper configured {@link MessagePackMapper} instance
133134
* @return this instance of builder {@link TarantoolClientBuilder}

src/main/java/io/tarantool/driver/api/TarantoolClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.tarantool.driver.api.connection.TarantoolConnectionSelectionStrategies;
66
import io.tarantool.driver.auth.SimpleTarantoolCredentials;
77
import io.tarantool.driver.auth.TarantoolCredentials;
8-
import io.tarantool.driver.mappers.DefaultMessagePackMapperFactory;
8+
import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory;
99
import io.tarantool.driver.mappers.MessagePackMapper;
1010
import io.tarantool.driver.utils.Assert;
1111

src/main/java/io/tarantool/driver/api/tuple/TarantoolTupleMultiResult.java renamed to src/main/java/io/tarantool/driver/api/tuple/TarantoolMultiTuplesResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Shortcut for {@link MultiValueCallResult} with default tuple result
88
*
99
* @author Alexey Kuzin
10-
* @see TarantoolTupleResult
10+
* @see TarantoolTuplesResult
1111
*/
12-
public interface TarantoolTupleMultiResult
12+
public interface TarantoolMultiTuplesResult
1313
extends MultiValueCallResult<TarantoolTuple, TarantoolResult<TarantoolTuple>> {
1414
}

src/main/java/io/tarantool/driver/api/tuple/TarantoolTupleSingleResult.java renamed to src/main/java/io/tarantool/driver/api/tuple/TarantoolSingleTuplesResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Shortcut for {@link SingleValueCallResult} with default tuple result
88
*
99
* @author Alexey Kuzin
10-
* @see TarantoolTupleResult
10+
* @see TarantoolTuplesResult
1111
*/
12-
public interface TarantoolTupleSingleResult extends SingleValueCallResult<TarantoolResult<TarantoolTuple>> {
12+
public interface TarantoolSingleTuplesResult extends SingleValueCallResult<TarantoolResult<TarantoolTuple>> {
1313
}

src/main/java/io/tarantool/driver/api/tuple/TarantoolTupleResult.java renamed to src/main/java/io/tarantool/driver/api/tuple/TarantoolTuplesResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
*
88
* @author Alexey Kuzin
99
*/
10-
public interface TarantoolTupleResult extends TarantoolResult<TarantoolTuple> {
10+
public interface TarantoolTuplesResult extends TarantoolResult<TarantoolTuple> {
1111
}

src/main/java/io/tarantool/driver/core/AbstractTarantoolClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import io.tarantool.driver.exceptions.TarantoolClientException;
2626
import io.tarantool.driver.exceptions.TarantoolSpaceNotFoundException;
2727
import io.tarantool.driver.mappers.CallResultMapper;
28-
import io.tarantool.driver.mappers.DefaultResultMapperFactoryFactory;
28+
import io.tarantool.driver.mappers.factories.DefaultResultMapperFactoryFactory;
2929
import io.tarantool.driver.mappers.MessagePackMapper;
3030
import io.tarantool.driver.mappers.MessagePackObjectMapper;
3131
import io.tarantool.driver.mappers.MessagePackValueMapper;
32-
import io.tarantool.driver.mappers.ResultMapperFactoryFactory;
32+
import io.tarantool.driver.mappers.factories.ResultMapperFactoryFactory;
3333
import io.tarantool.driver.mappers.converters.ValueConverter;
3434
import io.tarantool.driver.protocol.Packable;
3535
import io.tarantool.driver.protocol.TarantoolProtocolException;

src/main/java/io/tarantool/driver/core/MultiValueCallResultImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.tarantool.driver.api.MultiValueCallResult;
44
import io.tarantool.driver.exceptions.TarantoolFunctionCallException;
55
import io.tarantool.driver.exceptions.errors.TarantoolErrorsParser;
6+
import io.tarantool.driver.mappers.MessagePackValueMapper;
67
import io.tarantool.driver.mappers.converters.ValueConverter;
78
import org.msgpack.value.ArrayValue;
89
import org.msgpack.value.Value;
@@ -14,6 +15,7 @@
1415
* {@code null}, the second is treated as a formatted error or an error message.
1516
*
1617
* @author Alexey Kuzin
18+
* @author Artyom Dubinin
1719
*/
1820
public class MultiValueCallResultImpl<T, R extends List<T>> implements MultiValueCallResult<T, R> {
1921

@@ -36,6 +38,23 @@ public MultiValueCallResultImpl(Value result, ValueConverter<ArrayValue, R> valu
3638
}
3739
}
3840

41+
public MultiValueCallResultImpl(Value result, MessagePackValueMapper valueMapper) {
42+
if (result == null) {
43+
throw new TarantoolFunctionCallException("Function call result is null");
44+
}
45+
if (!result.isArrayValue()) {
46+
throw new TarantoolFunctionCallException("Function call result is not a MessagePack array");
47+
}
48+
ArrayValue resultArray = result.asArrayValue();
49+
if (resultArray.size() == 2 && (resultArray.get(0).isNilValue() && !resultArray.get(1).isNilValue())) {
50+
// [nil, "Error msg..."] or [nil, {str="Error msg...", stack="..."}]
51+
throw TarantoolErrorsParser.parse(resultArray.get(1));
52+
} else {
53+
// result
54+
this.value = valueMapper.fromValue(result.asArrayValue());
55+
}
56+
}
57+
3958
@Override
4059
public R value() {
4160
return value;

src/main/java/io/tarantool/driver/core/ProxyTarantoolClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import io.tarantool.driver.mappers.MessagePackMapper;
2424
import io.tarantool.driver.mappers.MessagePackObjectMapper;
2525
import io.tarantool.driver.mappers.MessagePackValueMapper;
26-
import io.tarantool.driver.mappers.ResultMapperFactoryFactory;
26+
import io.tarantool.driver.mappers.factories.ResultMapperFactoryFactory;
2727
import io.tarantool.driver.mappers.converters.ValueConverter;
2828
import io.tarantool.driver.protocol.Packable;
2929
import io.tarantool.driver.utils.Assert;

0 commit comments

Comments
 (0)