Package org.ujorm.tools.jdbc
Class JdbcBuilder
java.lang.Object
org.ujorm.tools.jdbc.JdbcBuilder
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SqlBuilder
Deprecated.
PrepareStatement builder support
How to use a SELECT
JdbcBuilder sql = new JdbcBuilder()
.write("SELECT")
.column("t.id")
.column("t.name")
.write("FROM testTable t WHERE")
.andCondition("t.name", "=", "Test")
.andCondition("t.created", ">=", someDate);
for (ResultSet rs : sql.executeSelect(dbConnection)) {
int id = rs.getInt(1);
String name = rs.getString(2);
}
How to use a INSERT
JdbcBuilder sql = new JdbcBuilder()
.write("INSERT INTO testTable (")
.columnInsert("id", 10)
.columnInsert("name", "Test")
.columnInsert("date", someDate)
.write(")");
sql.executeUpdate(dbConnection);
How to use a UPDATE
JdbcBuilder sql = new JdbcBuilder()
.write("UPDATE testTable SET")
.columnUpdate("name", "Test")
.columnUpdate("date", SOME_DATE)
.write("WHERE")
.andCondition("id", "IN", 10, 20, 30)
.andCondition("created BETWEEN ? AND ?", null, someDate, someDate.plusMonths(1))
.andCondition("name", "IS NOT NULL")
sql.executeUpdate(dbConnection);
For more information see a jUnit test.- Author:
- Pavel Ponec
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classDeprecated.A value marker envelopeprotected static classDeprecated.A SQL fragment -
Field Summary
FieldsModifier and TypeFieldDescriptionDeprecated.Argument listprotected intDeprecated.Column counterprotected intDeprecated.Condition counterprotected booleanDeprecated.An insert sign for different renderingstatic final JdbcBuilder.SqlEnvelopeDeprecated.Separator of database columnsprotected static final charDeprecated.A value marker for SQLprotected final @NotNull List<CharSequence>Deprecated.SQL string fragmentsprotected static final StringDeprecated.A value marker for SQL -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Default constructorJdbcBuilder(@NotNull List<CharSequence> sql, @NotNull List<Object> arguments) Deprecated.Default constructor -
Method Summary
Modifier and TypeMethodDescription@NotNull JdbcBuilderaddArguments(@NotNull Object... values) Deprecated.Add argument values with no SAPARATOR and no MARKER (for a common use)protected @NotNull JdbcBuilderDeprecated.Add a value to SQL (inlucing MARKER)@NotNull JdbcBuilderandCondition(@NotNull CharSequence sqlCondition, @Nullable String operator, @Nullable Object value) Deprecated.Add a condition for a valid argument joined by AND operator@NotNull JdbcBuilderandCondition(@NotNull CharSequence sqlCondition, @Nullable String operator, @Nullable Object... values) Deprecated.Add a condition for a multivalue argument joined by AND operator@NotNull JdbcBuildercolumn(@NotNull CharSequence column) Deprecated.Add new column@NotNull JdbcBuildercolumnInsert(@NotNull CharSequence column, @NotNull Object value) Deprecated.Set new value to column by templatename = ?@NotNull JdbcBuildercolumnUpdate(@NotNull CharSequence column, @NotNull Object value) Deprecated.Set new value to column by templatename = ?@NotNull JdbcBuildercondition(@Nullable CharSequence sqlCondition, @Nullable String operator, @Nullable Object value) Deprecated.Add a condition for an argument with lengthprotected static @NotNull ValuePrintercreateValuePrinter(@NotNull Appendable result) Deprecated.Create a value printer@NotNull LoopingIterator<ResultSet>executeSelect(@NotNull Connection connection) Deprecated.Create an iterator ready to a loop statementfor ( ; ; )Supported SQL statements are: INSERT, UPDATE, DELETE .<T> @NotNull List<T>executeSelect(@NotNull Connection connection, SqlFunction<ResultSet, T> function) Deprecated.Create a new result listintexecuteUpdate(@NotNull Connection connection) Deprecated.Create statement and callPreparedStatement.executeUpdate().@NotNull Object[]Deprecated.Returns an array of all JDBC argumentsprotected intgetBufferSizeEstimation(boolean preview) Deprecated.Estimate a buffer size in characters@NotNull StringgetSql()Deprecated.Returns a SQL statement@NotNull StringgetSql(boolean preview) Deprecated.Returns a SQL text@NotNull JdbcBuilderorCondition(@NotNull CharSequence sqlCondition, @NotNull String operator, @Nullable Object... values) Deprecated.Add a condition for a multivalue argument joined by OR operator@NotNull JdbcBuilderorCondition(@NotNull CharSequence sqlCondition, @Nullable String operator, @Nullable Object value) Deprecated.Add a condition for a valid argument joined by OR operator@NotNull PreparedStatementprepareStatement(@NotNull Connection connection) Deprecated.Build the PreparedStatement with arguments@NotNull StringtoString()Deprecated.Returns a SQL preview including values<T> TuniqueValue(@NotNull Class<T> resultType, @NotNull Connection connection) Deprecated.Return the first column value of a unique resultset, else returnsnullvalue<T> @NotNull Optional<T>uniqueValueOptional(@NotNull Class<T> resultType, @NotNull Connection connection) Deprecated.Return the first column value of a unique resultset@NotNull JdbcBuilderDeprecated.Add an argument value (including a SEPARATOR and a MARKER) for buidling a SQL INSERT statement@NotNull JdbcBuilderwrite(@NotNull JdbcBuilder builder) Deprecated.Add a another statement to the end of this statement.@NotNull JdbcBuilderwrite(@Nullable CharSequence sqlFragment) Deprecated.Write a sql fragment including a space before@NotNull JdbcBuilderwriteMany(@NotNull CharSequence... sqlFragments) Deprecated.Write many sql fragments including a space before@NotNull JdbcBuilderwriteManyNoSpace(@NotNull CharSequence... sqlFragments) Deprecated.Write many sql fragments with no space before@NotNull JdbcBuilderwriteNoSpace(@NotNull CharSequence sqlFragment) Deprecated.Write a sql fragment with no space beforeprotected voidwriteOperator(@org.jetbrains.annotations.Nullable boolean andOperator, boolean enabled) Deprecated.Write an opetaror AND / OR
-
Field Details
-
ITEM_SEPARATOR
Deprecated.Separator of database columns -
VALUE_MARKER
Deprecated.A value marker for SQL- See Also:
-
SPACE
protected static final char SPACEDeprecated.A value marker for SQL- See Also:
-
sql
Deprecated.SQL string fragments -
arguments
Deprecated.Argument list -
conditionCounter
protected int conditionCounterDeprecated.Condition counter -
columnCounter
protected int columnCounterDeprecated.Column counter -
insertMode
protected boolean insertModeDeprecated.An insert sign for different rendering
-
-
Constructor Details
-
JdbcBuilder
public JdbcBuilder()Deprecated.Default constructor -
JdbcBuilder
public JdbcBuilder(@NotNull @NotNull List<CharSequence> sql, @NotNull @NotNull List<Object> arguments) Deprecated.Default constructor
-
-
Method Details
-
write
Deprecated.Add a another statement to the end of this statement. -
write
Deprecated.Write a sql fragment including a space before- Parameters:
sqlFragment- An empty ornullvalue is ignored.
-
writeNoSpace
Deprecated.Write a sql fragment with no space before- Parameters:
sqlFragment- An empty or null fragment is ignored.
-
writeMany
Deprecated.Write many sql fragments including a space before -
writeManyNoSpace
@NotNull public @NotNull JdbcBuilder writeManyNoSpace(@NotNull @NotNull CharSequence... sqlFragments) Deprecated.Write many sql fragments with no space before -
column
Deprecated.Add new column -
columnUpdate
@NotNull public @NotNull JdbcBuilder columnUpdate(@NotNull @NotNull CharSequence column, @NotNull @NotNull Object value) Deprecated.Set new value to column by templatename = ? -
columnInsert
@NotNull public @NotNull JdbcBuilder columnInsert(@NotNull @NotNull CharSequence column, @NotNull @NotNull Object value) Deprecated.Set new value to column by templatename = ? -
andCondition
@NotNull public @NotNull JdbcBuilder andCondition(@NotNull @NotNull CharSequence sqlCondition, @Nullable @Nullable String operator, @Nullable @Nullable Object value) Deprecated.Add a condition for a valid argument joined by AND operator- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theVALUE_MARKERautomaticallyvalue- Add the value to arguments including a markup to the SQL statement. To ignore the value, send anull.
-
andCondition
@NotNull public @NotNull JdbcBuilder andCondition(@NotNull @NotNull CharSequence sqlCondition, @Nullable @Nullable String operator, @Nullable @Nullable Object... values) Deprecated.Add a condition for a multivalue argument joined by AND operator- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theVALUE_MARKERautomaticallyvalues- The value of the condition (a replacement for the question character)
-
orCondition
@NotNull public @NotNull JdbcBuilder orCondition(@NotNull @NotNull CharSequence sqlCondition, @Nullable @Nullable String operator, @Nullable @Nullable Object value) Deprecated.Add a condition for a valid argument joined by OR operator- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theVALUE_MARKERautomaticallyvalue- Add the value to arguments including a markup to the SQL statement. To ignore the value, send anull.
-
orCondition
@NotNull public @NotNull JdbcBuilder orCondition(@NotNull @NotNull CharSequence sqlCondition, @NotNull @NotNull String operator, @Nullable @Nullable Object... values) Deprecated.Add a condition for a multivalue argument joined by OR operator- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theVALUE_MARKERautomaticallyvalues- The value of the condition (a replacement for the question character)
-
condition
@NotNull public @NotNull JdbcBuilder condition(@Nullable @Nullable CharSequence sqlCondition, @Nullable @Nullable String operator, @Nullable @Nullable Object value) Deprecated.Add a condition for an argument with length- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?". Send anullvalue to ignore the method.operator- An optional operator is followed by theVALUE_MARKERautomaticallyvalue- Add a value to arguments including a markup to the SQL statement. To ignore the value, send anull. An array is supported
-
writeOperator
protected void writeOperator(@Nullable @org.jetbrains.annotations.Nullable boolean andOperator, boolean enabled) Deprecated.Write an opetaror AND / OR- Parameters:
andOperator-enabled-
-
value
Deprecated.Add an argument value (including a SEPARATOR and a MARKER) for buidling a SQL INSERT statement- See Also:
-
addValue
Deprecated.Add a value to SQL (inlucing MARKER)- Parameters:
value- Anullvalue is ignored- See Also:
-
addArguments
Deprecated.Add argument values with no SAPARATOR and no MARKER (for a common use)- See Also:
-
getArguments
Deprecated.Returns an array of all JDBC arguments- Returns:
- Array of arguments
-
prepareStatement
@NotNull public @NotNull PreparedStatement prepareStatement(@NotNull @NotNull Connection connection) throws SQLException Deprecated.Build the PreparedStatement with arguments- Throws:
SQLException
-
executeSelect
@NotNull public @NotNull LoopingIterator<ResultSet> executeSelect(@NotNull @NotNull Connection connection) throws IllegalStateException, SQLException Deprecated.Create an iterator ready to a loop statementfor ( ; ; )Supported SQL statements are: INSERT, UPDATE, DELETE .- Throws:
IllegalStateExceptionSQLException
-
executeSelect
@NotNull public <T> @NotNull List<T> executeSelect(@NotNull @NotNull Connection connection, SqlFunction<ResultSet, T> function) throws SQLExceptionDeprecated.Create a new result list- Throws:
SQLException
-
executeUpdate
Deprecated.Create statement and callPreparedStatement.executeUpdate(). Supported SQL statements are: INSERT, UPDATE, DELETE .- Throws:
IllegalStateException
-
uniqueValue
@Nullable public <T> T uniqueValue(@NotNull @NotNull Class<T> resultType, @NotNull @NotNull Connection connection) Deprecated.Return the first column value of a unique resultset, else returnsnullvalue -
uniqueValueOptional
@NotNull public <T> @NotNull Optional<T> uniqueValueOptional(@NotNull @NotNull Class<T> resultType, @NotNull @NotNull Connection connection) Deprecated.Return the first column value of a unique resultset -
getSql
Deprecated.Returns a SQL text -
createValuePrinter
@NotNull protected static @NotNull ValuePrinter createValuePrinter(@NotNull @NotNull Appendable result) Deprecated.Create a value printer -
getBufferSizeEstimation
protected int getBufferSizeEstimation(boolean preview) Deprecated.Estimate a buffer size in characters -
getSql
Deprecated.Returns a SQL statement -
toString
Deprecated.Returns a SQL preview including values
-
SqlParamBuilderclass rather from the release 2.26.