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

io.tarantool.driver.api.conditions.NamedField 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.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 name
 *
 * @author Alexey Kuzin
 */
public class NamedField implements FieldIdentifier {

    private String name;

    /**
     * Construct field using its name.
     *
     * @param name field name, should not be empty
     */
    public NamedField(String name) {
        Assert.hasText(name, "Field name should not be empty");

        this.name = name;
    }

    @Override
    public TarantoolFieldMetadata metadata(TarantoolMetadataOperations metadataOperations,
                                           TarantoolSpaceMetadata spaceMetadata) {

        Optional fieldMetadata = spaceMetadata.getFieldByName(name);
        if (!fieldMetadata.isPresent()) {
            throw new TarantoolFieldNotFoundException(name, spaceMetadata);
        }

        return fieldMetadata.get();
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy