Class StatementBuilder

java.lang.Object
me.hsgamer.hscore.database.client.sql.StatementBuilder

public class StatementBuilder extends Object
The PreparedStatement builder
  • Method Details

    • create

      public static StatementBuilder create(Connection connection)
      Create a new builder for the connection
      Parameters:
      connection - the connection
      Returns:
      the builder
    • addValues

      public StatementBuilder addValues(Object... values)
      Add values to the statement
      Parameters:
      values - the values
      Returns:
      the builder for chaining
    • addValues

      public StatementBuilder addValues(List<Object> values)
      Add values to the statement
      Parameters:
      values - the values
      Returns:
      the builder for chaining
    • execute

      public <T> T execute(SqlExecutor<T> sqlExecutor) throws SQLException
      Execute the statement
      Type Parameters:
      T - the type of the result
      Parameters:
      sqlExecutor - the executor
      Returns:
      the result
      Throws:
      SQLException - if there is an SQL error
    • query

      public <T> T query(ResultSetConverter<T> converter) throws SQLException
      Query from the connection and convert to the final object
      Type Parameters:
      T - the type of the final object
      Parameters:
      converter - the converter
      Returns:
      the final object
      Throws:
      SQLException - if there is an SQL error
    • consume

      public void consume(ResultSetConsumer consumer) throws SQLException
      Query from the connection and consume the result set
      Parameters:
      consumer - the consumer
      Throws:
      SQLException - if there is an SQL error
    • update

      public int update() throws SQLException
      Update the database
      Returns:
      the row count or 0 for nothing
      Throws:
      SQLException - if there is an SQL error
    • querySafe

      public <T> Optional<T> querySafe(ResultSetConverter<T> converter)
      Query from the connection and convert to the final object, but ignores exceptions
      Type Parameters:
      T - the type of the final object
      Parameters:
      converter - the converter
      Returns:
      the final object
    • consumeSafe

      public void consumeSafe(ResultSetConsumer consumer)
      Query from the connection and consume the result set, but ignores exceptions
      Parameters:
      consumer - the consumer
    • updateSafe

      public int updateSafe()
      Update the database but ignores exceptions
      Returns:
      the row count or 0 for nothing
    • getConnection

      public Connection getConnection()
      Get the connection
      Returns:
      the connection
    • getStatement

      public String getStatement()
      Get the statement
      Returns:
      the statement
    • setStatement

      public StatementBuilder setStatement(@Language("SQL") String statement)
      Set the statement to execute
      Parameters:
      statement - the statement
      Returns:
      the builder for chaining
    • getValues

      public List<Object> getValues()
      Get the values
      Returns:
      the values