-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RollbackOnError enum and refactor public proxy API with it
- Loading branch information
Showing
10 changed files
with
79 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/io/tarantool/driver/api/space/options/OperationWithRollbackOnErrorOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T extends OperationWithRollbackOnErrorOptions<T>> | ||
extends Options, Self<T> { | ||
/** | ||
* Specifies whether to not save any changes in the space if any tuple replace operation | ||
* is unsuccesful. Default value is <code>true</code>. | ||
* | ||
* @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<Boolean> getRollbackOnError() { | ||
return getOption(RollbackOnError.NAME, Boolean.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/io/tarantool/driver/api/space/options/enums/crud/RollbackOnError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="https://github.com/tarantool/crud">tarantool/crud</a>. | ||
*/ | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters