Package net.sf.basedb.core.dbengine
Class AbstractDbEngine
java.lang.Object
net.sf.basedb.core.dbengine.AbstractDbEngine
- All Implemented Interfaces:
DbEngine
- Direct Known Subclasses:
DefaultDbEngine
,MySQLEngine
,PostgresDbEngine
An abstract superclass with default implementations for most
DbEngine
methods. Subclasses only needs to override methods which behave differently.- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2016-12-13 13:01:22 +0100 (ti, 13 dec 2016) $
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturnABS(<value>)
.castToDate
(String value) Get a function that casts a date/timestamp to a date (eg. no time should be included in the result).boolean
Returns FALSE.boolean
When dropping an index, must foreign keys that uses the same columns also be dropped (before dropping the index)?ReturnEXP(<value>)
.getApproximateRowCountSql
(String catalog, String schema, String table) Get an SQL statement that returns an approximate count for the number of rows in the given table.getCaseSensitiveVarchar
(int length) Return null.getCatalogName
(String catalog, String schema) Return the catalog name.getCreatePartialIndexSql
(String catalog, String schema, String table, String name, Set<String> columns, String condition) Default implementation returns a regular non-unique index.int
Returns 10000.getQuotedName
(String name) Put quotes (") around the name.getSchemaName
(String catalog, String schema) Return the schema name.inspectSchemaGenerationSQL
(String sql, Dialect dialect, SchemaGenerator.Mode mode) Skip all "create index ..." statements.boolean
isValidColumnName
(String columnName) Checks that the name only contains the following characters: a-zA-Z0-9_ It must also start with a letter or underscore.protected boolean
isValidName
(String name) Check that the name only contains a-zA-Z0-9_ and starts with a letter or underscore.boolean
isValidTableName
(String tableName) Checks that the name only contains the following characters: a-zA-Z0-9_ It must also start with a letter or underscore.ReturnLN(<value>)
.makeSafeCreateTable
(String sql, String catalog, String schema, String table) Return the SQL unmodified.ReturnPOWER(<base>, <exponent>)
.Return<value> = <regexp>
boolean
Returns FALSE.boolean
Returns FALSE.boolean
Returns FALSE.boolean
Returns FALSE.boolean
Returns FALSE.boolean
If the underlying database need to create a savepoint before executing an SQL statement that results in an error in order to be able to continue using the same transaction for other SQL queries.boolean
Most databases doesn't.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sf.basedb.core.dbengine.DbEngine
analyzeAfterBatchOperation, caseInsensitiveComparison, getAnalyzeTableSql, getCreateForeignKeySql, getCreateIndexSql, getCreatePrimaryKeySql, getCreateSchemaSql, getCreateTemporaryIdTable, getDropForeignKeySql, getDropIndexSql, getDropPrimaryKey, getInsertAutoIncrementSql, getOptimizeTableSql
-
Field Details
-
valid
A regexp checking for invalid characters.
-
-
Constructor Details
-
AbstractDbEngine
public AbstractDbEngine()Create AbstractDbEngine.
-
-
Method Details
-
getCatalogName
Return the catalog name.- Specified by:
getCatalogName
in interfaceDbEngine
- Parameters:
catalog
- The catalog name (always not null)schema
- The schema name (always not null)- Returns:
- Should return a non-null value
- Since:
- 3.4
-
getSchemaName
Return the schema name.- Specified by:
getSchemaName
in interfaceDbEngine
- Parameters:
catalog
- The catalog name (always not null)schema
- The schema name (always not null)- Returns:
- The schema name or null to indicate that schemas are not used
- Since:
- 3.4
-
dropForeignKeysUsedInIndex
public boolean dropForeignKeysUsedInIndex()Description copied from interface:DbEngine
When dropping an index, must foreign keys that uses the same columns also be dropped (before dropping the index)? Default is FALSE, but MySQL need TRUE.- Specified by:
dropForeignKeysUsedInIndex
in interfaceDbEngine
- Returns:
- FALSE
- Since:
- 3.6
-
getCreatePartialIndexSql
public String getCreatePartialIndexSql(String catalog, String schema, String table, String name, Set<String> columns, String condition) Default implementation returns a regular non-unique index.- Specified by:
getCreatePartialIndexSql
in interfaceDbEngine
- Parameters:
catalog
- The name of the catalog (database) where the table is located, or null if it is located in the current catalogschema
- The name of the schema where the table is located, or null if is located in the current schematable
- The name of the tablename
- The name of the index to be createdcolumns
- The name of the columns in the indexcondition
- The condition that specifies which rows to include in the index. Use '[' and ']' as placeholders for the open/close quote of the current dialect.- Returns:
- The SQL to execute
- Since:
- 3.10
-
makeSafeCreateTable
Return the SQL unmodified.- Specified by:
makeSafeCreateTable
in interfaceDbEngine
- Parameters:
sql
- The original SQLcatalog
- The name of the catalog (database) where the table is being create, or null if it is located in the current catalogschema
- The name of the schema where the table is being created, or null if is located in the current schematable
- The name of the table that is being created- Returns:
- The modified or unmodified SQL statement
- Since:
- 2.6
-
useThetaJoin
public boolean useThetaJoin()Most databases doesn't. Any more than Oracle?- Specified by:
useThetaJoin
in interfaceDbEngine
- Returns:
- TRUE for theta join, FALSE for ansi join
-
supportsColumnAliasInWhere
public boolean supportsColumnAliasInWhere()Returns FALSE. It should always work.- Specified by:
supportsColumnAliasInWhere
in interfaceDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
supportColumnAliasInOrderBy
public boolean supportColumnAliasInOrderBy()Returns FALSE. It should always work.- Specified by:
supportColumnAliasInOrderBy
in interfaceDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
supportColumnAliasInGroupBy
public boolean supportColumnAliasInGroupBy()Returns FALSE. It should always work.- Specified by:
supportColumnAliasInGroupBy
in interfaceDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
supportColumnAliasInHaving
public boolean supportColumnAliasInHaving()Returns FALSE. It should always work.- Specified by:
supportColumnAliasInHaving
in interfaceDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
checkForInvalidNumberOperation
public boolean checkForInvalidNumberOperation()Returns FALSE.- Specified by:
checkForInvalidNumberOperation
in interfaceDbEngine
- Returns:
- TRUE if we need to check the numbers, FALSE otherwise
-
selectOrderByColumnsIfDistinct
public boolean selectOrderByColumnsIfDistinct()Returns FALSE.- Specified by:
selectOrderByColumnsIfDistinct
in interfaceDbEngine
- Returns:
- TRUE if order by columns must be selected, FALSE otherwise
-
getMaxParametersInQuery
public int getMaxParametersInQuery()Returns 10000.- Specified by:
getMaxParametersInQuery
in interfaceDbEngine
-
ln
ReturnLN(<value>)
. -
abs
ReturnABS(<value>)
. -
exp
ReturnEXP(<value>)
. -
power
ReturnPOWER(<base>, <exponent>)
. -
rlike
Return<value> = <regexp>
-
isValidTableName
Checks that the name only contains the following characters: a-zA-Z0-9_ It must also start with a letter or underscore.- Specified by:
isValidTableName
in interfaceDbEngine
- Parameters:
tableName
- The string to check- Returns:
- TRUE if the name is valid, FALSE if not
- Since:
- 2.4
-
isValidColumnName
Checks that the name only contains the following characters: a-zA-Z0-9_ It must also start with a letter or underscore.- Specified by:
isValidColumnName
in interfaceDbEngine
- Parameters:
columnName
- The string to check- Returns:
- TRUE if the name is valid, FALSE if not
-
getCaseSensitiveVarchar
Return null.- Specified by:
getCaseSensitiveVarchar
in interfaceDbEngine
- Parameters:
length
- The maximum length that needs to be stored in the column- Returns:
- The SQL snippet that creates the column, or null to let Hibernate use the default SQL
- Since:
- 2.9
-
castToDate
Description copied from interface:DbEngine
Get a function that casts a date/timestamp to a date (eg. no time should be included in the result).- Specified by:
castToDate
in interfaceDbEngine
- Parameters:
value
- The value to cast- Returns:
- ANSI SQL: cast(value as date)
-
inspectSchemaGenerationSQL
Skip all "create index ..." statements. Skip all "alter table ... add|drop constraint ..." Remove "not null" constraints from "alter table ... add column ..." statements that doesn't supply a default value for the new column when updating.- Specified by:
inspectSchemaGenerationSQL
in interfaceDbEngine
- Parameters:
sql
- The original SQL statment as generated by Hibernatedialect
- The Hibernate dialect currently in usemode
- The installation mode- Returns:
- The SQL statement which may have been modified or null to skip executing the statment
- Since:
- 3.1
-
getQuotedName
Put quotes (") around the name.- Specified by:
getQuotedName
in interfaceDbEngine
- Parameters:
name
- The name of an object in the database- Returns:
- A quoted name
-
useSavePointToContinueTransactionFromSqlFailure
public boolean useSavePointToContinueTransactionFromSqlFailure()Description copied from interface:DbEngine
If the underlying database need to create a savepoint before executing an SQL statement that results in an error in order to be able to continue using the same transaction for other SQL queries. This is, for example, needed by PostgreSQL which will otherwise ignore all SQL statements executed after the one that caused an error.- Specified by:
useSavePointToContinueTransactionFromSqlFailure
in interfaceDbEngine
- Returns:
- Always FALSE, but may be overridden by subclasses
-
getApproximateRowCountSql
Description copied from interface:DbEngine
Get an SQL statement that returns an approximate count for the number of rows in the given table. The SQL query should return a single row with a single value.- Specified by:
getApproximateRowCountSql
in interfaceDbEngine
- Parameters:
catalog
- The name of the catalog (database) where the table is located, or null if it is located in the current catalogschema
- The name of the schema where the table is located, or null if is located in the current schematable
- The name of the table- Returns:
- null, since this depends on capabilities of underlying database
-
isValidName
Check that the name only contains a-zA-Z0-9_ and starts with a letter or underscore.- Since:
- 2.4
-