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 Summary
ConstructorsConstructorDescriptionNativeSqlContext(TransactionalDatabaseProvider databaseProvider) Constructs a newNativeSqlContextinstance. -
Method Summary
Modifier and TypeMethodDescriptionExecutes a SQL update statement with the given SQL string and a variable-length list of positional bind parameters.Executes a SQL update statement with the given SQL string and a list of positional bind parameters.Executes a SQL update statement with the given SQL string and a map of named bind parameters.executeBatch(String sql, List<List<Object>> rowBindParameters) Executes a batch SQL update statement with the given SQL string and a per-row list containing per-row positional bind parameters.Executes a batch SQL update statement with the given SQL string and a per-row list containing named bind parameters.Parses the specified SQL statement and returns a positional parameter-based version along with bind parameter metadata.Executes a SQL query with the given SQL string and a variable-length list of positional bind parameters.Executes a SQL query with the given SQL string and a list of positional bind parameters.Executes a SQL query with the given SQL string and a map of named bind parameters.
-
Constructor Details
-
NativeSqlContext
Constructs a newNativeSqlContextinstance.- Parameters:
databaseProvider- the database provider to use for executing SQL operations
-
-
Method Details
-
query
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 benullbindParameters- the variable-length list of parameters to bind to the query- Returns:
- a list of
Rowobjects representing the result set of the query - Throws:
IllegalStateException- if an error occurs during query execution- See Also:
-
query
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 benullbindParameters- the list of parameters to bind to the query- Returns:
- a list of
Rowobjects representing the result set of the query - Throws:
IllegalStateException- if an error occurs during query execution- See Also:
-
query
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 benullbindParameters- the map of named parameters to bind to the query- Returns:
- a list of
Rowobjects representing the result set of the query - Throws:
IllegalStateException- if an error occurs during query execution- See Also:
-
execute
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 benullbindParameters- the variable-length list of positional parameters to bind to the statement- Returns:
- an
UpdateResultobject that encapsulates the outcome of the update operation - Throws:
IllegalStateException- if an error occurs while executing the update statement- See Also:
-
execute
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 benullbindParameters- the variable-length list of positional parameters to bind to the statement- Returns:
- an
UpdateResultobject that encapsulates the outcome of the update operation - Throws:
IllegalStateException- if an error occurs while executing the update statement- See Also:
-
execute
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 benullbindParameters- the map of named parameters to bind to the statement- Returns:
- an
UpdateResultobject that encapsulates the outcome of the update operation - Throws:
IllegalStateException- if an error occurs while executing the update statement- See Also:
-
executeBatch
Executes a batch SQL update statement with the given SQL string and a per-row list containing per-row positional bind parameters.- Parameters:
sql- the SQL update statement to execute; must not benullrowBindParameters- the list of positional parameters to bind to the statement, per row- Returns:
- the outcome of the batch update operation
- Throws:
IllegalStateException- if an error occurs while executing the update statement- See Also:
-
executeNamedBatch
public BatchUpdateResult executeNamedBatch(String sql, List<Map<String, @Nullable Object>> rowBindParameters) Executes a batch SQL update statement with the given SQL string and a per-row list containing named bind parameters.- Parameters:
sql- the SQL update statement to execute; must not benullrowBindParameters- the list of named parameters to bind to the statement, per row- Returns:
- the outcome of the batch update operation
- Throws:
IllegalStateException- if an error occurs while executing the update statement- See Also:
-
parse
Parses the specified SQL statement and returns a positional parameter-based version along with bind parameter metadata.For named parameter-based queries, this translates the SQL into a positional parameter-based version and provides the positional index of each bind parameter.
This returns the cached parsed SQL statement if it is found in the cache. Otherwise, it parses the input SQL and caches the parsed SQL statement.
- Parameters:
sql- SQL statement to parse/cache.- Returns:
- Parsed (and cached) SQL statement and metadata.
-