java.lang.Object
org.litebridge.db.spi.impl.AbstractDatabaseProvider
- All Implemented Interfaces:
DatabaseProvider
- Direct Known Subclasses:
H2DatabaseProvider
An abstract implementation of the
DatabaseProvider interface that provides a framework for interacting
with a database by managing SQL queries, metadata retrieval, and type conversions. This class serves as a base
for specific database implementations, handling common functionality while leaving database-specific details
to subclasses.
This class includes utility methods for preparing and executing SQL statements, fetching table metadata, and
performing insert, update, and select operations. It uses a caching mechanism for table metadata to improve
efficiency and ensures type conversion using a pluggable TypeConverter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DatabaseProviderContextprotected final ExecutionEngine -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a newAbstractDatabaseProvider. -
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.
-
Field Details
-
context
-
executionEngine
-
-
Constructor Details
-
AbstractDatabaseProvider
Constructs a newAbstractDatabaseProvider.
-
-
Method Details
-
metaData
Description copied from interface:DatabaseProviderRetrieve metadata/capabilities of this database provider.- Specified by:
metaDatain interfaceDatabaseProvider- Returns:
- metadata for this database provider.
-
databaseMetaData
Description copied from interface:DatabaseProviderRetrieve metadata for the connected database.- Specified by:
databaseMetaDatain interfaceDatabaseProvider- Parameters:
connectionProvider- theConnectionProviderused to get a database connection.- Returns:
- a
DatabaseMetaDataobject containing information about the connected database.
-
tableMetaData
Description copied from interface:DatabaseProviderRetrieve metadata for the specified table.- Specified by:
tableMetaDatain interfaceDatabaseProvider- 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.
-
executeUpdate
public <T extends Result> T executeUpdate(PreparedSql preparedSql, Class<T> resultType, ConnectionProvider connectionProvider) throws SQLException Description copied from interface:DatabaseProviderExecute a modifying SQL operation in the database using the provided statement.- Specified by:
executeUpdatein interfaceDatabaseProvider- 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
public BatchUpdateResult executeBatch(List<PreparedSql> preparedSqls, ConnectionProvider connectionProvider) throws SQLException Description copied from interface:DatabaseProviderExecute a batch of modifying SQL operations in the database using the provided statement.The statements must all have the same generated SQL.
- Specified by:
executeBatchin interfaceDatabaseProvider- 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
public List<Row> executeQuery(PreparedSql preparedSql, ConnectionProvider connectionProvider) throws SQLException Description copied from interface:DatabaseProviderExecutes a SELECT operation in the database using a pre-preparedPreparedSqlobject.- Specified by:
executeQueryin interfaceDatabaseProvider- 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.
-
typeConverter
Description copied from interface:DatabaseProviderRetrieve 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.- Specified by:
typeConverterin interfaceDatabaseProvider- Returns:
- the
TypeConverterinstance for handling data type conversions
-
sequenceColumnValueGenerator
public SequenceColumnValueGenerator sequenceColumnValueGenerator(String sequence) throws UnsupportedOperationException Description copied from interface:DatabaseProviderRetrieves 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.- Specified by:
sequenceColumnValueGeneratorin interfaceDatabaseProvider- 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.
-
toSql
Description copied from interface:DatabaseProviderConverts the givenOperationinto its corresponding SQL representation.This does not execute the operation, it only generates the SQL string.
- Specified by:
toSqlin interfaceDatabaseProvider- 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.
-
sqlFunctionRegistry
Description copied from interface:DatabaseProviderRetrieve 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.- Specified by:
sqlFunctionRegistryin interfaceDatabaseProvider- Returns:
- the
SqlFunctionRegistryinstance for managing SQL functions
-