Package com.gengoai.sql.statement
Class QueryStatement
- java.lang.Object
-
- com.gengoai.sql.statement.QueryStatement
-
- All Implemented Interfaces:
Copyable<QueryStatement>
,SQLElement
,Serializable
- Direct Known Subclasses:
QueryOperator
,Select
public abstract class QueryStatement extends Object implements SQLElement, Copyable<QueryStatement>
SQL Statement that performs a query over a database.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description QueryStatement()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryStatement
copy()
Makes a copy of this object.QueryStatement
except(@NonNull QueryStatement query2)
Combines this query with the given second query using an EXCEPT operatorboolean
exists(@NonNull SQLContext context)
Runs the query returning true if there is at least on result.QueryStatement
intersect(@NonNull QueryStatement query2)
Combines this query with the given second query using an INTERSECT operatorResultSet
query(@NonNull SQLContext context)
Runs the query on the given context returning a ResultSet<T> Stream<T>
query(@NonNull SQLContext context, @NonNull ResultSetMapper<? extends T> resultSetMapper)
Performs the query specified in this statement using the givenSQLContext
returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects<T> Stream<T>
query(@NonNull SQLContext context, @NonNull List<?> values, @NonNull ResultSetMapper<? extends T> resultSetMapper)
Performs the query specified in this statement using the givenSQLContext
filling in indexed value placeholders using the given List of values and returning the results as aResultSetIterator
* using the givenResultSetMapper
to map ResultSet to objects<T> Stream<T>
query(@NonNull SQLContext context, @NonNull Map<String,?> values, @NonNull ResultSetMapper<? extends T> resultSetMapper)
Performs the query specified in this statement using the givenSQLContext
filling in named value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects<T> T
queryScalar(@NonNull SQLContext context, @NonNull Class<T> tClass)
Performs this query on the givenSQLContext
which expects a single value for a single column to return.Double
queryScalarDouble(@NonNull SQLContext context)
Performs this query on the givenSQLContext
which expects a single value for a single column to return.Long
queryScalarLong(@NonNull SQLContext context)
Performs this query on the givenSQLContext
which expects a single value for a single column to return.String
queryScalarString(@NonNull SQLContext context)
Performs this query on the givenSQLContext
which expects a single value for a single column to return.QueryStatement
union(@NonNull QueryStatement query2)
Combines this query with the given second query using an UNION operatorQueryStatement
unionAll(@NonNull QueryStatement query2)
Combines this query with the given second query using an UNION ALL operator-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.gengoai.sql.SQLElement
getClassName
-
-
-
-
Method Detail
-
copy
public QueryStatement copy()
Description copied from interface:Copyable
Makes a copy of this object.
- Specified by:
copy
in interfaceCopyable<QueryStatement>
- Returns:
- A copy of this object.
-
except
public QueryStatement except(@NonNull @NonNull QueryStatement query2)
Combines this query with the given second query using an EXCEPT operator- Parameters:
query2
- the second query.- Returns:
- the combined SQLQueryStatement
-
exists
public boolean exists(@NonNull @NonNull SQLContext context) throws SQLException
Runs the query returning true if there is at least on result.- Parameters:
context
- the context to perform the query over- Returns:
- True if there is at least one result
- Throws:
SQLException
- something happened trying to query
-
intersect
public QueryStatement intersect(@NonNull @NonNull QueryStatement query2)
Combines this query with the given second query using an INTERSECT operator- Parameters:
query2
- the second query.- Returns:
- the combined SQLQueryStatement
-
query
public <T> Stream<T> query(@NonNull @NonNull SQLContext context, @NonNull @NonNull ResultSetMapper<? extends T> resultSetMapper) throws SQLException
Performs the query specified in this statement using the givenSQLContext
returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the query overresultSetMapper
- the mapper from ResultSet to Object- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
query
public <T> Stream<T> query(@NonNull @NonNull SQLContext context, @NonNull @NonNull List<?> values, @NonNull @NonNull ResultSetMapper<? extends T> resultSetMapper) throws SQLException
Performs the query specified in this statement using the givenSQLContext
filling in indexed value placeholders using the given List of values and returning the results as aResultSetIterator
* using the givenResultSetMapper
to map ResultSet to objects- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the query overvalues
- the values to use to fill the query statement (by Index)resultSetMapper
- the mapper from ResultSet to Object- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
query
public <T> Stream<T> query(@NonNull @NonNull SQLContext context, @NonNull @NonNull Map<String,?> values, @NonNull @NonNull ResultSetMapper<? extends T> resultSetMapper) throws SQLException
Performs the query specified in this statement using the givenSQLContext
filling in named value placeholders using the given Map of values and returning the results as aResultSetIterator
using the givenResultSetMapper
to map ResultSet to objects- Type Parameters:
T
- the Iterator type parameter- Parameters:
context
- the context to perform the query overvalues
- the values to use to fill the query statement (by Name)resultSetMapper
- the mapper from ResultSet to Object- Returns:
- the ResultSetIterator over the results of the given
QueryStatement
- Throws:
SQLException
- something happened trying to query
-
query
public final ResultSet query(@NonNull @NonNull SQLContext context) throws SQLException
Runs the query on the given context returning a ResultSet- Parameters:
context
- the context to perform the query over- Returns:
- the ResultSet
- Throws:
SQLException
- Something went wrong querying
-
queryScalar
public <T> T queryScalar(@NonNull @NonNull SQLContext context, @NonNull @NonNull Class<T> tClass) throws SQLException
Performs this query on the givenSQLContext
which expects a single value for a single column to return. The resultant value is converted into the given class type for return. If there is no value or the value cannot be converted anull
value is returned.- Type Parameters:
T
- the type parameter- Parameters:
context
- the context to perform the query overtClass
- the class type desired for the scalar object- Returns:
- the scalar result
- Throws:
SQLException
- something happened trying to query
-
queryScalarDouble
public Double queryScalarDouble(@NonNull @NonNull SQLContext context) throws SQLException
Performs this query on the givenSQLContext
which expects a single value for a single column to return. The resultant value is converted into a Double return. If there is no value or the value cannot be converted anull
value is returned.- Parameters:
context
- the context to perform the query over- Returns:
- the scalar result
- Throws:
SQLException
- something happened trying to query
-
queryScalarLong
public Long queryScalarLong(@NonNull @NonNull SQLContext context) throws SQLException
Performs this query on the givenSQLContext
which expects a single value for a single column to return. The resultant value is converted into a Long return. If there is no value or the value cannot be converted anull
value is returned.- Parameters:
context
- the context to perform the query over- Returns:
- the scalar result
- Throws:
SQLException
- something happened trying to query
-
queryScalarString
public String queryScalarString(@NonNull @NonNull SQLContext context) throws SQLException
Performs this query on the givenSQLContext
which expects a single value for a single column to return. The resultant value is converted into a String return. If there is no value or the value cannot be converted anull
value is returned.- Parameters:
context
- the context to perform the query over- Returns:
- the scalar result
- Throws:
SQLException
- something happened trying to query
-
union
public QueryStatement union(@NonNull @NonNull QueryStatement query2)
Combines this query with the given second query using an UNION operator- Parameters:
query2
- the second query.- Returns:
- the combined SQLQueryStatement
-
unionAll
public QueryStatement unionAll(@NonNull @NonNull QueryStatement query2)
Combines this query with the given second query using an UNION ALL operator- Parameters:
query2
- the second query.- Returns:
- the combined SQLQueryStatement
-
-