Class Transaction.Builder
java.lang.Object
com.loomcache.server.transaction.Transaction.Builder
- Enclosing class:
Transaction
Fluent builder for constructing transactions.
Usage Example:
Transaction txn = Transaction.builder()
.ifExists("mykey")
.thenPut("counter", "1")
.elsePut("counter", "0")
.build();
- Since:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns the completed transaction.elseDelete(String key) Add an ELSE operation: delete a key.elseDeleteInMap(String mapName, String key) Add an ELSE operation: get a key's value.elseGetInMap(String mapName, String key) Add an ELSE operation: put a key-value pair.elsePutInMap(String mapName, String key, String value) Adds a condition: key must exist.ifExistsInMap(String mapName, String key) ifNotExists(String key) Adds a condition: key must not exist.ifNotExistsInMap(String mapName, String key) ifValueEquals(String key, @Nullable String expectedValue) Adds a condition: key's value must equal the expected value.ifValueEqualsInMap(String mapName, String key, @Nullable String expectedValue) thenDelete(String key) Adds a THEN operation: delete a key.thenDeleteInMap(String mapName, String key) Adds a THEN operation: get and return a key's value.thenGetInMap(String mapName, String key) Adds a THEN operation: put a key-value pair.thenPutInMap(String mapName, String key, String value)
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
ifExists
Adds a condition: key must exist.- Parameters:
key- the key to check (must not be null)- Returns:
- this builder for method chaining
- Throws:
NullPointerException- if key is null
-
ifNotExists
Adds a condition: key must not exist.- Parameters:
key- the key to check (must not be null)- Returns:
- this builder for method chaining
- Throws:
NullPointerException- if key is null
-
ifValueEquals
Adds a condition: key's value must equal the expected value.- Parameters:
key- the key to check (must not be null)expectedValue- the expected value (can be null)- Returns:
- this builder for method chaining
- Throws:
NullPointerException- if key is null
-
ifExistsInMap
-
ifNotExistsInMap
-
ifValueEqualsInMap
public Transaction.Builder ifValueEqualsInMap(String mapName, String key, @Nullable String expectedValue) -
thenPut
Adds a THEN operation: put a key-value pair.- Parameters:
key- the key to put (must not be null)value- the value to set (must not be null)- Returns:
- this builder for method chaining
- Throws:
NullPointerException- if key or value is null
-
thenDelete
Adds a THEN operation: delete a key.- Parameters:
key- the key to delete (must not be null)- Returns:
- this builder for method chaining
- Throws:
NullPointerException- if key is null
-
thenGet
Adds a THEN operation: get and return a key's value.- Parameters:
key- the key to read (must not be null)- Returns:
- this builder for method chaining
- Throws:
NullPointerException- if key is null
-
elsePut
Add an ELSE operation: put a key-value pair.- Parameters:
key- the key to putvalue- the value to set- Returns:
- this builder for chaining
- Throws:
NullPointerException- if key or value is null
-
elseDelete
Add an ELSE operation: delete a key.- Parameters:
key- the key to delete- Returns:
- this builder for chaining
- Throws:
NullPointerException- if key is null
-
elseGet
Add an ELSE operation: get a key's value.- Parameters:
key- the key to read- Returns:
- this builder for chaining
- Throws:
NullPointerException- if key is null
-
thenPutInMap
-
thenDeleteInMap
-
thenGetInMap
-
elsePutInMap
-
elseDeleteInMap
-
elseGetInMap
-
build
Builds and returns the completed transaction.- Returns:
- a new immutable Transaction with all configured conditions and operations (never null)
-