io.tarantool.driver.api.conditions.IdIndex 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.TarantoolIndexNotFoundException;
import io.tarantool.driver.metadata.TarantoolIndexMetadata;
import io.tarantool.driver.metadata.TarantoolMetadataOperations;
import io.tarantool.driver.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.utils.Assert;
import java.util.Optional;
/**
* Represents an index defined by its id
*
* @author Alexey Kuzin
*/
public class IdIndex implements FieldIdentifier {
private int position;
/**
* Construct index by its id
*
* @param position index position in the order of creation, starting from 0
*/
public IdIndex(int position) {
Assert.state(position >= 0, "Index position should be greater or equal 0");
this.position = position;
}
@Override
public TarantoolIndexMetadata metadata(TarantoolMetadataOperations metadataOperations,
TarantoolSpaceMetadata spaceMetadata) {
Optional indexMetadata =
metadataOperations.getIndexById(spaceMetadata.getSpaceName(), position);
if (!indexMetadata.isPresent()) {
throw new TarantoolIndexNotFoundException(spaceMetadata.getSpaceName(), position);
}
return indexMetadata.get();
}
@Override
public Integer toIdentifier() {
return position;
}
}