Skip to content

Commit

Permalink
Use suppliers instead of mappers in eval and space operations
Browse files Browse the repository at this point in the history
This change is breaking and it is required for making on-demand mapper
instantiation only in cases if the corresponding mapper is not found in
the mapper cache (will be done later).
  • Loading branch information
akudiyar committed Aug 23, 2023
1 parent ad0eb60 commit 4526101
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
* Aggregates all value operation variants
Expand Down Expand Up @@ -42,11 +43,11 @@ public interface TarantoolEvalOperations {
* keyword <code>return</code>.
*
* @param expression lua expression, must not be null or empty
* @param resultMapper mapper for result value MessagePack entity-to-object conversion
* @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected
*/
CompletableFuture<List<?>> eval(String expression, MessagePackValueMapper resultMapper)
CompletableFuture<List<?>> eval(String expression, Supplier<MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException;

/**
Expand All @@ -56,11 +57,12 @@ CompletableFuture<List<?>> eval(String expression, MessagePackValueMapper result
* @param expression lua expression, must not be null or empty
* @param arguments the list of function arguments. The object mapper specified in the client configuration
* will be used for arguments conversion to MessagePack entities
* @param resultMapper mapper for result value MessagePack entity-to-object conversion
* @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected
*/
CompletableFuture<List<?>> eval(String expression, List<?> arguments, MessagePackValueMapper resultMapper)
CompletableFuture<List<?>> eval(
String expression, List<?> arguments, Supplier<MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException;

/**
Expand All @@ -70,13 +72,13 @@ CompletableFuture<List<?>> eval(String expression, List<?> arguments, MessagePac
* @param expression lua expression, must not be null or empty
* @param arguments the list of function arguments
* @param argumentsMapper mapper for arguments object-to-MessagePack entity conversion
* @param resultMapper mapper for result value MessagePack entity-to-object conversion
* @param resultMapperSupplier mapper supplier for result value MessagePack entity-to-object conversion
* @return some result
* @throws TarantoolClientException if the client is not connected
*/
CompletableFuture<List<?>> eval(
String expression,
List<?> arguments,
MessagePackObjectMapper argumentsMapper,
MessagePackValueMapper resultMapper) throws TarantoolClientException;
Supplier<MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,32 +517,34 @@ public CompletableFuture<List<?>> eval(String expression) throws TarantoolClient
@Override
public CompletableFuture<List<?>> eval(String expression, List<?> arguments)
throws TarantoolClientException {
return eval(expression, arguments, config.getMessagePackMapper());
return eval(expression, arguments, config::getMessagePackMapper);
}

@Override
public CompletableFuture<List<?>> eval(String expression, MessagePackValueMapper resultMapper)
public CompletableFuture<List<?>> eval(String expression, Supplier<MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
return eval(expression, Collections.emptyList(), resultMapper);
return eval(expression, Collections.emptyList(), resultMapperSupplier);
}

@Override
public CompletableFuture<List<?>> eval(String expression, List<?> arguments, MessagePackValueMapper resultMapper)
public CompletableFuture<List<?>> eval(
String expression, List<?> arguments, Supplier<MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
return eval(expression, arguments, config.getMessagePackMapper(), resultMapper);
return eval(expression, arguments, config.getMessagePackMapper(), resultMapperSupplier);
}

@Override
public CompletableFuture<List<?>> eval(
String expression,
List<?> arguments,
MessagePackObjectMapper argumentsMapper,
MessagePackValueMapper resultMapper) throws TarantoolClientException {
Supplier<MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException {
try {
TarantoolEvalRequest request = new TarantoolEvalRequest.Builder()
.withExpression(expression)
.withArguments(arguments)
.build(argumentsMapper);
MessagePackValueMapper resultMapper = resultMapperSupplier.get();
return connectionManager().getConnection()
.thenCompose(c -> c.sendRequest(request).getFuture())
.thenApply(resultMapper::fromValue);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/io/tarantool/driver/core/ProxyTarantoolClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,24 +391,25 @@ public CompletableFuture<List<?>> eval(String expression, List<?> arguments) thr
}

@Override
public CompletableFuture<List<?>> eval(String expression, MessagePackValueMapper resultMapper)
public CompletableFuture<List<?>> eval(String expression, Supplier<MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
return client.eval(expression, resultMapper);
return client.eval(expression, resultMapperSupplier);
}

@Override
public CompletableFuture<List<?>> eval(String expression, List<?> arguments, MessagePackValueMapper resultMapper)
public CompletableFuture<List<?>> eval(
String expression, List<?> arguments, Supplier<MessagePackValueMapper> resultMapperSupplier)
throws TarantoolClientException {
return client.eval(expression, arguments, resultMapper);
return client.eval(expression, arguments, resultMapperSupplier);
}

@Override
public CompletableFuture<List<?>> eval(
String expression,
List<?> arguments,
MessagePackObjectMapper argumentsMapper,
MessagePackValueMapper resultMapper) throws TarantoolClientException {
return client.eval(expression, arguments, argumentsMapper, resultMapper);
Supplier<MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException {
return client.eval(expression, arguments, argumentsMapper, resultMapperSupplier);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,24 +369,24 @@ public CompletableFuture<List<?>> eval(String expression, List<?> arguments) thr
@Override
public CompletableFuture<List<?>> eval(
String expression,
MessagePackValueMapper resultMapper) throws TarantoolClientException {
return wrapOperation(() -> client.eval(expression, resultMapper));
Supplier<MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException {
return wrapOperation(() -> client.eval(expression, resultMapperSupplier));
}

@Override
public CompletableFuture<List<?>> eval(
String expression,
List<?> arguments,
MessagePackValueMapper resultMapper) throws TarantoolClientException {
return wrapOperation(() -> client.eval(expression, arguments, resultMapper));
Supplier<MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException {
return wrapOperation(() -> client.eval(expression, arguments, resultMapperSupplier));
}

@Override
public CompletableFuture<List<?>> eval(
String expression, List<?> arguments,
MessagePackObjectMapper argumentsMapper,
MessagePackValueMapper resultMapper) throws TarantoolClientException {
return wrapOperation(() -> client.eval(expression, arguments, argumentsMapper, resultMapper));
Supplier<MessagePackValueMapper> resultMapperSupplier) throws TarantoolClientException {
return wrapOperation(() -> client.eval(expression, arguments, argumentsMapper, resultMapperSupplier));
}

@Override
Expand Down
Loading

0 comments on commit 4526101

Please sign in to comment.