2.17.2: 2011-06-17

net.sf.basedb.core.dbengine
Class AbstractDbEngine

java.lang.Object
  extended by 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: 2010-09-27 14:53:33 +0200 (Mon, 27 Sep 2010) $

Field Summary
private static Pattern valid
          A regexp checking for invalid characters.
 
Constructor Summary
AbstractDbEngine()
          Create AbstractDbEngine.
 
Method Summary
 String abs(String value)
          Return ABS(<value>).
 String castToDate(String value)
          Get a function that casts a date/timestamp to a date (eg. no time should be included in the result).
 boolean checkForInvalidNumberOperation()
          Returns FALSE.
 String exp(String value)
          Return EXP(<value>).
 String getCaseSensitiveVarchar(int length)
          Return null.
 String inspectSchemaGenerationSQL(String sql, org.hibernate.dialect.Dialect dialect, boolean update)
          Remove "not null" constraints from "alter table ... add column" statements that doesn't supply a default value for the new column when updating.
 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.
 String ln(String value)
          Return LN(<value>).
 String makeSafeCreateTable(String sql, String catalog, String schema, String table)
          Return the SQL unmodified.
 String power(String base, String exponent)
          Return POWER(<base>, <exponent>).
 String rlike(String value, String regexp)
          Return <value> = <regexp>
 boolean selectOrderByColumnsIfDistinct()
          Returns FALSE.
 boolean supportColumnAliasInGroupBy()
          Returns FALSE.
 boolean supportColumnAliasInHaving()
          Returns FALSE.
 boolean supportColumnAliasInOrderBy()
          Returns FALSE.
 boolean supportsColumnAliasInWhere()
          Returns FALSE.
 boolean useThetaJoin()
          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, getCreateIndexSql, getDropIndexSql, getOptimizeTableSql
 

Field Detail

valid

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

Constructor Detail

AbstractDbEngine

public AbstractDbEngine()
Create AbstractDbEngine.

Method Detail

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

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,
                                         org.hibernate.dialect.Dialect dialect,
                                         boolean update)
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
update - TRUE if we are updating an existing database, FALSE if we are creating a new one
Returns:
The SQL statement which may have been modified or null to skip executing the statment
Since:
2.16

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

2.17.2: 2011-06-17