com.scalar.db.api.OperationBuilder Maven / Gradle / Ivy
Show all versions of scalardb Show documentation
package com.scalar.db.api;
import com.scalar.db.io.Column;
import com.scalar.db.io.Key;
import java.nio.ByteBuffer;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* This class defines common interfaces used by {@link DeleteBuilder}, {@link PutBuilder}, {@link
* GetBuilder} and {@link ScanBuilder}
*/
class OperationBuilder {
interface Namespace {
/**
* Sets the specified target namespace for this operation
*
* @param namespaceName target namespace for this operation
* @return the operation builder
*/
T namespace(String namespaceName);
}
interface ClearNamespace {
/**
* Removes the namespace
*
* @return the operation builder
*/
T clearNamespace();
}
interface Table {
/**
* Sets the specified target table for this operation
*
* @param tableName target table name for this operation
* @return the operation builder
*/
T table(String tableName);
}
interface PartitionKey {
/**
* Constructs the operation with the specified partition {@link Key}.
*
* @param partitionKey a partition {@code Key} (it might be composed of multiple values)
* @return the operation builder
*/
T partitionKey(Key partitionKey);
}
interface ClusteringKey {
/**
* Constructs the operation with the specified clustering {@link Key}.
*
* @param clusteringKey a clustering {@code Key} (it might be composed of multiple values)
* @return the operation builder
*/
T clusteringKey(Key clusteringKey);
}
interface ClearClusteringKey {
/**
* Remove the clustering key
*
* @return the operation builder
*/
T clearClusteringKey();
}
interface Consistency {
/**
* Sets the specified consistency level for this operation
*
* @param consistency consistency level to set
* @return the operation builder
*/
E consistency(com.scalar.db.api.Consistency consistency);
}
interface Projection {
/**
* Appends the specified column name to the list of projections.
*
* @param projection a column name to project
* @return the operation builder
*/
T projection(String projection);
/**
* Appends the specified collection of the specified column names to the list of projections.
*
* @param projections a collection of the column names to project
* @return the operation builder
*/
T projections(Collection projections);
/**
* Appends the specified collection of the specified column names to the list of projections.
*
* @param projections the column names to project
* @return the operation builder
*/
T projections(String... projections);
}
interface ClearProjections {
/**
* Clear the list of projections
*
* @return the operation builder
*/
T clearProjections();
}
interface Condition {
/**
* Sets the specified {@link MutationCondition}
*
* @param condition a {@code MutationCondition}
* @return the operation builder
*/
T condition(MutationCondition condition);
}
interface ClearCondition {
/**
* Remove the condition
*
* @return the operation builder
*/
T clearCondition();
}
interface Values {
/**
* Adds the specified BOOLEAN value to the list of put values.
*
* @param columnName a column name of the value
* @param value a BOOLEAN value to put
* @return the Put operation builder
*/
T booleanValue(String columnName, boolean value);
/**
* Adds the specified BOOLEAN value to the list of put values.
*
* @param columnName a column name of the value
* @param value a BOOLEAN value to put
* @return the Put operation builder
*/
T booleanValue(String columnName, @Nullable Boolean value);
/**
* Adds the specified INT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a INT value to put
* @return the Put operation builder
*/
T intValue(String columnName, int value);
/**
* Adds the specified INT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a INT value to put
* @return the Put operation builder
*/
T intValue(String columnName, @Nullable Integer value);
/**
* Adds the specified BIGINT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a BIGINT value to put
* @return the Put operation builder
*/
T bigIntValue(String columnName, long value);
/**
* Adds the specified BIGINT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a BIGINT value to put
* @return the Put operation builder
*/
T bigIntValue(String columnName, @Nullable Long value);
/**
* Adds the specified FLOAT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a FLOAT value to put
* @return the Put operation builder
*/
T floatValue(String columnName, float value);
/**
* Adds the specified FLOAT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a FLOAT value to put
* @return the Put operation builder
*/
T floatValue(String columnName, @Nullable Float value);
/**
* Adds the specified DOUBLE value to the list of put values.
*
* @param columnName a column name of the value
* @param value a DOUBLE value to put
* @return the Put operation builder
*/
T doubleValue(String columnName, double value);
/**
* Adds the specified DOUBLE value to the list of put values.
*
* @param columnName a column name of the value
* @param value a DOUBLE value to put
* @return the Put operation builder
*/
T doubleValue(String columnName, @Nullable Double value);
/**
* Adds the specified TEXT value to the list of put values.
*
* @param columnName a column name of the value
* @param value a TEXT value to put
* @return the Put operation builder
*/
T textValue(String columnName, @Nullable String value);
/**
* Adds the specified BLOB value as a byte array to the list of put values.
*
* @param columnName a column name of the value
* @param value a BLOB value to put
* @return the Put operation builder
*/
T blobValue(String columnName, @Nullable byte[] value);
/**
* Adds the specified BLOB value as a ByteBuffer to the list of put values.
*
* @param columnName a column name of the value
* @param value a BLOB value to put
* @return the Put operation builder
*/
T blobValue(String columnName, @Nullable ByteBuffer value);
/**
* Adds a column to the list of put values.
*
* This method is primarily for internal use. Breaking changes can and will be introduced to
* this method. Users should not depend on it.
*
* @param column a column to put
* @return the Put operation builder
*/
T value(Column> column);
}
interface ClearValues {
/**
* Clear the list of values
*
* @return the operation builder
*/
T clearValues();
/**
* Clear the value for the given column
*
* @param columnName a column name
* @return the operation builder
*/
T clearValue(String columnName);
}
interface Limit {
/**
* Sets the specified number of results to be returned
*
* @param limit the number of results to be returned
* @return the scan operation builder
*/
T limit(int limit);
}
interface Ordering {
/**
* Sets the specified scan ordering. Ordering can only be specified with clustering keys. To
* sort results by multiple clustering keys, call this method multiple times in the order of
* sorting or call {@link #orderings(Collection)} or {@link #orderings(Scan.Ordering...)}.
*
* @param ordering a scan ordering
* @return the scan operation builder
*/
T ordering(Scan.Ordering ordering);
/**
* Sets the specified scan orderings. Ordering can only be specified with clustering keys.
*
* @param orderings scan orderings
* @return the scan operation builder
*/
T orderings(Collection orderings);
/**
* Sets the specified scan orderings. Ordering can only be specified with clustering keys.
*
* @param orderings scan orderings
* @return the scan operation builder
*/
T orderings(Scan.Ordering... orderings);
}
interface ClearOrderings {
/**
* Clear the list of orderings
*
* @return the scan operation builder
*/
T clearOrderings();
}
interface ClusteringKeyFiltering {
/**
* Sets the specified clustering key as a starting point for scan. The boundary is inclusive.
*
* @param clusteringKey a starting clustering key
* @return the scan operation builder
*/
default T start(Key clusteringKey) {
return start(clusteringKey, true);
}
/**
* Sets the specified clustering key with the specified boundary as a starting point for scan.
*
* @param clusteringKey a starting clustering key
* @param inclusive indicates whether the boundary is inclusive or not
* @return the scan operation builder
*/
T start(Key clusteringKey, boolean inclusive);
/**
* Sets the specified clustering key as an ending point for scan. The boundary is inclusive.
*
* @param clusteringKey an ending clustering key
* @return the scan operation builder
*/
default T end(Key clusteringKey) {
return end(clusteringKey, true);
}
/**
* Sets the specified clustering key with the specified boundary as an ending point for scan.
*
* @param clusteringKey an ending clustering key
* @param inclusive indicates whether the boundary is inclusive or not
* @return the scan operation builder
*/
T end(Key clusteringKey, boolean inclusive);
}
interface ClearBoundaries {
/**
* Remove the scan starting boundary
*
* @return the scan operation builder
*/
T clearStart();
/**
* Remove the scan ending boundary
*
* @return the scan operation builder
*/
T clearEnd();
}
interface All {
/**
* Specify the Scan operation will retrieve all the entries of the database
*
* @return the scan operation builder
*/
T all();
}
interface IndexKey {
/**
* Constructs the operation with the specified index {@link Key}.
*
* @param indexKey an index {@code Key}
* @return the operation builder
*/
T indexKey(Key indexKey);
}
interface Where {
/**
* Appends the specified condition.
*
* @param condition a condition
* @return the operation builder
*/
T where(ConditionalExpression condition);
}
interface WhereAnd {
/**
* Appends the specified set of or-wise conditions.
*
* @param conditions a set of conditions
* @return the operation builder
*/
T where(ScanBuilder.OrConditionSet conditions);
}
interface WhereOr {
/**
* Appends the specified set of and-wise conditions.
*
* @param conditions a set of conditions
* @return the operation builder
*/
T where(ScanBuilder.AndConditionSet conditions);
}
interface And {
/**
* Appends the specified condition.
*
* @param condition a condition
* @return the operation builder
*/
T and(ConditionalExpression condition);
/**
* Appends the specified set of or-wise conditions.
*
* @param conditions a set of conditions
* @return the operation builder
*/
T and(ScanBuilder.OrConditionSet conditions);
}
interface Or {
/**
* Appends the specified condition.
*
* @param condition a condition
* @return the operation builder
*/
T or(ConditionalExpression condition);
/**
* Appends the specified set of and-wise conditions.
*
* @param conditions a set of conditions
* @return the operation builder
*/
T or(ScanBuilder.AndConditionSet conditions);
}
interface ClearConditions {
/**
* Clear all conditions
*
* @return the scan operation builder
*/
T clearConditions();
}
abstract static class TableBuilder implements Table {
final String namespace;
public TableBuilder(String namespace) {
this.namespace = namespace;
}
}
abstract static class PartitionKeyBuilder implements PartitionKey {
@Nullable final String namespaceName;
final String tableName;
public PartitionKeyBuilder(@Nullable String namespaceName, String tableName) {
this.namespaceName = namespaceName;
this.tableName = tableName;
}
}
abstract static class Buildable {
@Nullable String namespaceName;
String tableName;
Key partitionKey;
public Buildable(@Nullable String namespaceName, String tableName, Key partitionKey) {
this.namespaceName = namespaceName;
this.tableName = tableName;
this.partitionKey = partitionKey;
}
public abstract T build();
}
}