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

io.tarantool.driver.core.conditions.NamedIndexImpl 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.core.conditions;

import io.tarantool.driver.api.conditions.NamedIndex;
import io.tarantool.driver.api.metadata.TarantoolIndexMetadata;
import io.tarantool.driver.api.metadata.TarantoolMetadataOperations;
import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.exceptions.TarantoolIndexNotFoundException;
import io.tarantool.driver.utils.Assert;

import java.util.Objects;
import java.util.Optional;

/**
 * Represents an index defined by name
 *
 * @author Alexey Kuzin
 */
public class NamedIndexImpl implements NamedIndex {

    private static final long serialVersionUID = 20200708L;

    private final String name;

    /**
     * Construct index by its name
     *
     * @param name index name, should not be empty
     */
    public NamedIndexImpl(String name) {
        Assert.hasText(name, "Index name should not be empty");

        this.name = name;
    }

    @Override
    public TarantoolIndexMetadata metadata(
        TarantoolMetadataOperations metadataOperations,
        TarantoolSpaceMetadata spaceMetadata) {
        Optional indexMetadata =
            metadataOperations.getIndexByName(spaceMetadata.getSpaceName(), name);
        if (!indexMetadata.isPresent()) {
            throw new TarantoolIndexNotFoundException(spaceMetadata.getSpaceName(), name);
        }

        return indexMetadata.get();
    }

    @Override
    public String toIdentifier() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        NamedIndexImpl that = (NamedIndexImpl) o;
        return Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy