-
Notifications
You must be signed in to change notification settings - Fork 13
Use mappers for parsing TarantoolResult instead of single converter #300
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
Changes from all commits
2bd8bc2
e069798
376f706
b6c6749
24a139b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import io.tarantool.driver.api.SingleValueCallResult; | ||
| import io.tarantool.driver.exceptions.TarantoolFunctionCallException; | ||
| import io.tarantool.driver.exceptions.errors.TarantoolErrorsParser; | ||
| import io.tarantool.driver.mappers.MessagePackValueMapper; | ||
| import io.tarantool.driver.mappers.converters.ValueConverter; | ||
| import org.msgpack.value.ArrayValue; | ||
| import org.msgpack.value.Value; | ||
|
|
@@ -12,6 +13,7 @@ | |
| * {@code null}, the second is treated as a formatted error or an error message. | ||
| * | ||
| * @author Alexey Kuzin | ||
| * @author Artyom Dubinin | ||
| */ | ||
| public class SingleValueCallResultImpl<T> implements SingleValueCallResult<T> { | ||
|
|
||
|
|
@@ -33,6 +35,22 @@ public SingleValueCallResultImpl(ArrayValue result, ValueConverter<Value, T> val | |
| } | ||
| } | ||
|
|
||
| public SingleValueCallResultImpl(ArrayValue result, MessagePackValueMapper valueMapper) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same question as for the multi result implementation, we need to either remove the constructor with converter or make them both reusing the same code
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need it when we pass only one converter to parsing. For example, we parse callForSingleiResult with one converter on the top of stack |
||
| if (result == null) { | ||
| throw new TarantoolFunctionCallException("Function call result is null"); | ||
| } | ||
| if (result.size() == 0 || result.size() == 1 && result.get(0).isNilValue()) { | ||
| // [nil] or [] | ||
| value = null; | ||
| } else if (result.size() == 2 && (result.get(0).isNilValue() && !result.get(1).isNilValue())) { | ||
| // [nil, "Error msg..."] or [nil, {str="Error msg...", stack="..."}] | ||
| throw TarantoolErrorsParser.parse(result.get(1)); | ||
| } else { | ||
| // [result] | ||
| value = valueMapper.fromValue(result.get(0)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public T value() { | ||
| return value; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the existing method once we have this new one? We need either to remove the former one or to refactor them in a way that eliminates the copy-paste.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need it when we pass only one converter to parsing. We parse callForMultiResult with one converter on the top of stack