Package org.dalesbred.query
Class SqlQuery
java.lang.Object
org.dalesbred.query.SqlQuery
- All Implemented Interfaces:
Serializable
Represents an SQL query along all of its arguments.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
@NotNull List<?>
Returns the list of arguments this query has.@Nullable FetchDirection
Returns the fetch direction of this query.@Nullable Integer
Returns the fetch size of this query.@NotNull String
getSql()
Returns the SQL that is to be execute at the database.@Nullable Duration
Returns the timeout of this query.int
hashCode()
static @NotNull SqlQuery
namedQuery
(@NotNull String sql, @NotNull Object bean) Constructs a query with named arguments, using the properties/fields of given bean for resolving arguments.static @NotNull SqlQuery
namedQuery
(@NotNull String sql, @NotNull Map<String, ?> valueMap) Constructs a query with named arguments, using given map for resolving the values of arguments.static @NotNull SqlQuery
namedQuery
(@NotNull String sql, @NotNull VariableResolver variableResolver) Creates a newSqlQuery
consisting of given SQL statement and a provider for named arguments.static @NotNull SqlQuery
static @NotNull SqlQuery
Creates a newSqlQuery
consisting of given SQL statement and arguments.void
setFetchDirection
(@Nullable FetchDirection direction) A non-null fetch direction will be set as the fetch direction for the statements executed from this query.void
setFetchSize
(@Nullable Integer size) A non-null fetch size will be set as the fetch size for the statements executed from this query.void
setTimeout
(@NotNull Duration timeout) A non-null timeout will be set as the timeout for the statements executed from this query.@NotNull String
toString()
-
Method Details
-
query
Creates a newSqlQuery
consisting of given SQL statement and arguments. '?' characters act as placeholders for arguments in the query. -
query
@NotNull public static @NotNull SqlQuery query(@NotNull @NotNull String sql, @NotNull @NotNull List<?> args) - See Also:
-
namedQuery
@NotNull public static @NotNull SqlQuery namedQuery(@NotNull @NotNull String sql, @NotNull @NotNull Map<String, ?> valueMap) Constructs a query with named arguments, using given map for resolving the values of arguments. -
namedQuery
@NotNull public static @NotNull SqlQuery namedQuery(@NotNull @NotNull String sql, @NotNull @NotNull Object bean) Constructs a query with named arguments, using the properties/fields of given bean for resolving arguments. -
namedQuery
@NotNull public static @NotNull SqlQuery namedQuery(@NotNull @NotNull String sql, @NotNull @NotNull VariableResolver variableResolver) Creates a newSqlQuery
consisting of given SQL statement and a provider for named arguments. The argument names in SQL should be prefixed by a colon, e.g. ":argument".- Throws:
SqlSyntaxException
- if SQL is malformedVariableResolutionException
- if variableResolver can't provide values for named parameters
-
getSql
Returns the SQL that is to be execute at the database. If the original query was a named query, the variable placeholders will have been replaced by positional placeholders in this query. -
getArguments
Returns the list of arguments this query has. -
getFetchSize
Returns the fetch size of this query. -
setFetchSize
A non-null fetch size will be set as the fetch size for the statements executed from this query. If the fetch size specified is zero, the JDBC driver ignores the value and makes its own best guess of the fetch size.- Parameters:
size
- fetch size in rows or null- Throws:
IllegalArgumentException
- if size is < 0
-
getFetchDirection
Returns the fetch direction of this query. -
setFetchDirection
A non-null fetch direction will be set as the fetch direction for the statements executed from this query.- Parameters:
direction
- fetch direction or null
-
getTimeout
Returns the timeout of this query. -
setTimeout
A non-null timeout will be set as the timeout for the statements executed from this query. If the timeout specified is zero, there is no limit for execution time- Throws:
IllegalArgumentException
- if timeout is negative- See Also:
-
toString
-
equals
-
hashCode
public int hashCode()
-