io.tarantool.driver.api.tuple.operations.TupleSpliceOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartridge-driver Show documentation
Show all versions of cartridge-driver Show documentation
Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework
package io.tarantool.driver.api.tuple.operations;
import io.tarantool.driver.mappers.MessagePackObjectMapper;
import org.msgpack.value.Value;
import java.util.Arrays;
/**
* Represent splice operation on tuple field
*
* @author Sergey Volgin
*/
public class TupleSpliceOperation extends TupleUpdateOperation {
private final int position;
private final int offset;
public TupleSpliceOperation(int fieldIndex, int position, int offset, String value) {
super(TarantoolUpdateOperationType.SPLICE, fieldIndex, value);
this.position = position;
this.offset = offset;
}
public TupleSpliceOperation(String fieldName, int position, int offset, String value) {
super(TarantoolUpdateOperationType.SPLICE, fieldName, value);
this.position = position;
this.offset = offset;
}
private TupleSpliceOperation(TarantoolUpdateOperationType operationType, Integer fieldIndex,
String fieldName, Object value, int position, int offset,
boolean isProxyOperation) {
super(operationType, fieldIndex, fieldName, value, isProxyOperation);
this.position = position;
this.offset = offset;
}
@Override
public TupleOperation toProxyTupleOperation() {
return new TupleSpliceOperation(
this.getOperationType(),
this.getFieldNumber(),
this.getFieldName(),
this.getValue(),
this.getPosition(),
this.getOffset(),
true
);
}
@Override
public Value toMessagePackValue(MessagePackObjectMapper mapper) {
return mapper.toValue(Arrays.asList(
getOperationType().toString(), getFieldIndex(), getPosition(), getOffset(), getValue()));
}
public int getPosition() {
return position;
}
public int getOffset() {
return offset;
}
}