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
      Parameters:
      connection - the connection
      Returns:
      the builder
    • setStatement

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

      public StatementBuilder setValues(Object... values)
      Set the values
      Parameters:
      values - the values
      Returns:
      the builder for chaining
    • setValues

      public StatementBuilder setValues(List<Object> values)
      Set the values
      Parameters:
      values - the values
      Returns:
      the builder for chaining
    • addValues

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

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

      public <T> T execute(StatementBuilder.Executor<T> executor) throws SQLException
      Execute the statement
      Type Parameters:
      T - the result type
      Parameters:
      executor - the executor
      Returns:
      the result
      Throws:
      SQLException - if a SQL error occurs
    • query

      public <T> T query(StatementBuilder.ResultSetConverter<T> converter) throws SQLException
      Query the statement
      Type Parameters:
      T - the result type
      Parameters:
      converter - the converter
      Returns:
      the result
      Throws:
      SQLException - if a SQL error occurs
    • queryList

      public <T> List<T> queryList(StatementBuilder.ResultSetConverter<T> converter) throws SQLException
      Query the statement and return a list
      Type Parameters:
      T - the result type
      Parameters:
      converter - the converter
      Returns:
      the result
      Throws:
      SQLException - if a SQL error occurs
    • consume

      public void consume(StatementBuilder.ResultSetConsumer consumer) throws SQLException
      Consume the statement
      Parameters:
      consumer - the consumer
      Throws:
      SQLException - if a SQL error occurs
    • update

      public int update() throws SQLException
      Update the statement
      Returns:
      the result
      Throws:
      SQLException - if a SQL error occurs
    • querySafe

      public <T> Optional<T> querySafe(StatementBuilder.ResultSetConverter<T> converter)
      Query the statement but ignore the exception
      Type Parameters:
      T - the result type
      Parameters:
      converter - the converter
      Returns:
      the result
    • queryListSafe

      public <T> Optional<List<T>> queryListSafe(StatementBuilder.ResultSetConverter<T> converter)
      Query the statement and return a list but ignore the exception
      Type Parameters:
      T - the result type
      Parameters:
      converter - the converter
      Returns:
      the result
    • consumeSafe

      public void consumeSafe(StatementBuilder.ResultSetConsumer consumer)
      Consume the statement but ignore the exception
      Parameters:
      consumer - the consumer
    • updateSafe

      public int updateSafe()
      Update the statement but ignore the exception
      Returns:
      the result