Skip to content

Commit

Permalink
Support insert_many and replace_many CRUD operations
Browse files Browse the repository at this point in the history
  • Loading branch information
akudiyar committed Sep 20, 2022
1 parent 1445056 commit eef114e
Show file tree
Hide file tree
Showing 54 changed files with 1,308 additions and 200 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

### Features
- Added options parameter to Tarantool Space API ([#266](https://github.com/tarantool/cartridge-java/pull/266))
- Added support for insert_many and replace_many CRUD operations ([#259](https://github.com/tarantool/cartridge-java/issues/259))

## [0.8.2] - 2022-09-16

### Features
- Removed code duplication in *ProxyOperations builders ([#256](https://github.com/tarantool/cartridge-java/issues/256))
- Added client EventLoopThreadsNumber property for control netty work threads ([#253](https://github.com/tarantool/cartridge-java/pull/253))

### Misc
- Removed code duplication in *ProxyOperations builders ([#256](https://github.com/tarantool/cartridge-java/issues/256))
- Refactor CRUDOperationOptions to a hierarchy of classes ([#258](https://github.com/tarantool/cartridge-java/issues/258))

## [0.8.1] - 2022-08-18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public final class ProxyOperationsMappingConfig {
public static final String SCHEMA_FUNCTION = "ddl.get_schema";
public static final String DELETE_FUNCTION = CRUD_PREFIX + "delete";
public static final String INSERT_FUNCTION = CRUD_PREFIX + "insert";
public static final String INSERT_MANY_FUNCTION = CRUD_PREFIX + "insert_many";
public static final String REPLACE_FUNCTION = CRUD_PREFIX + "replace";
public static final String REPLACE_MANY_FUNCTION = CRUD_PREFIX + "replace_many";
public static final String SELECT_FUNCTION = CRUD_PREFIX + "select";
public static final String UPDATE_FUNCTION = CRUD_PREFIX + "update";
public static final String UPSERT_FUNCTION = CRUD_PREFIX + "upsert";
Expand All @@ -21,7 +23,9 @@ public final class ProxyOperationsMappingConfig {
private final String schemaFunctionName;
private final String deleteFunctionName;
private final String insertFunctionName;
private final String insertManyFunctionName;
private final String replaceFunctionName;
private final String replaceManyFunctionName;
private final String updateFunctionName;
private final String upsertFunctionName;
private final String selectFunctionName;
Expand Down Expand Up @@ -58,6 +62,16 @@ public String getInsertFunctionName() {
return insertFunctionName;
}

/**
* Get API function name for performing the insert_many operation.
* The default value is <code>crud.insert_many</code>.
*
* @return a callable API function name
*/
public String getInsertManyFunctionName() {
return insertManyFunctionName;
}

/**
* Get API function name for performing the replace operation. The default value is <code>crud.replace</code>.
*
Expand All @@ -67,6 +81,16 @@ public String getReplaceFunctionName() {
return replaceFunctionName;
}

/**
* Get API function name for performing the replace_many operation.
* The default value is <code>crud.replace_many</code>.
*
* @return a callable API function name
*/
public String getReplaceManyFunctionName() {
return replaceManyFunctionName;
}

/**
* Get API function name for performing the update operation. The default value is <code>crud.update</code>.
*
Expand Down Expand Up @@ -104,13 +128,16 @@ public String getTruncateFunctionName() {
}

private ProxyOperationsMappingConfig(String schemaFunctionName, String deleteFunctionName,
String insertFunctionName, String replaceFunctionName,
String insertFunctionName, String insertManyFunctionName,
String replaceFunctionName, String replaceManyFunctionName,
String updateFunctionName, String upsertFunctionName,
String selectFunctionName, String truncateFunctionName) {
this.schemaFunctionName = schemaFunctionName;
this.deleteFunctionName = deleteFunctionName;
this.insertFunctionName = insertFunctionName;
this.insertManyFunctionName = insertManyFunctionName;
this.replaceFunctionName = replaceFunctionName;
this.replaceManyFunctionName = replaceManyFunctionName;
this.updateFunctionName = updateFunctionName;
this.upsertFunctionName = upsertFunctionName;
this.selectFunctionName = selectFunctionName;
Expand All @@ -134,7 +161,9 @@ public static final class Builder {
private String schemaFunctionName = SCHEMA_FUNCTION;
private String deleteFunctionName = DELETE_FUNCTION;
private String insertFunctionName = INSERT_FUNCTION;
private String insertManyFunctionName = INSERT_MANY_FUNCTION;
private String replaceFunctionName = REPLACE_FUNCTION;
private String replaceManyFunctionName = REPLACE_MANY_FUNCTION;
private String updateFunctionName = UPDATE_FUNCTION;
private String upsertFunctionName = UPSERT_FUNCTION;
private String selectFunctionName = SELECT_FUNCTION;
Expand Down Expand Up @@ -176,6 +205,17 @@ public Builder withInsertFunctionName(String insertFunctionName) {
return this;
}

/**
* Get API function name for performing the insert_many operation
*
* @param insertManyFunctionName name for stored function performing insert_many operation
* @return a callable API function name
*/
public Builder withInsertManyFunctionName(String insertManyFunctionName) {
this.insertManyFunctionName = insertManyFunctionName;
return this;
}

/**
* Get API function name for performing the replace operation
*
Expand All @@ -187,6 +227,17 @@ public Builder withReplaceFunctionName(String replaceFunctionName) {
return this;
}

/**
* Get API function name for performing the replace_many operation
*
* @param replaceManyFunctionName name for stored function performing replace_many operation
* @return a callable API function name
*/
public Builder withReplaceManyFunctionName(String replaceManyFunctionName) {
this.replaceManyFunctionName = replaceManyFunctionName;
return this;
}

/**
* Get API function name for performing the update operation
*
Expand Down Expand Up @@ -238,8 +289,8 @@ public Builder withTruncateFunctionName(String truncateFunctionName) {
*/
public ProxyOperationsMappingConfig build() {
return new ProxyOperationsMappingConfig(schemaFunctionName, deleteFunctionName, insertFunctionName,
replaceFunctionName, updateFunctionName, upsertFunctionName, selectFunctionName,
truncateFunctionName);
insertManyFunctionName, replaceFunctionName, replaceManyFunctionName, updateFunctionName,
upsertFunctionName, selectFunctionName, truncateFunctionName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import io.tarantool.driver.api.cursor.TarantoolCursor;
import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.api.space.options.DeleteOptions;
import io.tarantool.driver.api.space.options.InsertManyOptions;
import io.tarantool.driver.api.space.options.InsertOptions;
import io.tarantool.driver.api.space.options.ReplaceManyOptions;
import io.tarantool.driver.api.space.options.ReplaceOptions;
import io.tarantool.driver.api.space.options.SelectOptions;
import io.tarantool.driver.api.space.options.UpdateOptions;
Expand Down Expand Up @@ -38,7 +40,7 @@ public interface TarantoolSpaceOperations<T extends Packable, R extends Collecti
* Delete a tuple. Only a single primary index value condition is supported.
*
* @param conditions query with options
* @param options specified options
* @param options operation options
* @return a future that will contain removed tuple once completed
* @throws TarantoolClientException in case if the request failed
*/
Expand All @@ -59,14 +61,38 @@ default CompletableFuture<R> delete(Conditions conditions, DeleteOptions options
* Inserts tuple into the space, if no tuple with same unique keys exists. Otherwise throw duplicate key error.
*
* @param tuple new data
* @param options specified options
* @param options operation options
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if request failed
*/
default CompletableFuture<R> insert(T tuple, InsertOptions options) throws TarantoolClientException {
return insert(tuple);
}

/**
* Inserts several tuples into the space at once. If writing of any tuple fails,
* all tuples will not be saved.
*
* @param tuples new data
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if request failed
*/
CompletableFuture<R> insertMany(Collection<T> tuples) throws TarantoolClientException;

/**
* Inserts several tuples into the space at once. If writing of any tuple fails,
* all tuples will not be saved.
*
* @param tuples new data
* @param options operation options
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if request failed
*/
default CompletableFuture<R> insertMany(Collection<T> tuples, InsertManyOptions options)
throws TarantoolClientException {
return insertMany(tuples);
}

/**
* Insert a tuple into the space or replace an existing one.
*
Expand All @@ -80,7 +106,7 @@ default CompletableFuture<R> insert(T tuple, InsertOptions options) throws Taran
* Insert a tuple into the space or replace an existing one.
*
* @param tuple new data
* @param options specified options
* @param options operation options
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if request failed
*/
Expand All @@ -89,7 +115,31 @@ default CompletableFuture<R> replace(T tuple, ReplaceOptions options) throws Tar
}

/**
* Select tuples matching the specified query with specified conditions.
* Insert or replace several tuples into the space at once. If writing of any tuple fails,
* all tuples will not be saved.
*
* @param tuples new data
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if request failed
*/
CompletableFuture<R> replaceMany(Collection<T> tuples) throws TarantoolClientException;

/**
* Insert or replace several tuples into the space at once. If writing of any tuple fails,
* all tuples will not be saved, but this behavior can be changed with the options.
*
* @param tuples new data
* @param options operation options
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if request failed
*/
default CompletableFuture<R> replaceMany(Collection<T> tuples, ReplaceManyOptions options)
throws TarantoolClientException {
return replaceMany(tuples);
}

/**
* Select tuples matching the specified query with options.
*
* @param conditions query with options
* @return a future that will contain all corresponding tuples once completed
Expand All @@ -101,7 +151,7 @@ default CompletableFuture<R> replace(T tuple, ReplaceOptions options) throws Tar
* Select tuples matching the specified query with specified conditions and options.
*
* @param conditions specified conditions
* @param options specified options
* @param options operation options
* @return a future that will contain all corresponding tuples once completed
* @throws TarantoolClientException in case if the request failed
*/
Expand All @@ -124,7 +174,7 @@ default CompletableFuture<R> select(Conditions conditions, SelectOptions options
*
* @param conditions query with options
* @param tuple tuple with new field values
* @param options specified options
* @param options operation options
* @return a future that will contain corresponding tuple once completed
* @throws TarantoolClientException in case if the request failed
*/
Expand All @@ -147,7 +197,7 @@ default CompletableFuture<R> update(Conditions conditions, T tuple, UpdateOption
*
* @param conditions query with options
* @param operations the list update operations
* @param options specified options
* @param options operation options
* @return a future that will contain corresponding tuple once completed
* @throws TarantoolClientException in case if the request failed
*/
Expand All @@ -174,7 +224,7 @@ default CompletableFuture<R> update(Conditions conditions, TupleOperations opera
* @param conditions query with options
* @param tuple new data that will be insert if tuple will be not found
* @param operations the list of update operations to be performed if the tuple exists
* @param options specified options
* @param options operation options
* @return a future that will empty list
* @throws TarantoolClientException in case if the request failed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* Public API for space operations.
*
* An abstract class necessary for implementing CRT (curiously recurring template)
* pattern for the cluster proxy operation options.
* An abstract class-container for all operation options.
*
* @author Alexey Kuzin
* @author Artyom Dubinin
Expand All @@ -18,11 +16,24 @@ public abstract class AbstractOptions<B extends AbstractOptions<B>> implements O

protected abstract B self();

/**
* Add an option value.
*
* @param option option name
* @param value option value
*/
public void addOption(String option, Object value) {
resultMap.put(option, value);
}

public Map<String, Object> asMap() {
return resultMap;
/**
* Get an option value.
*
* @param option option name
* @param optionClass option value type
*/
@SuppressWarnings("unchecked")
public <T> Optional<T> getOption(String option, Class<T> optionClass) {
return Optional.ofNullable((T) resultMap.get(option));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.tarantool.driver.api.space.options;

/**
* Marker interface for space delete options
* Marker interface for space delete operation options
*
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface DeleteOptions extends Options {
public interface DeleteOptions extends OperationWithTimeoutOptions {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.tarantool.driver.api.space.options;

import java.util.Optional;

/**
* Marker interface for space insert_many operation options
*
* @author Alexey Kuzin
*/
public interface InsertManyOptions extends OperationWithTimeoutOptions {
/**
* Return whether all changes should not be saved if any tuple insertion
* was unsuccesful.
*
* @return true, if the operation should rollback on error
*/
Optional<Boolean> getRollbackOnError();

/**
* Return whether the operation should be interrupted if any tuple insertion
* was unsuccesful.
*
* @return true, if the operation should stop on error
*/
Optional<Boolean> getStopOnError();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.tarantool.driver.api.space.options;

/**
* Marker interface for space insert options
* Marker interface for space insert operation options
*
* @author Artyom Dubinin
* @author Alexey Kuzin
*/
public interface InsertOptions extends Options {
public interface InsertOptions extends OperationWithTimeoutOptions {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.tarantool.driver.api.space.options;

import java.util.Optional;

/**
* Base class for all operation options that may have a configurable timeout.
*
* @author Alexey Kuzin
*/
public interface OperationWithTimeoutOptions extends Options {
/**
* Return operation timeout.
*
* @return timeout, in milliseconds.
*/
Optional<Integer> getTimeout();
}
Loading

0 comments on commit eef114e

Please sign in to comment.