Class NativeSqlContext

java.lang.Object
org.litebridge.orm.nativesql.NativeSqlContext

public final class NativeSqlContext extends Object
Provides a context for executing native SQL queries and updates in a transactional database environment.

This class facilitates the execution of raw SQL operations using the capabilities provided by a TransactionalDatabaseProvider.

It supports parameterised SQL queries and updates with flexible parameter binding and ensures that all database interactions are performed in a transactional context.

  • Constructor Details

    • NativeSqlContext

      public NativeSqlContext(TransactionalDatabaseProvider databaseProvider)
      Constructs a new NativeSqlContext instance.
      Parameters:
      databaseProvider - the database provider to use for executing SQL operations
  • Method Details

    • query

      public List<Row> query(String sql, Object... bindParameters)
      Executes a SQL query with the given SQL string and a variable-length list of positional bind parameters.

      This method takes a variable number of parameters and delegates to the overloaded query method that accepts a list of bind parameters.

      Parameters:
      sql - the SQL query string to be executed; must not be null
      bindParameters - the variable-length list of parameters to bind to the query
      Returns:
      a list of Row objects representing the result set of the query
      Throws:
      IllegalStateException - if an error occurs during query execution
    • query

      public List<Row> query(String sql, List<@Nullable Object> bindParameters)
      Executes a SQL query with the given SQL string and a list of positional bind parameters.
      Parameters:
      sql - the SQL query string to be executed; must not be null
      bindParameters - the list of parameters to bind to the query
      Returns:
      a list of Row objects representing the result set of the query
      Throws:
      IllegalStateException - if an error occurs during query execution
    • query

      public List<Row> query(String sql, Map<String,@Nullable Object> bindParameters)
      Executes a SQL query with the given SQL string and a map of named bind parameters.
      Parameters:
      sql - the SQL query string to be executed; must not be null
      bindParameters - the map of named parameters to bind to the query
      Returns:
      a list of Row objects representing the result set of the query
      Throws:
      IllegalStateException - if an error occurs during query execution
    • execute

      public UpdateResult execute(String sql, Object... bindParameters)
      Executes a SQL update statement with the given SQL string and a variable-length list of positional bind parameters.

      This method delegates to the overloaded execute method that accepts a list of bind parameters.

      Parameters:
      sql - the SQL update statement to execute; must not be null
      bindParameters - the variable-length list of positional parameters to bind to the statement
      Returns:
      an UpdateResult object that encapsulates the outcome of the update operation
      Throws:
      IllegalStateException - if an error occurs while executing the update statement
    • execute

      public UpdateResult execute(String sql, List<@Nullable Object> bindParameters)
      Executes a SQL update statement with the given SQL string and a list of positional bind parameters.
      Parameters:
      sql - the SQL update statement to execute; must not be null
      bindParameters - the variable-length list of positional parameters to bind to the statement
      Returns:
      an UpdateResult object that encapsulates the outcome of the update operation
      Throws:
      IllegalStateException - if an error occurs while executing the update statement
    • execute

      public UpdateResult execute(String sql, Map<String,@Nullable Object> bindParameters)
      Executes a SQL update statement with the given SQL string and a map of named bind parameters.
      Parameters:
      sql - the SQL update statement to execute; must not be null
      bindParameters - the map of named parameters to bind to the statement
      Returns:
      an UpdateResult object that encapsulates the outcome of the update operation
      Throws:
      IllegalStateException - if an error occurs while executing the update statement