Package tools.jdbc

Class JdbcBuilder

java.lang.Object
tools.jdbc.JdbcBuilder
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SqlBuilder

public class JdbcBuilder extends Object implements Serializable
Deprecated.
Use the SqlParamBuilder class rather from the release 2.26.
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:
  • Field Details

    • ITEM_SEPARATOR

      public static final JdbcBuilder.SqlEnvelope ITEM_SEPARATOR
      Deprecated.
      Separator of database columns
    • VALUE_MARKER

      protected static final String VALUE_MARKER
      Deprecated.
      A value marker for SQL
      See Also:
    • SPACE

      protected static final char SPACE
      Deprecated.
      A value marker for SQL
      See Also:
    • sql

      @NotNull protected final @NotNull List<CharSequence> sql
      Deprecated.
      SQL string fragments
    • arguments

      @NotNull protected final @NotNull List<Object> arguments
      Deprecated.
      Argument list
    • conditionCounter

      protected int conditionCounter
      Deprecated.
      Condition counter
    • columnCounter

      protected int columnCounter
      Deprecated.
      Column counter
    • insertMode

      protected boolean insertMode
      Deprecated.
      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

      @NotNull public @NotNull JdbcBuilder write(@NotNull @NotNull JdbcBuilder builder)
      Deprecated.
      Add a another statement to the end of this statement.
    • write

      @NotNull public @NotNull JdbcBuilder write(@Nullable @Nullable CharSequence sqlFragment)
      Deprecated.
      Write a sql fragment including a space before
      Parameters:
      sqlFragment - An empty or null value is ignored.
    • writeNoSpace

      @NotNull public @NotNull JdbcBuilder writeNoSpace(@NotNull @NotNull CharSequence sqlFragment)
      Deprecated.
      Write a sql fragment with no space before
      Parameters:
      sqlFragment - An empty or null fragment is ignored.
    • writeMany

      @NotNull public @NotNull JdbcBuilder writeMany(@NotNull @NotNull CharSequence... sqlFragments)
      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

      @NotNull public @NotNull JdbcBuilder column(@NotNull @NotNull CharSequence 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 template name = ?
    • columnInsert

      @NotNull public @NotNull JdbcBuilder columnInsert(@NotNull @NotNull CharSequence column, @NotNull @NotNull Object value)
      Deprecated.
      Set new value to column by template name = ?
    • 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 the VALUE_MARKER automatically
      value - Add the value to arguments including a markup to the SQL statement. To ignore the value, send a null.
    • 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 the VALUE_MARKER automatically
      values - 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 the VALUE_MARKER automatically
      value - Add the value to arguments including a markup to the SQL statement. To ignore the value, send a null.
    • 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 the VALUE_MARKER automatically
      values - 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 a null value to ignore the method.
      operator - An optional operator is followed by the VALUE_MARKER automatically
      value - Add a value to arguments including a markup to the SQL statement. To ignore the value, send a null. 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

      @NotNull public @NotNull JdbcBuilder value(@NotNull @NotNull Object value)
      Deprecated.
      Add an argument value (including a SEPARATOR and a MARKER) for buidling a SQL INSERT statement
      See Also:
    • addValue

      @NotNull protected @NotNull JdbcBuilder addValue(@Nullable @Nullable Object value)
      Deprecated.
      Add a value to SQL (inlucing MARKER)
      Parameters:
      value - A null value is ignored
      See Also:
    • addArguments

      @NotNull public @NotNull JdbcBuilder addArguments(@NotNull @NotNull Object... values)
      Deprecated.
      Add argument values with no SAPARATOR and no MARKER (for a common use)
      See Also:
    • getArguments

      @NotNull public @NotNull Object[] 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 statement for ( ; ; ) Supported SQL statements are: INSERT, UPDATE, DELETE .
      Throws:
      IllegalStateException
      SQLException
    • executeSelect

      @NotNull public <T> @NotNull List<T> executeSelect(@NotNull @NotNull Connection connection, SqlFunction<ResultSet,T> function) throws SQLException
      Deprecated.
      Create a new result list
      Throws:
      SQLException
    • executeUpdate

      public int executeUpdate(@NotNull @NotNull Connection connection) throws IllegalStateException
      Deprecated.
      Create statement and call PreparedStatement.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 returns null value
    • 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

      @NotNull public @NotNull String getSql(boolean preview)
      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

      @NotNull public @NotNull String getSql()
      Deprecated.
      Returns a SQL statement
    • toString

      @NotNull public @NotNull String toString()
      Deprecated.
      Returns a SQL preview including values
      Overrides:
      toString in class Object