
com.github.helenusdriver.driver.Select Maven / Gradle / Ivy
Show all versions of api Show documentation
/*
* Copyright (C) 2015-2015 The Helenus Driver Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.helenusdriver.driver;
/**
* The Select
interface extends the functionality of Cassandra's
* {@link com.datastax.driver.core.querybuilder.Select} class to provide support
* for POJOs.
*
* @copyright 2015-2015 The Helenus Driver Project Authors
*
* @author The Helenus Driver Project Authors
* @version 1 - Jan 15, 2015 - paouelle - Creation
*
* @param The type of POJO associated with this statement.
*
* @since 1.0
*/
public interface Select extends ObjectStatement {
/**
* Adds a WHERE clause to this statement.
*
* This is a shorter/more readable version for {@code where().and(clauses)}.
*
* @author paouelle
*
* @param clause the clause to add.
* @return the where clause of this query to which more clause can be added.
* @throws IllegalArgumentException if the clause reference a
* column which is not a primary key or an index column in the POJO
*/
public Where where(Clause clause);
/**
* Gets a Where statement for this query without adding clause.
*
* @author paouelle
*
* @return the where clause of this query to which more clause can be added.
*/
public Where where();
/**
* Adds an ORDER BY clause to this statement.
*
* @author paouelle
*
* @param orderings the orderings to define for this query.
* @return this statement.
* @throws IllegalStateException if an ORDER BY clause has already been
* provided.
* @throws IllegalArgumentException if any of the column names are not defined
* by the POJO
*/
public Select orderBy(Ordering... orderings);
/**
* Adds a LIMIT clause to this statement.
*
* @author paouelle
*
* @param limit the limit to set.
* @return this statement.
* @throws IllegalArgumentException if {@code limit >e; 0}.
* @throws IllegalStateException if a LIMIT clause has already been
* provided.
*/
public Select limit(int limit);
/**
* Adds an ALLOW FILTERING directive to this statement.
*
* @author paouelle
*
* @return this statement.
*/
public Select allowFiltering();
/**
* The Where
interface defines a WHERE clause for a SELECT
* statement.
*
* @copyright 2015-2015 The Helenus Driver Project Authors
*
* @author The Helenus Driver Project Authors
* @version 1 - Jan 15, 2015 - paouelle - Creation
*
* @param The type of POJO associated with the statement.
*
* @since 1.0
*/
public interface Where extends ObjectStatement {
/**
* Adds the provided clause to this WHERE clause.
*
* @author paouelle
*
* @param clause the clause to add.
* @return this WHERE clause.
* @throws IllegalArgumentException if the clause referenced a
* column which is not a primary key or an index column in the POJO
*/
public Where and(Clause clause);
/**
* Adds an ORDER BY clause to the SELECT statement this WHERE clause if part
* of.
*
* @author paouelle
*
* @param orderings the orderings to add.
* @return the select statement this Where clause if part of.
* @throws IllegalStateException if an ORDER BY clause has already been
* provided.
* @throws IllegalArgumentException if any of the column names are not defined
* by the POJO
*/
public Select orderBy(Ordering... orderings);
/**
* Adds a LIMIT clause to the SELECT statement this WHERE clause if part of.
*
* @author paouelle
*
* @param limit the limit to set.
* @return the select statement this Where clause if part of.
* @throws IllegalArgumentException if {@code limit >e; 0}.
* @throws IllegalStateException if a LIMIT clause has already been
* provided.
*/
public Select limit(int limit);
}
/**
* The Builder
interface defines an in-construction SELECT
* statement.
*
* @copyright 2015-2015 The Helenus Driver Project Authors
*
* @author The Helenus Driver Project Authors
* @version 1 - Jan 15, 2015 - paouelle - Creation
*
* @param The type of POJO associated with the statement.
*
* @since 1.0
*/
public interface Builder {
/**
* Specify to select from the keyspace as defined in the POJO and the
* specified table.
*
* This flavor should be used when the POJO doesn't require suffixes to the
* keyspace name.
*
* @author paouelle
*
* @param table the name of the table to select from
* @return a newly build SELECT statement
* @throws NullPointerException if table
is null
* @throws IllegalArgumentException if the table or any of the referenced
* columns are not defined by the POJO
*/
public Select from(String table);
}
/**
* The Selection
interface defines a selection clause for an
* in-construction SELECT statement.
*
* @copyright 2015-2015 The Helenus Driver Project Authors
*
* @author The Helenus Driver Project Authors
* @version 1 - Jan 15, 2015 - paouelle - Creation
*
* @param The type of POJO associated with the response from this statement.
*
* @since 1.0
*/
public interface Selection extends Builder {
/**
* Selects all columns (i.e. "SELECT * ...")
*
* @author paouelle
*
* @return an in-build SELECT statement.
* @throws IllegalStateException if some columns had already been selected
* for this builder
*/
public Builder all();
/**
* Selects the count of all returned rows (i.e. "SELECT count(*) ...").
*
* @author paouelle
*
* @return an in-build SELECT statement.
* @throws IllegalStateException if some columns had already been selected
* for this builder.
*/
public Builder countAll();
/**
* Selects the provided column.
*
* @author paouelle
*
* @param name the new column name to add.
* @return this in-build SELECT statement
* @throws NullPointerException if name
is null
* @throws IllegalArgumentException if the specified column is not defined
* by the POJO
*/
public Selection column(Object name);
/**
* Selects the write time of provided column.
*
* This is a shortcut for {@code fcall("writetime", StatementBuilder.column(name))}.
*
* @author paouelle
*
* @param name the name of the column to select the write time of.
* @return this in-build SELECT statement
* @throws NullPointerException if name
is null
* @throws IllegalArgumentException if the specified column is not defined
* by the POJO
*/
public Selection writeTime(String name);
/**
* Selects the ttl of provided column.
*
* This is a shortcut for {@code fcall("ttl", StatementBuilder.column(name))}.
*
* @author paouelle
*
* @param name the name of the column to select the ttl of.
* @return this in-build SELECT statement
* @throws NullPointerException if name
is null
* @throws IllegalArgumentException if the specified column is not defined
* by the POJO
*/
public Selection ttl(String name);
/**
* Creates a function call.
*
* Please note that the parameters are interpreted as values, and so
* {@code fcall("textToBlob", "foo")} will generate the string
* {@code "textToBlob('foo')"}. If you want to generate
* {@code "textToBlob(foo)"}, i.e. if the argument must be interpreted
* as a column name (in a select clause), you will need to use the
* {@link StatementBuilder#column} method, and so
* {@code fcall("textToBlob", StatementBuilder.column(foo)}.
*
* @author paouelle
*
* @param name the name of the column to select the function for
* @param parameters the parameters to the function
* @return this in-build SELECT statement
* @throws NullPointerException if name
is null
* @throws IllegalArgumentException if any of specified column parameters are
* not defined by the POJO
*/
public Selection fcall(String name, Object... parameters);
}
}