All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.tarantool.driver.api.tuple.operations.TupleSpliceOperation Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy