-
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.
Support insert_many and replace_many CRUD operations
- Loading branch information
Showing
12 changed files
with
474 additions
and
9 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
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
80 changes: 80 additions & 0 deletions
80
src/main/java/io/tarantool/driver/core/proxy/InsertManyProxyOperation.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,80 @@ | ||
package io.tarantool.driver.core.proxy; | ||
|
||
import io.tarantool.driver.api.SingleValueCallResult; | ||
import io.tarantool.driver.api.TarantoolCallOperations; | ||
import io.tarantool.driver.mappers.CallResultMapper; | ||
import io.tarantool.driver.mappers.MessagePackObjectMapper; | ||
import io.tarantool.driver.protocol.Packable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Proxy operation for inserting many records at once | ||
* | ||
* @param <T> result type | ||
* @param <R> result collection type | ||
* @author Alexey Kuzin | ||
*/ | ||
public final class InsertManyProxyOperation<T extends Packable, R extends Collection<T>> | ||
extends AbstractProxyOperation<R> { | ||
|
||
InsertManyProxyOperation(TarantoolCallOperations client, | ||
String functionName, | ||
List<?> arguments, | ||
MessagePackObjectMapper argumentsMapper, | ||
CallResultMapper<R, SingleValueCallResult<R>> resultMapper) { | ||
super(client, functionName, arguments, argumentsMapper, resultMapper); | ||
} | ||
|
||
/** | ||
* The builder for this class. | ||
*/ | ||
public static final class Builder<T extends Packable, R extends Collection<T>> | ||
extends GenericOperationsBuilder<R, Builder<T, R>> { | ||
private Collection<T> tuples; | ||
private Boolean stopOnError; | ||
private Boolean rollbackOnError; | ||
|
||
public Builder() { | ||
} | ||
|
||
@Override | ||
Builder<T, R> self() { | ||
return this; | ||
} | ||
|
||
public Builder<T, R> withTuples(Collection<T> tuples) { | ||
this.tuples = tuples; | ||
return this; | ||
} | ||
|
||
public Builder<T, R> withStopOnError(boolean stopOnError) { | ||
this.stopOnError = stopOnError; | ||
return this; | ||
} | ||
|
||
public Builder<T, R> withRollbackOnError(boolean rollbackOnError) { | ||
this.rollbackOnError = rollbackOnError; | ||
return this; | ||
} | ||
|
||
public InsertManyProxyOperation<T, R> build() { | ||
if (tuples == null) { | ||
throw new IllegalArgumentException("Tuples must be specified for batch insert operation"); | ||
} | ||
|
||
CRUDBatchOptions options = new CRUDBatchOptions.Builder() | ||
.withTimeout(requestTimeout) | ||
.withStopOnError(stopOnError) | ||
.withRollbackOnError(rollbackOnError) | ||
.build(); | ||
|
||
List<?> arguments = Arrays.asList(spaceName, tuples, options.asMap()); | ||
|
||
return new InsertManyProxyOperation<>( | ||
this.client, this.functionName, arguments, this.argumentsMapper, this.resultMapper); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/io/tarantool/driver/core/proxy/ReplaceManyProxyOperation.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,80 @@ | ||
package io.tarantool.driver.core.proxy; | ||
|
||
import io.tarantool.driver.api.SingleValueCallResult; | ||
import io.tarantool.driver.api.TarantoolCallOperations; | ||
import io.tarantool.driver.mappers.CallResultMapper; | ||
import io.tarantool.driver.mappers.MessagePackObjectMapper; | ||
import io.tarantool.driver.protocol.Packable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Proxy operation for replacing many records at once | ||
* | ||
* @param <T> result type | ||
* @param <R> result collection type | ||
* @author Alexey Kuzin | ||
*/ | ||
public final class ReplaceManyProxyOperation<T extends Packable, R extends Collection<T>> | ||
extends AbstractProxyOperation<R> { | ||
|
||
ReplaceManyProxyOperation(TarantoolCallOperations client, | ||
String functionName, | ||
List<?> arguments, | ||
MessagePackObjectMapper argumentsMapper, | ||
CallResultMapper<R, SingleValueCallResult<R>> resultMapper) { | ||
super(client, functionName, arguments, argumentsMapper, resultMapper); | ||
} | ||
|
||
/** | ||
* The builder for this class. | ||
*/ | ||
public static final class Builder<T extends Packable, R extends Collection<T>> | ||
extends GenericOperationsBuilder<R, Builder<T, R>> { | ||
private Collection<T> tuples; | ||
private Boolean stopOnError; | ||
private Boolean rollbackOnError; | ||
|
||
public Builder() { | ||
} | ||
|
||
@Override | ||
Builder<T, R> self() { | ||
return this; | ||
} | ||
|
||
public Builder<T, R> withTuples(Collection<T> tuples) { | ||
this.tuples = tuples; | ||
return this; | ||
} | ||
|
||
public Builder<T, R> withStopOnError(boolean stopOnError) { | ||
this.stopOnError = stopOnError; | ||
return this; | ||
} | ||
|
||
public Builder<T, R> withRollbackOnError(boolean rollbackOnError) { | ||
this.rollbackOnError = rollbackOnError; | ||
return this; | ||
} | ||
|
||
public ReplaceManyProxyOperation<T, R> build() { | ||
if (tuples == null) { | ||
throw new IllegalArgumentException("Tuples must be specified for batch replace operation"); | ||
} | ||
|
||
CRUDBatchOptions options = new CRUDBatchOptions.Builder() | ||
.withTimeout(requestTimeout) | ||
.withStopOnError(stopOnError) | ||
.withRollbackOnError(rollbackOnError) | ||
.build(); | ||
|
||
List<?> arguments = Arrays.asList(spaceName, tuples, options.asMap()); | ||
|
||
return new ReplaceManyProxyOperation<>( | ||
this.client, this.functionName, arguments, this.argumentsMapper, this.resultMapper); | ||
} | ||
} | ||
} |
Oops, something went wrong.