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

com.aerospike.jdbc.predicate.QueryPredicateList Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
package com.aerospike.jdbc.predicate;

import com.aerospike.client.exp.Exp;
import com.aerospike.client.query.Filter;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

import static com.aerospike.jdbc.util.Constants.defaultKeyName;

public class QueryPredicateList extends QueryPredicateBase {

    private final Operator operator;
    private final Object[] values;

    public QueryPredicateList(String binName, Operator operator, Object[] values) {
        super(binName, getValueType(values[0]));
        this.operator = operator;
        this.values = values;
    }

    @Override
    public Exp toFilterExpression() {
        return operator.exp(
                Arrays.stream(values).map(v -> Exp.eq(buildLeftExp(), getValueExp(v))).toArray(Exp[]::new)
        );
    }

    @Override
    public Optional toFilter(String binName) {
        return Optional.empty();
    }

    @Override
    public boolean isIndexable() {
        return false;
    }

    @Override
    public Collection getPrimaryKeys() {
        if (binName.equals(defaultKeyName)) {
            return Arrays.asList(values);
        }
        return Collections.emptyList();
    }
}