Interface DatabaseAdapter
- All Known Implementing Classes:
DatabaseDialectServiceDatabaseAdapter,GenericDatabaseAdapter,MSSQL2008DatabaseAdapter,MSSQLDatabaseAdapter,MySQLDatabaseAdapter,Oracle12DatabaseAdapter,OracleDatabaseAdapter,PhoenixDatabaseAdapter,PostgreSQLDatabaseAdapter
public interface DatabaseAdapter
Interface for RDBMS/JDBC-specific code.
-
Method Summary
Modifier and TypeMethodDescriptiondefault StringgenerateTableName(String catalog, String schemaName, String tableName, TableSchema tableSchema) default StringgetAlterTableStatement(String tableName, List<ColumnDescription> columnsToAdd) getAutoCommitForReads(Integer fetchSize) Get the auto commit mode to use for reading from this database type.default StringgetCreateTableStatement(TableSchema tableSchema) Generates a CREATE TABLE statement using the specified table schemadefault StringgetInsertIgnoreStatement(String table, List<String> columnNames, Collection<String> uniqueKeyColumnNames) Returns an SQL INSERT_IGNORE statement - i.e.getName()getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) Returns a SQL SELECT statement with the given clauses applied.default StringgetSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset, String columnForPartitioning) Returns a SQL SELECT statement with the given clauses applied.default StringgetSQLForDataType(int sqlType) default StringgetTableAliasClause(String tableName) default StringgetUpsertStatement(String table, List<String> columnNames, Collection<String> uniqueKeyColumnNames) Returns an SQL UPSERT statement - i.e.default booleandefault booleanTells whether this adapter supports INSERT_IGNORE.default booleanTells whether this adapter supports UPSERT.
-
Method Details
-
getName
String getName() -
getDescription
String getDescription() -
getSelectStatement
String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) Returns a SQL SELECT statement with the given clauses applied.- Parameters:
tableName- The name of the table to fetch rows fromcolumnNames- The names of the columns to fetch from the tablewhereClause- The filter to apply to the statement. This should not include the WHERE keywordorderByClause- The columns/clause used for ordering the result rows. This should not include the ORDER BY keywordslimit- The value for the LIMIT clause (i.e. the number of rows to return)offset- The value for the OFFSET clause (i.e. the number of rows to skip)- Returns:
- A String containing a SQL SELECT statement with the given clauses applied
-
getSelectStatement
default String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset, String columnForPartitioning) Returns a SQL SELECT statement with the given clauses applied. Note that if this method is overridden, the other overloaded methods need to be overridden as well, to call this method with columnForPartitioning = false- Parameters:
tableName- The name of the table to fetch rows fromcolumnNames- The names of the columns to fetch from the tablewhereClause- The filter to apply to the statement. This should not include the WHERE keywordorderByClause- The columns/clause used for ordering the result rows. This should not include the ORDER BY keywordslimit- The value for the LIMIT clause (i.e. the number of rows to return)offset- The value for the OFFSET clause (i.e. the number of rows to skip)columnForPartitioning- The (optional) column name that, if provided, the limit and offset values are based on values from the column itself (rather than the row number)- Returns:
- A String containing a SQL SELECT statement with the given clauses applied
-
supportsUpsert
default boolean supportsUpsert()Tells whether this adapter supports UPSERT.- Returns:
- true if UPSERT is supported, false otherwise
-
supportsInsertIgnore
default boolean supportsInsertIgnore()Tells whether this adapter supports INSERT_IGNORE.- Returns:
- true if INSERT_IGNORE is supported, false otherwise
-
getUpsertStatement
default String getUpsertStatement(String table, List<String> columnNames, Collection<String> uniqueKeyColumnNames) Returns an SQL UPSERT statement - i.e. UPDATE record or INSERT if id doesn't exist.
There is no standard way of doing this so not all adapters support it - use together withsupportsUpsert()!- Parameters:
table- The name of the table in which to update/insert a record into.columnNames- The name of the columns in the table to add values to.uniqueKeyColumnNames- The name of the columns that form a unique key.- Returns:
- A String containing the parameterized jdbc SQL statement. The order and number of parameters are the same as that of the provided column list.
-
getInsertIgnoreStatement
default String getInsertIgnoreStatement(String table, List<String> columnNames, Collection<String> uniqueKeyColumnNames) Returns an SQL INSERT_IGNORE statement - i.e. Ignore record or INSERT if id doesn't exist.
There is no standard way of doing this so not all adapters support it - use together withsupportsInsertIgnore()!- Parameters:
table- The name of the table in which to ignore/insert a record into.columnNames- The name of the columns in the table to add values to.uniqueKeyColumnNames- The name of the columns that form a unique key.- Returns:
- A String containing the parameterized jdbc SQL statement. The order and number of parameters are the same as that of the provided column list.
-
getTableAliasClause
-
supportsCreateTableIfNotExists
default boolean supportsCreateTableIfNotExists() -
getCreateTableStatement
Generates a CREATE TABLE statement using the specified table schema- Parameters:
tableSchema- The table schema including column information- Returns:
- A String containing DDL to create the specified table
-
getAlterTableStatement
-
getAutoCommitForReads
Get the auto commit mode to use for reading from this database type. Most databases do not care which auto commit mode is used to read. For PostgreSQL it can make a difference.- Parameters:
fetchSize- The number of rows to retrieve at a time. Value of 0 means retrieve all rows at once.- Returns:
- Optional.empty() if auto commit mode does not matter and can be left as is. Return true or false to indicate whether auto commit needs to be true or false for this database.
-
getSQLForDataType
-
generateTableName
default String generateTableName(String catalog, String schemaName, String tableName, TableSchema tableSchema)
-