Package org.dalesbred.query
Class QueryBuilder
java.lang.Object
org.dalesbred.query.QueryBuilder
A very simple builder that can be used to build queries dynamically.
Operates on a slightly higher level than StringBuilder in that it tracks
the query-variables and can be used as a building block for higher level
abstractions.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Placeholder to be used in queries for values -
Constructor Summary
ConstructorDescriptionConstructs a new empty QueryBuilder.QueryBuilder
(@NotNull String sql) Constructs a QueryBuilder with given initial SQL-fragment.QueryBuilder
(@NotNull String sql, Object... arguments) Constructs a QueryBuilder with given initial SQL-fragment and arguments. -
Method Summary
Modifier and TypeMethodDescription@NotNull QueryBuilder
addArgument
(@Nullable Object argument) Adds an argument to this query.@NotNull QueryBuilder
addArguments
(@NotNull Collection<?> args) Adds given arguments to this query.@NotNull QueryBuilder
addArguments
(Object... args) Adds given arguments to this query.@NotNull QueryBuilder
Appends given fragment to this query.@NotNull QueryBuilder
append
(@NotNull String sql, @NotNull Collection<?> args) Appends given fragment and arguments to this query.@NotNull QueryBuilder
Appends given fragment and arguments to this query.@NotNull QueryBuilder
Appends given query and its arguments to this query.@NotNull QueryBuilder
appendPlaceholders
(int count) Adds a given amount of comma-separated place-holders.@NotNull QueryBuilder
appendPlaceholders
(@NotNull Collection<?> args) Adds placeholders for all elements of collection and then adds then values of collection itself.@NotNull SqlQuery
build()
Builds an SQL query from the current state of this builder.boolean
Does this query have any arguments?boolean
isEmpty()
Is the query string empty?
-
Field Details
-
PLACEHOLDER
Placeholder to be used in queries for values- See Also:
-
-
Constructor Details
-
QueryBuilder
public QueryBuilder()Constructs a new empty QueryBuilder. -
QueryBuilder
Constructs a QueryBuilder with given initial SQL-fragment. -
QueryBuilder
Constructs a QueryBuilder with given initial SQL-fragment and arguments.
-
-
Method Details
-
append
Appends given fragment to this query. -
append
Appends given fragment and arguments to this query. -
append
@NotNull public @NotNull QueryBuilder append(@NotNull @NotNull String sql, @NotNull @NotNull Collection<?> args) Appends given fragment and arguments to this query. -
append
Appends given query and its arguments to this query. -
appendPlaceholders
Adds a given amount of comma-separated place-holders. The amount must be at last 1. -
appendPlaceholders
Adds placeholders for all elements of collection and then adds then values of collection itself. -
isEmpty
public boolean isEmpty()Is the query string empty? -
hasArguments
public boolean hasArguments()Does this query have any arguments? -
addArgument
Adds an argument to this query. -
addArguments
Adds given arguments to this query. -
addArguments
Adds given arguments to this query. -
build
Builds an SQL query from the current state of this builder.- Throws:
IllegalStateException
- if the builder is empty
-