Interface DatabaseProvider

All Known Subinterfaces:
LitebridgeOverrideDatabaseProvider<LB>
All Known Implementing Classes:
AbstractDatabaseProvider, H2DatabaseProvider, 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

    • metaData

      Retrieve metadata/capabilities of this database provider.
      Returns:
      metadata for this database provider.
    • databaseMetaData

      DatabaseMetaData databaseMetaData(ConnectionProvider connectionProvider) throws SQLException
      Retrieve metadata for the connected database.
      Parameters:
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      a DatabaseMetaData object containing information about the connected database.
      Throws:
      SQLException - if any SQL error occurs while retrieving the metadata.
    • 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.
    • executeUpdate

      <T extends Result> T executeUpdate(PreparedSql preparedSql, Class<T> resultType, ConnectionProvider connectionProvider) throws SQLException
      Execute a modifying SQL operation in the database using the provided statement.
      Parameters:
      preparedSql - the PreparedSql for the statement.
      resultType - the expected resulting UpdateOpResult type
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      an Result containing e.g. the number of rows affected and any generated keys.
      Throws:
      SQLException - if any SQL error occurs during the execution of the SELECT operation.
    • executeBatch

      BatchUpdateResult executeBatch(List<PreparedSql> preparedSqls, ConnectionProvider connectionProvider) throws SQLException
      Execute a batch of modifying SQL operations in the database using the provided statement.

      The statements must all have the same generated SQL.

      Parameters:
      preparedSqls - the list of PreparedSql statements to batch.
      connectionProvider - the ConnectionProvider used to get a database connection.
      Returns:
      an Result containing e.g. the number of rows affected and any generated keys.
      Throws:
      SQLException - if any SQL error occurs during the execution of the SELECT operation.
    • executeQuery

      List<Row> executeQuery(PreparedSql preparedSql, ConnectionProvider connectionProvider) throws SQLException
      Executes a SELECT operation in the database using a pre-prepared PreparedSql object.
      Parameters:
      preparedSql - the PreparedSql object containing the SQL query string and bind values.
      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.
    • 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.
    • typeConverter

      TypeConverter typeConverter()
      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
    • sequenceColumnValueGenerator

      SequenceColumnValueGenerator sequenceColumnValueGenerator(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.
    • sqlFunctionRegistry

      SqlFunctionRegistry sqlFunctionRegistry()
      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