Package net.sf.basedb.core.dbengine
Class MySQLEngine
java.lang.Object
net.sf.basedb.core.dbengine.AbstractDbEngine
net.sf.basedb.core.dbengine.MySQLEngine
- All Implemented Interfaces:
DbEngine
Database engine for My SQL.
- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2016-02-15 11:58:10 +0100 (må, 15 feb 2016) $
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true.private void
appendList
(StringBuilder sb, Collection<String> items) boolean
Returns TRUE.boolean
When dropping an index, must foreign keys that uses the same columns also be dropped (before dropping the index)?getAnalyzeTableSql
(String catalog, String schema, String table) Generateanalyze table <catalog>.<table>
.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) Returnvarchar(length) CHARACTER SET utf8 COLLATE utf8_bin
.getCatalogName
(String catalog, String schema) Generates a catalog name by combining the catalog and schema name (catalog_schema).getCreateForeignKeySql
(String catalog, String schema, String table, String name, Set<String> columns, String refTable, Set<String> refColumns) Generatealter table schema.table add constraint name foreign key (columns) references refTable (refColumns)
getCreateIndexSql
(String catalog, String schema, String table, String name, Set<String> columns, boolean unique) Generatealter table <catalog>.<table> add [unique] index <name> (<columns>)
.getCreatePrimaryKeySql
(String catalog, String schema, String table, String name, Set<String> columns) Generatealter table catalog.table add primary key (columns)
getCreateSchemaSql
(String catalog, String schema) Generatecreate schema <catalog>
.getDropForeignKeySql
(String catalog, String schema, String table, String name) Generatealter table <catalog>.<table> drop foreign key <name>
getDropIndexSql
(String catalog, String schema, String table, String name, boolean unique) Generatedrop index <name> on <catalog>.<table>
.getDropPrimaryKey
(String catalog, String schema, String table, String name) Generatealter table catalog.table drop primary key
Return a SQL fragment that can be used in an INSERT INTO statement to generate an ID for new rows.getOptimizeTableSql
(String catalog, String schema, String table) Generateoptimize table <catalog>.<table>
.getQuotedName
(String name) Put quotes (`) around the name.getSchemaName
(String catalog, String schema) Return null.ReturnLOG(<value>)
.makeSafeCreateTable
(String sql, String catalog, String schema, String table) Replace "create table" with "create table if not exists"...Return<value> RLIKE <regexp>
.boolean
Returns TRUE.boolean
Returns TRUE.boolean
Returns TRUE.boolean
Returns FALSE.boolean
Always false.Methods inherited from class net.sf.basedb.core.dbengine.AbstractDbEngine
abs, castToDate, checkForInvalidNumberOperation, exp, getCreatePartialIndexSql, getMaxParametersInQuery, inspectSchemaGenerationSQL, isValidColumnName, isValidName, isValidTableName, power, selectOrderByColumnsIfDistinct, useSavePointToContinueTransactionFromSqlFailure
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
abs, castToDate, checkForInvalidNumberOperation, exp, getCreatePartialIndexSql, getCreateTemporaryIdTable, getMaxParametersInQuery, inspectSchemaGenerationSQL, isValidColumnName, isValidTableName, power, selectOrderByColumnsIfDistinct, useSavePointToContinueTransactionFromSqlFailure
-
Constructor Details
-
MySQLEngine
public MySQLEngine()Create MySQLEngine.
-
-
Method Details
-
useThetaJoin
public boolean useThetaJoin()Always false.- Specified by:
useThetaJoin
in interfaceDbEngine
- Overrides:
useThetaJoin
in classAbstractDbEngine
- Returns:
- TRUE for theta join, FALSE for ansi join
-
getCatalogName
Generates a catalog name by combining the catalog and schema name (catalog_schema).- Specified by:
getCatalogName
in interfaceDbEngine
- Overrides:
getCatalogName
in classAbstractDbEngine
- 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 null.- Specified by:
getSchemaName
in interfaceDbEngine
- Overrides:
getSchemaName
in classAbstractDbEngine
- 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
-
getCreateSchemaSql
Generatecreate schema <catalog>
.- Specified by:
getCreateSchemaSql
in interfaceDbEngine
- Since:
- 3.4
-
getCreateIndexSql
public String getCreateIndexSql(String catalog, String schema, String table, String name, Set<String> columns, boolean unique) Generatealter table <catalog>.<table> add [unique] index <name> (<columns>)
. The schema parameter is not supported.- Specified by:
getCreateIndexSql
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 indexunique
- If the index must contain unique values or not- Returns:
- The SQL to execute
-
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
- Overrides:
dropForeignKeysUsedInIndex
in classAbstractDbEngine
- Returns:
- TRUE
- Since:
- 3.6
-
getDropIndexSql
public String getDropIndexSql(String catalog, String schema, String table, String name, boolean unique) Generatedrop index <name> on <catalog>.<table>
. The schema parameter is not supported.- Specified by:
getDropIndexSql
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 indexunique
- If the index contains unique values or not- Returns:
- The SQL to execute
-
getCreateForeignKeySql
public String getCreateForeignKeySql(String catalog, String schema, String table, String name, Set<String> columns, String refTable, Set<String> refColumns) Generatealter table schema.table add constraint name foreign key (columns) references refTable (refColumns)
- Specified by:
getCreateForeignKeySql
in interfaceDbEngine
- Parameters:
catalog
- The name of the catalog (database) where the tables are located, or null if it is located in the current catalogschema
- The name of the schema where the tables are located, or null if is located in the current schematable
- The name of the foreign key tablename
- The name of the foreign keycolumns
- The columns that make up the foreign keyrefTable
- The table that is referenced by the foreign keyrefColumns
- The columns that are referenced by the foreign key- Returns:
- The SQL to create the foreign key
- Since:
- 3.1
-
getDropForeignKeySql
Generatealter table <catalog>.<table> drop foreign key <name>
- Specified by:
getDropForeignKeySql
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 foreign key- Returns:
- The SQL to execute
- Since:
- 3.0
-
getCreatePrimaryKeySql
public String getCreatePrimaryKeySql(String catalog, String schema, String table, String name, Set<String> columns) Generatealter table catalog.table add primary key (columns)
- Specified by:
getCreatePrimaryKeySql
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 primary keycolumns
- The name of the columns in the primary key- Returns:
- The SQL to execute
- Since:
- 3.1
-
getDropPrimaryKey
Generatealter table catalog.table drop primary key
- Specified by:
getDropPrimaryKey
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 primary key- Returns:
- The SQL to execute
- Since:
- 3.1
-
getInsertAutoIncrementSql
Description copied from interface:DbEngine
Return a SQL fragment that can be used in an INSERT INTO statement to generate an ID for new rows.- Specified by:
getInsertAutoIncrementSql
in interfaceDbEngine
- Parameters:
pc
- The persistent class- Returns:
- Always "null" (assuming that the ID column is an AUTO_INCREMENT column)
-
analyzeAfterBatchOperation
public boolean analyzeAfterBatchOperation()Return true.- Specified by:
analyzeAfterBatchOperation
in interfaceDbEngine
-
getOptimizeTableSql
Generateoptimize table <catalog>.<table>
. The schema parameter is not supported.- Specified by:
getOptimizeTableSql
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 to optimize- Returns:
- The SQL to execute
- See Also:
-
getAnalyzeTableSql
Generateanalyze table <catalog>.<table>
. The schema parameter is not supported.- Specified by:
getAnalyzeTableSql
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 to analyze- Returns:
- The SQL to execute, or null if not supported
- See Also:
-
makeSafeCreateTable
Replace "create table" with "create table if not exists"...- Specified by:
makeSafeCreateTable
in interfaceDbEngine
- Overrides:
makeSafeCreateTable
in classAbstractDbEngine
- 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
-
caseInsensitiveComparison
public boolean caseInsensitiveComparison()Returns TRUE.- Specified by:
caseInsensitiveComparison
in interfaceDbEngine
- Returns:
- FALSE if comparisons are case sensitive (ABC != abc), TRUE if they are case insensitive (ABC = abc)
- Since:
- 2.4
-
supportsColumnAliasInWhere
public boolean supportsColumnAliasInWhere()Returns FALSE.- Specified by:
supportsColumnAliasInWhere
in interfaceDbEngine
- Overrides:
supportsColumnAliasInWhere
in classAbstractDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
supportColumnAliasInOrderBy
public boolean supportColumnAliasInOrderBy()Returns TRUE.- Specified by:
supportColumnAliasInOrderBy
in interfaceDbEngine
- Overrides:
supportColumnAliasInOrderBy
in classAbstractDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
supportColumnAliasInGroupBy
public boolean supportColumnAliasInGroupBy()Returns TRUE.- Specified by:
supportColumnAliasInGroupBy
in interfaceDbEngine
- Overrides:
supportColumnAliasInGroupBy
in classAbstractDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
supportColumnAliasInHaving
public boolean supportColumnAliasInHaving()Returns TRUE.- Specified by:
supportColumnAliasInHaving
in interfaceDbEngine
- Overrides:
supportColumnAliasInHaving
in classAbstractDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
ln
ReturnLOG(<value>)
.- Specified by:
ln
in interfaceDbEngine
- Overrides:
ln
in classAbstractDbEngine
- Parameters:
value
- The value to take the logarithm of- Returns:
- The function call that calculates the logartihm
-
rlike
Return<value> RLIKE <regexp>
.- Specified by:
rlike
in interfaceDbEngine
- Overrides:
rlike
in classAbstractDbEngine
- Parameters:
value
- The left valueregexp
- The regular expression as a string- Returns:
- The function call/expression that matches the value agains the regular expression
- Since:
- 2.8
-
getCaseSensitiveVarchar
Returnvarchar(length) CHARACTER SET utf8 COLLATE utf8_bin
.- Specified by:
getCaseSensitiveVarchar
in interfaceDbEngine
- Overrides:
getCaseSensitiveVarchar
in classAbstractDbEngine
- 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
-
getQuotedName
Put quotes (`) around the name.- Specified by:
getQuotedName
in interfaceDbEngine
- Overrides:
getQuotedName
in classAbstractDbEngine
- Parameters:
name
- The name of an object in the database- Returns:
- A quoted name
-
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
- Overrides:
getApproximateRowCountSql
in classAbstractDbEngine
- 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
-
appendList
-