- 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 Summary
Modifier and TypeMethodDescriptiondatabaseMetaData(ConnectionProvider connectionProvider) Retrieve metadata for the connected database.executeBatch(List<PreparedSql> preparedSqls, ConnectionProvider connectionProvider) Execute a batch of modifying SQL operations in the database using the provided statement.executeQuery(PreparedSql preparedSql, ConnectionProvider connectionProvider) Executes a SELECT operation in the database using a pre-preparedPreparedSqlobject.<T extends Result>
TexecuteUpdate(PreparedSql preparedSql, Class<T> resultType, ConnectionProvider connectionProvider) Execute a modifying SQL operation in the database using the provided statement.metaData()Retrieve metadata/capabilities of this database provider.sequenceColumnValueGenerator(String sequence) Retrieves aSequenceColumnValueGeneratorinstance for generating SQL fragments that fetch the next value from a specified database sequence.Retrieve theSqlFunctionRegistryinstance associated with the database provider.tableMetaData(Table table, ConnectionProvider connectionProvider) Retrieve metadata for the specified table.toSql(Operation operation, ConnectionProvider connectionProvider) Converts the givenOperationinto its corresponding SQL representation.Retrieve theTypeConverterinstance associated with the database provider.
-
Method Details
-
metaData
DatabaseProviderMetaData metaData()Retrieve metadata/capabilities of this database provider.- Returns:
- metadata for this database provider.
-
databaseMetaData
Retrieve metadata for the connected database.- Parameters:
connectionProvider- theConnectionProviderused to get a database connection.- Returns:
- a
DatabaseMetaDataobject containing information about the connected database. - Throws:
SQLException- if any SQL error occurs while retrieving the metadata.
-
tableMetaData
Retrieve metadata for the specified table.- Parameters:
table- theTableobject representing the table for which metadata is to be retrieved.connectionProvider- theConnectionProviderused to get a database connection.- Returns:
- a
TableMetaDataobject 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- thePreparedSqlfor the statement.resultType- the expected resultingUpdateOpResulttypeconnectionProvider- theConnectionProviderused to get a database connection.- Returns:
- an
Resultcontaining 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 ofPreparedSqlstatements to batch.connectionProvider- theConnectionProviderused to get a database connection.- Returns:
- an
Resultcontaining 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-preparedPreparedSqlobject.- Parameters:
preparedSql- thePreparedSqlobject containing the SQL query string and bind values.connectionProvider- theConnectionProviderused to get a database connection.- Returns:
- a
ListofRowobjects representing the results of the SELECT operation. - Throws:
SQLException- if any SQL error occurs during the execution of the SELECT operation.
-
toSql
Converts the givenOperationinto its corresponding SQL representation.This does not execute the operation, it only generates the SQL string.
- Parameters:
operation- theOperationobject representing the database operation (e.g., SELECT, INSERT, UPDATE, DELETE) to be converted to a SQL string.connectionProvider- theConnectionProviderused to obtain database-specific context or information required for SQL generation, such as metadata or dialect.- Returns:
- a
Stringcontaining the SQL representation of the givenOperation.
-
typeConverter
TypeConverter typeConverter()Retrieve theTypeConverterinstance associated with the database provider.The
TypeConverteris used for converting objects between different types, typically for database data type conversions and mapping domain-specific representations.- Returns:
- the
TypeConverterinstance for handling data type conversions
-
sequenceColumnValueGenerator
SequenceColumnValueGenerator sequenceColumnValueGenerator(String sequence) throws UnsupportedOperationException Retrieves aSequenceColumnValueGeneratorinstance 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
SequenceColumnValueGeneratorinstance 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 theSqlFunctionRegistryinstance associated with the database provider.The
SqlFunctionRegistryis used for registering and managing SQL functions that can be used in SQL queries executed by the database provider.- Returns:
- the
SqlFunctionRegistryinstance for managing SQL functions
-