Package org.dalesbred.query
Class SqlQuery
- java.lang.Object
-
- org.dalesbred.query.SqlQuery
-
- All Implemented Interfaces:
java.io.Serializable
public final class SqlQuery extends java.lang.Object implements java.io.SerializableRepresents an SQL query along all of its arguments.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)@NotNull java.util.List<?>getArguments()Returns the list of arguments this query has.@Nullable FetchDirectiongetFetchDirection()Returns the fetch direction of this query.@Nullable java.lang.IntegergetFetchSize()Returns the fetch size of this query.@NotNull java.lang.StringgetSql()Returns the SQL that is to be execute at the database.@Nullable java.time.DurationgetTimeout()Returns the timeout of this query.inthashCode()static @NotNull SqlQuerynamedQuery(@NotNull java.lang.String sql, @NotNull java.lang.Object bean)Constructs a query with named arguments, using the properties/fields of given bean for resolving arguments.static @NotNull SqlQuerynamedQuery(@NotNull java.lang.String sql, @NotNull java.util.Map<java.lang.String,?> valueMap)Constructs a query with named arguments, using given map for resolving the values of arguments.static @NotNull SqlQuerynamedQuery(@NotNull java.lang.String sql, @NotNull VariableResolver variableResolver)Creates a newSqlQueryconsisting of given SQL statement and a provider for named arguments.static @NotNull SqlQueryquery(@NotNull java.lang.String sql, @NotNull java.util.List<?> args)static @NotNull SqlQueryquery(@NotNull java.lang.String sql, java.lang.Object... args)Creates a newSqlQueryconsisting of given SQL statement and arguments.voidsetFetchDirection(@Nullable FetchDirection direction)A non-null fetch direction will be set as the fetch direction for the statements executed from this query.voidsetFetchSize(@Nullable java.lang.Integer size)A non-null fetch size will be set as the fetch size for the statements executed from this query.voidsetTimeout(@NotNull java.time.Duration timeout)A non-null timeout will be set as the timeout for the statements executed from this query.@NotNull java.lang.StringtoString()
-
-
-
Method Detail
-
query
@NotNull public static @NotNull SqlQuery query(@NotNull @NotNull java.lang.String sql, java.lang.Object... args)
Creates a newSqlQueryconsisting of given SQL statement and arguments. '?' characters act as placeholders for arguments in the query.
-
query
@NotNull public static @NotNull SqlQuery query(@NotNull @NotNull java.lang.String sql, @NotNull @NotNull java.util.List<?> args)
- See Also:
query(String, Object...)
-
namedQuery
@NotNull public static @NotNull SqlQuery namedQuery(@NotNull @NotNull java.lang.String sql, @NotNull @NotNull java.util.Map<java.lang.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 java.lang.String sql, @NotNull @NotNull java.lang.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 java.lang.String sql, @NotNull @NotNull VariableResolver variableResolver)
Creates a newSqlQueryconsisting 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
@NotNull public @NotNull java.lang.String 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
@NotNull public @NotNull java.util.List<?> getArguments()
Returns the list of arguments this query has.
-
getFetchSize
@Nullable public @Nullable java.lang.Integer getFetchSize()
Returns the fetch size of this query.
-
setFetchSize
public void setFetchSize(@Nullable @Nullable java.lang.Integer size)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:
java.lang.IllegalArgumentException- if size is < 0
-
getFetchDirection
@Nullable public @Nullable FetchDirection getFetchDirection()
Returns the fetch direction of this query.
-
setFetchDirection
public void setFetchDirection(@Nullable @Nullable FetchDirection direction)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
@Nullable public @Nullable java.time.Duration getTimeout()
Returns the timeout of this query.
-
setTimeout
public void setTimeout(@NotNull @NotNull java.time.Duration timeout)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:
java.lang.IllegalArgumentException- if timeout is negative- See Also:
Statement.setQueryTimeout(int)
-
toString
@NotNull public @NotNull java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-