diff --git a/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java b/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java index 477dab07d..908c55c2d 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java @@ -8,14 +8,7 @@ * @author Alexey Kuzin */ public interface InsertManyOptions> - extends OperationWithTimeoutOptions, OperationWithFieldsOptions { - /** - * Return whether all changes should not be saved if any tuple insertion - * was unsuccesful. - * - * @return true, if the operation should rollback on error - */ - Optional getRollbackOnError(); + extends OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithRollbackOnErrorOptions { /** * Return whether the operation should be interrupted if any tuple insertion diff --git a/src/main/java/io/tarantool/driver/api/space/options/OperationWithRollbackOnErrorOptions.java b/src/main/java/io/tarantool/driver/api/space/options/OperationWithRollbackOnErrorOptions.java new file mode 100644 index 000000000..76c279f90 --- /dev/null +++ b/src/main/java/io/tarantool/driver/api/space/options/OperationWithRollbackOnErrorOptions.java @@ -0,0 +1,36 @@ +package io.tarantool.driver.api.space.options; + + +import io.tarantool.driver.api.space.options.enums.crud.RollbackOnError; + +import java.util.Optional; + +/** + * Base interface for all operation options that may have a configurable rollback_on_error. + * + * @author Belonogov Nikolay + */ +public interface OperationWithRollbackOnErrorOptions> + extends Options, Self { + /** + * Specifies whether to not save any changes in the space if any tuple replace operation + * is unsuccesful. Default value is true. + * + * @param rollbackOnError should rollback batch on error + * @return this options instance + */ + default T withRollbackOnError(RollbackOnError rollbackOnError) { + addOption(RollbackOnError.NAME, rollbackOnError.value()); + return self(); + } + + /** + * Return whether all changes should not be saved if any tuple replace + * was unsuccesful. + * + * @return true, if the operation should rollback on error + */ + default Optional getRollbackOnError() { + return getOption(RollbackOnError.NAME, Boolean.class); + } +} diff --git a/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java b/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java index 0352bf80e..898b4d795 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java @@ -8,14 +8,7 @@ * @author Alexey Kuzin */ public interface ReplaceManyOptions> - extends OperationWithTimeoutOptions, OperationWithFieldsOptions { - /** - * Return whether all changes should not be saved if any tuple replace - * was unsuccesful. - * - * @return true, if the operation should rollback on error - */ - Optional getRollbackOnError(); + extends OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithRollbackOnErrorOptions { /** * Return whether the operation should be interrupted if any tuple replace diff --git a/src/main/java/io/tarantool/driver/api/space/options/enums/crud/RollbackOnError.java b/src/main/java/io/tarantool/driver/api/space/options/enums/crud/RollbackOnError.java new file mode 100644 index 000000000..2dec6b384 --- /dev/null +++ b/src/main/java/io/tarantool/driver/api/space/options/enums/crud/RollbackOnError.java @@ -0,0 +1,30 @@ +package io.tarantool.driver.api.space.options.enums.crud; + +/** + * Enum represents the CRUD predefined rollback_on_error option values. + * + * @author Belonogov Nikolay. + * @see tarantool/crud. + */ +public enum RollbackOnError { + + TRUE(true), + + FALSE(false); + + public static final String NAME = "rollback_on_error"; + private final boolean value; + + RollbackOnError(boolean value) { + this.value = value; + } + + public boolean value() { + return this.value; + } + + @Override + public String toString() { + return Boolean.toString(this.value); + } +} diff --git a/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyInsertManyOptions.java b/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyInsertManyOptions.java index 5d70b8113..2474c6312 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyInsertManyOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyInsertManyOptions.java @@ -1,7 +1,7 @@ package io.tarantool.driver.api.space.options.proxy; -import io.tarantool.driver.api.space.options.InsertManyOptions; import io.tarantool.driver.api.space.options.BaseOptions; +import io.tarantool.driver.api.space.options.InsertManyOptions; import java.util.Optional; @@ -13,7 +13,6 @@ public final class ProxyInsertManyOptions extends BaseOptions implements InsertManyOptions { - public static final String ROLLBACK_ON_ERROR = "rollback_on_error"; public static final String STOP_ON_ERROR = "stop_on_error"; private ProxyInsertManyOptions() { @@ -28,18 +27,6 @@ public static ProxyInsertManyOptions create() { return new ProxyInsertManyOptions(); } - /** - * Specifies whether to not save any changes in the space if any tuple insert operation - * is unsuccesful. Default value is true. - * - * @param rollbackOnError should rollback batch on error - * @return this options instance - */ - public ProxyInsertManyOptions withRollbackOnError(boolean rollbackOnError) { - addOption(ROLLBACK_ON_ERROR, rollbackOnError); - return self(); - } - /** * Specifies whether to not try to insert more tuples into the space if any tuple insert * operation is unsuccesful. Default value is true. @@ -57,11 +44,6 @@ public ProxyInsertManyOptions self() { return this; } - @Override - public Optional getRollbackOnError() { - return getOption(ROLLBACK_ON_ERROR, Boolean.class); - } - @Override public Optional getStopOnError() { return getOption(STOP_ON_ERROR, Boolean.class); diff --git a/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyReplaceManyOptions.java b/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyReplaceManyOptions.java index 0badd50bf..748cdc6ce 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyReplaceManyOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/proxy/ProxyReplaceManyOptions.java @@ -13,7 +13,6 @@ public final class ProxyReplaceManyOptions extends BaseOptions implements ReplaceManyOptions { - public static final String ROLLBACK_ON_ERROR = "rollback_on_error"; public static final String STOP_ON_ERROR = "stop_on_error"; private ProxyReplaceManyOptions() { @@ -28,18 +27,6 @@ public static ProxyReplaceManyOptions create() { return new ProxyReplaceManyOptions(); } - /** - * Specifies whether to not save any changes in the space if any tuple replace operation - * is unsuccesful. Default value is true. - * - * @param rollbackOnError should rollback batch on error - * @return this options instance - */ - public ProxyReplaceManyOptions withRollbackOnError(boolean rollbackOnError) { - addOption(ROLLBACK_ON_ERROR, rollbackOnError); - return self(); - } - /** * Specifies whether to not try to replace more tuples into the space if any tuple replace * operation is unsuccesful. Default value is true. @@ -57,11 +44,6 @@ public ProxyReplaceManyOptions self() { return this; } - @Override - public Optional getRollbackOnError() { - return getOption(ROLLBACK_ON_ERROR, Boolean.class); - } - @Override public Optional getStopOnError() { return getOption(STOP_ON_ERROR, Boolean.class); diff --git a/src/main/java/io/tarantool/driver/core/space/ProxyTarantoolSpace.java b/src/main/java/io/tarantool/driver/core/space/ProxyTarantoolSpace.java index ebe65ea57..d55deaf1b 100644 --- a/src/main/java/io/tarantool/driver/core/space/ProxyTarantoolSpace.java +++ b/src/main/java/io/tarantool/driver/core/space/ProxyTarantoolSpace.java @@ -16,6 +16,7 @@ import io.tarantool.driver.api.space.options.SelectOptions; import io.tarantool.driver.api.space.options.UpdateOptions; import io.tarantool.driver.api.space.options.UpsertOptions; +import io.tarantool.driver.api.space.options.enums.crud.RollbackOnError; import io.tarantool.driver.api.space.options.proxy.ProxyDeleteOptions; import io.tarantool.driver.api.space.options.proxy.ProxyInsertManyOptions; import io.tarantool.driver.api.space.options.proxy.ProxyInsertOptions; @@ -144,7 +145,7 @@ private CompletableFuture insert( public CompletableFuture insertMany(Collection tuples) { return insertMany(tuples, rowsMetadataTupleResultMapper(), ProxyInsertManyOptions.create() .withStopOnError(true) - .withRollbackOnError(true) + .withRollbackOnError(RollbackOnError.TRUE) ); } @@ -210,7 +211,7 @@ private CompletableFuture replace( public CompletableFuture replaceMany(Collection tuples) throws TarantoolClientException { return replaceMany(tuples, rowsMetadataTupleResultMapper(), ProxyReplaceManyOptions.create() .withStopOnError(true) - .withRollbackOnError(true) + .withRollbackOnError(RollbackOnError.TRUE) ); } diff --git a/src/test/java/io/tarantool/driver/core/proxy/ProxyOperationBuildersTest.java b/src/test/java/io/tarantool/driver/core/proxy/ProxyOperationBuildersTest.java index 1961a6681..6fb850b24 100644 --- a/src/test/java/io/tarantool/driver/core/proxy/ProxyOperationBuildersTest.java +++ b/src/test/java/io/tarantool/driver/core/proxy/ProxyOperationBuildersTest.java @@ -4,6 +4,7 @@ import io.tarantool.driver.api.TarantoolResult; import io.tarantool.driver.api.conditions.Conditions; import io.tarantool.driver.api.space.options.enums.crud.Mode; +import io.tarantool.driver.api.space.options.enums.crud.RollbackOnError; import io.tarantool.driver.api.space.options.proxy.ProxyDeleteOptions; import io.tarantool.driver.api.space.options.proxy.ProxyInsertManyOptions; import io.tarantool.driver.api.space.options.proxy.ProxyInsertOptions; @@ -122,7 +123,7 @@ public void insertManyOperationBuilderTest() { .withArgumentsMapper(defaultMapper) .withOptions(ProxyInsertManyOptions.create() .withTimeout(client.getConfig().getRequestTimeout()) - .withRollbackOnError(true) + .withRollbackOnError(RollbackOnError.TRUE) .withStopOnError(false) ) .build(); @@ -182,7 +183,7 @@ public void replaceManyOperationBuilderTest() { .withArgumentsMapper(defaultMapper) .withOptions(ProxyReplaceManyOptions.create() .withTimeout(client.getConfig().getRequestTimeout()) - .withRollbackOnError(true) + .withRollbackOnError(RollbackOnError.TRUE) .withStopOnError(false) ) .build(); diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java index 713353186..39862a692 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java @@ -6,8 +6,8 @@ import io.tarantool.driver.api.conditions.Conditions; import io.tarantool.driver.api.space.TarantoolSpaceOperations; import io.tarantool.driver.api.space.options.InsertManyOptions; +import io.tarantool.driver.api.space.options.enums.crud.RollbackOnError; import io.tarantool.driver.api.space.options.proxy.ProxyInsertManyOptions; -import io.tarantool.driver.api.space.options.proxy.ProxyReplaceManyOptions; import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory; import io.tarantool.driver.api.tuple.TarantoolTuple; import io.tarantool.driver.api.tuple.TarantoolTupleFactory; @@ -101,7 +101,7 @@ public void withStopOnError_withRollbackOnError() throws ExecutionException, Int profileSpace.insertMany( tarantoolTuples, ProxyInsertManyOptions.create() - .withRollbackOnError(false) + .withRollbackOnError(RollbackOnError.FALSE) .withStopOnError(false) ).get(); crudInsertManyOpts = client.eval("return crud_insert_many_opts").get(); diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java index 20e9ea6fa..c04a5956a 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java @@ -5,6 +5,7 @@ import io.tarantool.driver.api.TarantoolResult; import io.tarantool.driver.api.space.TarantoolSpaceOperations; import io.tarantool.driver.api.space.options.ReplaceManyOptions; +import io.tarantool.driver.api.space.options.enums.crud.RollbackOnError; import io.tarantool.driver.api.space.options.proxy.ProxyReplaceManyOptions; import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory; import io.tarantool.driver.api.tuple.TarantoolTuple; @@ -92,7 +93,7 @@ public void withStopOnError_withRollbackOnError() throws ExecutionException, Int profileSpace.replaceMany( tarantoolTuples, ProxyReplaceManyOptions.create() - .withRollbackOnError(false) + .withRollbackOnError(RollbackOnError.FALSE) .withStopOnError(false) ).get(); crudReplaceManyOpts = client.eval("return crud_replace_many_opts").get();