io.tarantool.driver.api.conditions.PositionField 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.conditions;
import io.tarantool.driver.exceptions.TarantoolFieldNotFoundException;
import io.tarantool.driver.metadata.TarantoolFieldMetadata;
import io.tarantool.driver.metadata.TarantoolMetadataOperations;
import io.tarantool.driver.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.utils.Assert;
import java.util.Optional;
/**
* Represents a field defined by position
*
* @author Alexey Kuzin
*/
public class PositionField implements FieldIdentifier {
private int position;
/**
* Construct field using its position in field.
*
* @param position field position, starting from 0
*/
public PositionField(int position) {
Assert.state(position >= 0, "Field position must be greater or equal 0");
this.position = position;
}
@Override
public TarantoolFieldMetadata metadata(TarantoolMetadataOperations metadataOperations,
TarantoolSpaceMetadata spaceMetadata) {
Optional fieldMetadata = spaceMetadata.getFieldByPosition(position);
if (!fieldMetadata.isPresent()) {
throw new TarantoolFieldNotFoundException(position, spaceMetadata);
}
return fieldMetadata.get();
}
@Override
public Integer toIdentifier() {
return position;
}
}