Class SqlBuilder

java.lang.Object
org.tamilnadujug.SqlBuilder
All Implemented Interfaces:
Sql<Integer>
Direct Known Subclasses:
SqlBuilder.PreparedSqlBuilder

public sealed class SqlBuilder extends Object implements Sql<Integer> permits SqlBuilder.PreparedSqlBuilder
Utility class for building and executing SQL queries with dynamic parameters. SqlBuilder helps manage SQL queries efficiently, reducing boilerplate and supporting both query execution and parameterized updates.
  • Constructor Details

    • SqlBuilder

      protected SqlBuilder(String theSql)
      Constructor that initializes the SqlBuilder with a given SQL query.
      Parameters:
      theSql - the SQL query to be prepared and executed
  • Method Details

    • prepareCall

      public static SqlBuilder.CallableSqlBuilder prepareCall(String theSql)
      Builds Callable Sql Builder from Sql.
      Parameters:
      theSql - the SQL query to be prepared and executed
      Returns:
      sqlBuilder
    • prepareSql

      public static SqlBuilder.PreparedSqlBuilder prepareSql(String theSql)
      Builds Prerpared Sql Builder from Sql.
      Parameters:
      theSql - the SQL query to be prepared and executed
      Returns:
      sqlBuilder
    • sql

      public static SqlBuilder sql(String theSql)
      Builds Sql Builder from Sql.
      Parameters:
      theSql - the SQL query to be prepared and executed
      Returns:
      sqlBuilder
    • getSql

      protected String getSql()
      Get the SQL Query.
      Returns:
      sql
    • execute

      public Integer execute(Connection connection) throws SQLException
      Executes the SQL operation using the given JDBC connection.
      Specified by:
      execute in interface Sql<Integer>
      Parameters:
      connection - JDBC connection to use for execution
      Returns:
      result of the SQL operation
      Throws:
      SQLException - if an error occurs during execution
    • queryForExists

      public Sql<Boolean> queryForExists()
      Provides if record exists.
      Returns:
      a new Query instance for execution
    • queryForByte

      public Sql<Byte> queryForByte()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Byte.
      Returns:
      a new Query instance for execution
    • queryForListOfByte

      public Sql<List<Byte>> queryForListOfByte()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Byte.
      Returns:
      a new Query instance for execution
    • queryForBytes

      public Sql<byte[]> queryForBytes()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Byte Array.
      Returns:
      a new Query instance for execution
    • queryForListOfBytes

      public Sql<List<byte[]>> queryForListOfBytes()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Byte Array.
      Returns:
      a new Query instance for execution
    • queryForInt

      public Sql<Integer> queryForInt()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to an Integer.
      Returns:
      a new Query instance for execution
    • queryForListOfInt

      public Sql<List<Integer>> queryForListOfInt()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to List of Integer.
      Returns:
      a new Query instance for execution
    • queryForShort

      public Sql<Short> queryForShort()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Short.
      Returns:
      a new Query instance for execution
    • queryForListOfShort

      public Sql<List<Short>> queryForListOfShort()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Short.
      Returns:
      a new Query instance for execution
    • queryForString

      public Sql<String> queryForString()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a String.
      Returns:
      a new Query instance for execution
    • queryForListOfString

      public Sql<List<String>> queryForListOfString()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a String.
      Returns:
      a new Query instance for execution
    • queryForURL

      public Sql<URL> queryForURL()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a URL.
      Returns:
      a new Query instance for execution
    • queryForListOfURL

      public Sql<List<URL>> queryForListOfURL()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of URL.
      Returns:
      a new Query instance for execution
    • queryForDouble

      public Sql<Double> queryForDouble()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Double.
      Returns:
      a new Query instance for execution
    • queryForListOfDouble

      public Sql<List<Double>> queryForListOfDouble()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Double.
      Returns:
      a new Query instance for execution
    • queryForFloat

      public Sql<Float> queryForFloat()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Float.
      Returns:
      a new Query instance for execution
    • queryForListOfFloat

      public Sql<List<Float>> queryForListOfFloat()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Float.
      Returns:
      a new Query instance for execution
    • queryForBigDecimal

      public Sql<BigDecimal> queryForBigDecimal()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a BigDecimal.
      Returns:
      a new Query instance for execution
    • queryForListOfBigDecimal

      public Sql<List<BigDecimal>> queryForListOfBigDecimal()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of BigDecimal.
      Returns:
      a new Query instance for execution
    • queryForBoolean

      public Sql<Boolean> queryForBoolean()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Boolean.
      Returns:
      a new Query instance for execution
    • queryForListOfBoolean

      public Sql<List<Boolean>> queryForListOfBoolean()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Boolean.
      Returns:
      a new Query instance for execution
    • queryForLong

      public Sql<Long> queryForLong()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Long.
      Returns:
      a new Query instance for execution
    • queryForListOfLong

      public Sql<List<Long>> queryForListOfLong()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Long.
      Returns:
      a new Query instance for execution
    • queryForDate

      public Sql<Date> queryForDate()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Date.
      Returns:
      a new Query instance for execution
    • queryForListOfDate

      public Sql<List<Date>> queryForListOfDate()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Date.
      Returns:
      a new Query instance for execution
    • queryForTime

      public Sql<Time> queryForTime()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Time.
      Returns:
      a new Query instance for execution
    • queryForListOfTime

      public Sql<List<Time>> queryForListOfTime()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Time.
      Returns:
      a new Query instance for execution
    • queryForTimestamp

      public Sql<Timestamp> queryForTimestamp()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Timestamp.
      Returns:
      a new Query instance for execution
    • queryForListOfTimestamp

      public Sql<List<Timestamp>> queryForListOfTimestamp()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Timestamp.
      Returns:
      a new Query instance for execution
    • queryForObject

      public Sql<Object> queryForObject()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to an Object.
      Returns:
      a new Query instance for execution
    • queryForListOfObject

      public Sql<List<Object>> queryForListOfObject()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Object.
      Returns:
      a new Query instance for execution
    • queryForOne

      public <T> Sql<T> queryForOne(RowMapper<T> rowMapper)
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a specific object type using the provided RowMapper.
      Type Parameters:
      T - the type of object to map the result set to
      Parameters:
      rowMapper - an implementation of RowMapper to map each row of the result set
      Returns:
      a new Query instance for execution
    • queryForList

      public <T> Sql<List<T>> queryForList(RowMapper<T> rowMapper)
      Creates a new Query object that can be used to execute a SELECT query and map the result set to list of a specific object type using the provided RowMapper.
      Type Parameters:
      T - the type of object to map the result set to
      Parameters:
      rowMapper - an implementation of RowMapper to map each row of the result set
      Returns:
      a new Query instance for execution
    • exists

      protected boolean exists(Connection connection) throws SQLException
      Checks if Record Exists.
      Parameters:
      connection -
      Returns:
      exists
      Throws:
      SQLException
    • addBatch

      public SqlBuilder.Batch addBatch(String sqlQuery)
      add Batch.
      Parameters:
      sqlQuery -
      Returns:
      new Batch
    • queryGeneratedKeyForByte

      public Sql<Byte> queryGeneratedKeyForByte()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Byte.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfByte

      public Sql<List<Byte>> queryGeneratedKeysAsListOfByte()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Byte.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForBytes

      public Sql<byte[]> queryGeneratedKeyForBytes()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Byte Array.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfBytes

      public Sql<List<byte[]>> queryGeneratedKeysAsListOfBytes()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Byte Array.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForInt

      public Sql<Integer> queryGeneratedKeyForInt()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to an Integer.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfInt

      public Sql<List<Integer>> queryGeneratedKeysAsListOfInt()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to List of Integer.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForShort

      public Sql<Short> queryGeneratedKeyForShort()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Short.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfShort

      public Sql<List<Short>> queryGeneratedKeysAsListOfShort()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Short.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForString

      public Sql<String> queryGeneratedKeyForString()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a String.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfString

      public Sql<List<String>> queryGeneratedKeysAsListOfString()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a String.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForURL

      public Sql<URL> queryGeneratedKeyForURL()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a URL.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfURL

      public Sql<List<URL>> queryGeneratedKeysAsListOfURL()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of URL.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForDouble

      public Sql<Double> queryGeneratedKeyForDouble()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Double.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfDouble

      public Sql<List<Double>> queryGeneratedKeysAsListOfDouble()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Double.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForFloat

      public Sql<Float> queryGeneratedKeyForFloat()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Float.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfFloat

      public Sql<List<Float>> queryGeneratedKeysAsListOfFloat()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Float.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForBigDecimal

      public Sql<BigDecimal> queryGeneratedKeyForBigDecimal()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a BigDecimal.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfBigDecimal

      public Sql<List<BigDecimal>> queryGeneratedKeysAsListOfBigDecimal()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of BigDecimal.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForBoolean

      public Sql<Boolean> queryGeneratedKeyForBoolean()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Boolean.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfBoolean

      public Sql<List<Boolean>> queryGeneratedKeysAsListOfBoolean()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Boolean.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForLong

      public Sql<Long> queryGeneratedKeyForLong()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Long.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfLong

      public Sql<List<Long>> queryGeneratedKeysAsListOfLong()
      Creates a new Query object that can be used to execute a SELECT query and map the result set the List of Long.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForDate

      public Sql<Date> queryGeneratedKeyForDate()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Date.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfDate

      public Sql<List<Date>> queryGeneratedKeysAsListOfDate()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Date.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForTime

      public Sql<Time> queryGeneratedKeyForTime()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Time.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfTime

      public Sql<List<Time>> queryGeneratedKeysAsListOfTime()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Time.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForTimestamp

      public Sql<Timestamp> queryGeneratedKeyForTimestamp()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to a Timestamp.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfTimestamp

      public Sql<List<Timestamp>> queryGeneratedKeysAsListOfTimestamp()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Timestamp.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeyForObject

      public Sql<Object> queryGeneratedKeyForObject()
      Creates a new Query object that can be used to execute a SELECT query and map the result set to an Object.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsListOfObject

      public Sql<List<Object>> queryGeneratedKeysAsListOfObject()
      Creates a new Query object that can be used to execute a SELECT query and map the result set List of Object.
      Returns:
      a new Query instance for execution
    • queryGeneratedKeys

      public <T> Sql<T> queryGeneratedKeys(RowMapper<T> rowMapper)
      Creates a new Generated Keys object that can be used to execute a SELECT query and map the result set to a specific object type using the provided RowMapper.
      Type Parameters:
      T - the type of object to map the result set to
      Parameters:
      rowMapper - an implementation of RowMapper to map each row of the result set
      Returns:
      a new Query instance for execution
    • queryGeneratedKeysAsList

      public <T> Sql<List<T>> queryGeneratedKeysAsList(RowMapper<T> rowMapper)
      Creates query to get Generated Keys As a List.
      Type Parameters:
      T - the type of object to map the result set to
      Parameters:
      rowMapper - an implementation of RowMapper to map each row of the result set
      Returns:
      a new Query instance for execution