Class AbstractDbEngine

java.lang.Object
net.sf.basedb.core.dbengine.AbstractDbEngine
All Implemented Interfaces:
DbEngine
Direct Known Subclasses:
DefaultDbEngine, MySQLEngine, PostgresDbEngine

public abstract class AbstractDbEngine
extends Object
implements DbEngine
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 Details

    • valid

      private static final Pattern valid
      A regexp checking for invalid characters.
  • Constructor Details

    • AbstractDbEngine

      public AbstractDbEngine()
      Create AbstractDbEngine.
  • Method Details

    • getCatalogName

      public String getCatalogName​(String catalog, String schema)
      Return the catalog name.
      Specified by:
      getCatalogName in interface DbEngine
      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

      public String getSchemaName​(String catalog, String schema)
      Return the schema name.
      Specified by:
      getSchemaName in interface DbEngine
      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 interface DbEngine
      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 interface DbEngine
      Parameters:
      catalog - The name of the catalog (database) where the table is located, or null if it is located in the current catalog
      schema - The name of the schema where the table is located, or null if is located in the current schema
      table - The name of the table
      name - The name of the index to be created
      columns - The name of the columns in the index
      condition - 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

      public String makeSafeCreateTable​(String sql, String catalog, String schema, String table)
      Return the SQL unmodified.
      Specified by:
      makeSafeCreateTable in interface DbEngine
      Parameters:
      sql - The original SQL
      catalog - The name of the catalog (database) where the table is being create, or null if it is located in the current catalog
      schema - The name of the schema where the table is being created, or null if is located in the current schema
      table - 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 interface DbEngine
      Returns:
      TRUE for theta join, FALSE for ansi join
    • supportsColumnAliasInWhere

      public boolean supportsColumnAliasInWhere()
      Returns FALSE. It should always work.
      Specified by:
      supportsColumnAliasInWhere in interface DbEngine
      Returns:
      TRUE if column aliases are supported, FALSE otherwise
    • supportColumnAliasInOrderBy

      public boolean supportColumnAliasInOrderBy()
      Returns FALSE. It should always work.
      Specified by:
      supportColumnAliasInOrderBy in interface DbEngine
      Returns:
      TRUE if column aliases are supported, FALSE otherwise
    • supportColumnAliasInGroupBy

      public boolean supportColumnAliasInGroupBy()
      Returns FALSE. It should always work.
      Specified by:
      supportColumnAliasInGroupBy in interface DbEngine
      Returns:
      TRUE if column aliases are supported, FALSE otherwise
    • supportColumnAliasInHaving

      public boolean supportColumnAliasInHaving()
      Returns FALSE. It should always work.
      Specified by:
      supportColumnAliasInHaving in interface DbEngine
      Returns:
      TRUE if column aliases are supported, FALSE otherwise
    • checkForInvalidNumberOperation

      public boolean checkForInvalidNumberOperation()
      Returns FALSE.
      Specified by:
      checkForInvalidNumberOperation in interface DbEngine
      Returns:
      TRUE if we need to check the numbers, FALSE otherwise
    • selectOrderByColumnsIfDistinct

      public boolean selectOrderByColumnsIfDistinct()
      Returns FALSE.
      Specified by:
      selectOrderByColumnsIfDistinct in interface DbEngine
      Returns:
      TRUE if order by columns must be selected, FALSE otherwise
    • getMaxParametersInQuery

      public int getMaxParametersInQuery()
      Returns 10000.
      Specified by:
      getMaxParametersInQuery in interface DbEngine
    • ln

      public String ln​(String value)
      Return LN(<value>).
      Specified by:
      ln in interface DbEngine
      Parameters:
      value - The value to take the logarithm of
      Returns:
      The function call that calculates the logartihm
    • abs

      public String abs​(String value)
      Return ABS(<value>).
      Specified by:
      abs in interface DbEngine
      Parameters:
      value - The value to use in the calculation
      Returns:
      The function call that calculates the absolute value
    • exp

      public String exp​(String value)
      Return EXP(<value>).
      Specified by:
      exp in interface DbEngine
      Parameters:
      value - The value to use in the calculation
      Returns:
      The function call that calculates the exponential
    • power

      public String power​(String base, String exponent)
      Return POWER(<base>, <exponent>).
      Specified by:
      power in interface DbEngine
      Parameters:
      base - The base in the expression
      exponent - The exponent in the expression
      Returns:
      The function call that calculates the power
    • rlike

      public String rlike​(String value, String regexp)
      Return <value> = <regexp>
      Specified by:
      rlike in interface DbEngine
      Parameters:
      value - The left value
      regexp - The regular expression as a string
      Returns:
      The function call/expression that matches the value agains the regular expression
      Since:
      2.8
    • isValidTableName

      public 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.
      Specified by:
      isValidTableName in interface DbEngine
      Parameters:
      tableName - The string to check
      Returns:
      TRUE if the name is valid, FALSE if not
      Since:
      2.4
    • isValidColumnName

      public 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.
      Specified by:
      isValidColumnName in interface DbEngine
      Parameters:
      columnName - The string to check
      Returns:
      TRUE if the name is valid, FALSE if not
    • getCaseSensitiveVarchar

      public String getCaseSensitiveVarchar​(int length)
      Return null.
      Specified by:
      getCaseSensitiveVarchar in interface DbEngine
      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

      public String castToDate​(String value)
      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 interface DbEngine
      Parameters:
      value - The value to cast
      Returns:
      ANSI SQL: cast(value as date)
    • inspectSchemaGenerationSQL

      public String inspectSchemaGenerationSQL​(String sql, Dialect dialect, SchemaGenerator.Mode mode)
      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 interface DbEngine
      Parameters:
      sql - The original SQL statment as generated by Hibernate
      dialect - The Hibernate dialect currently in use
      mode - The installation mode
      Returns:
      The SQL statement which may have been modified or null to skip executing the statment
      Since:
      3.1
    • getQuotedName

      public String getQuotedName​(String name)
      Put quotes (") around the name.
      Specified by:
      getQuotedName in interface DbEngine
      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 interface DbEngine
      Returns:
      Always FALSE, but may be overridden by subclasses
    • getApproximateRowCountSql

      public String getApproximateRowCountSql​(String catalog, String schema, String table)
      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 interface DbEngine
      Parameters:
      catalog - The name of the catalog (database) where the table is located, or null if it is located in the current catalog
      schema - The name of the schema where the table is located, or null if is located in the current schema
      table - The name of the table
      Returns:
      null, since this depends on capabilities of underlying database
    • isValidName

      protected boolean isValidName​(String name)
      Check that the name only contains a-zA-Z0-9_ and starts with a letter or underscore.
      Since:
      2.4