Interface DatabaseProvider

All Known Implementing Classes:
AbstractDatabaseProvider, H2DatabaseProvider, OracleDatabaseProvider, PostgresDatabaseProvider, SQLiteDatabaseProvider, TransactionalDatabaseProvider

public interface DatabaseProvider
Main interface for interacting with a database.

This interface defines the operations for retrieving metadata, executing SQL queries, and managing data within a specific database backend.

  • Method Details

    • tableMetaData

      TableMetaData tableMetaData(Table table, ConnectionProvider connectionProvider) throws SQLException
      Retrieve metadata for the specified table.
      Parameters:
      table - the Table object representing the table for which metadata is to be retrieved.
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      a TableMetaData object containing metadata information about the specified table, including its columns, primary key, and other details.
      Throws:
      SQLException - if any SQL error occurs while retrieving the metadata.
    • insert

      InsertResult insert(Insert insert, ConnectionProvider connectionProvider) throws SQLException
      Execute an INSERT operation in the database using the provided Insert statement.
      Parameters:
      insert - the Insert statement containing the table, columns, and rows to insert.
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      an InsertResult containing the number of rows affected and any generated keys.
      Throws:
      SQLException - if any SQL error occurs during the execution of the insert operation.
    • update

      UpdateResult update(Update update, ConnectionProvider connectionProvider) throws SQLException
      Execute an UPDATE operation in the database using the provided Update statement.
      Parameters:
      update - the Update statement containing the table, columns, and rows to update.
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      an UpdateResult containing the number of rows affected.
      Throws:
      SQLException - if any SQL error occurs during the execution of the update operation.
    • select

      List<Row> select(Select select, ConnectionProvider connectionProvider) throws SQLException
      Execute a SELECT operation in the database using the provided Select statement.
      Parameters:
      select - the Select statement containing information about the table, expressions, joins, conditions, ordering, and optional limits for the query.
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      a List of Row objects representing the results of the SELECT operation.
      Throws:
      SQLException - if any SQL error occurs during the execution of the SELECT operation.
    • delete

      UpdateResult delete(Delete delete, ConnectionProvider connectionProvider) throws SQLException
      Execute a DELETE operation in the database using the provided Delete statement.
      Parameters:
      delete - the Delete statement containing the table and rows to delete.
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      an UpdateResult containing the number of rows affected.
      Throws:
      SQLException - if any SQL error occurs during the execution of the delete operation.
    • toSql

      String toSql(Operation operation, ConnectionProvider connectionProvider)
      Converts the given Operation into its corresponding SQL representation.

      This does not execute the operation, it only generates the SQL string.

      Parameters:
      operation - the Operation object representing the database operation (e.g., SELECT, INSERT, UPDATE, DELETE) to be converted to a SQL string.
      connectionProvider - the ConnectionProvider used to obtain database-specific context or information required for SQL generation, such as metadata or dialect.
      Returns:
      a String containing the SQL representation of the given Operation.
    • nativeSqlQuery

      List<Row> nativeSqlQuery(String sql, List<@Nullable Object> bindParameters, ConnectionProvider connectionProvider) throws SQLException
      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
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      a list of Row objects representing the result set of the query
      Throws:
      SQLException - if an error occurs during query execution
    • nativeSqlUpdate

      UpdateResult nativeSqlUpdate(String sql, List<@Nullable Object> bindParameters, ConnectionProvider connectionProvider) throws SQLException
      Executes a SQL update statement with the given SQL string and a 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 list of named parameters to bind to the statement
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      an UpdateResult object that encapsulates the outcome of the update operation
      Throws:
      SQLException - if an error occurs while executing the update statement
    • getTypeConverter

      TypeConverter getTypeConverter()
      Retrieve the TypeConverter instance associated with the database provider.

      The TypeConverter is used for converting objects between different types, typically for database data type conversions and mapping domain-specific representations.

      Returns:
      the TypeConverter instance for handling data type conversions
    • getSequenceColumnValueGenerator

      SequenceColumnValueGenerator getSequenceColumnValueGenerator(String sequence) throws UnsupportedOperationException
      Retrieves a SequenceColumnValueGenerator instance for generating SQL fragments that fetch the next value from a specified database sequence. This is typically used in SQL statements such as INSERT or UPDATE to generate unique values from a sequence.
      Parameters:
      sequence - the name of the database sequence from which the values will be generated. It is used to create the SQL fragment to retrieve the next value in the sequence.
      Returns:
      a SequenceColumnValueGenerator instance that generates SQL fragments for retrieving sequence values.
      Throws:
      UnsupportedOperationException - if the database provider does not support sequence-based value generation.
    • getSqlFunctionRegistry

      SqlFunctionRegistry getSqlFunctionRegistry()
      Retrieve the SqlFunctionRegistry instance associated with the database provider.

      The SqlFunctionRegistry is used for registering and managing SQL functions that can be used in SQL queries executed by the database provider.

      Returns:
      the SqlFunctionRegistry instance for managing SQL functions
    • getAliasTransformer

      AliasTransformer getAliasTransformer()
      Retrieve the AliasTransformer instance associated with the database provider.
      Returns:
      the AliasTransformer instance for transforming aliases