2.17.2: 2011-06-17

net.sf.basedb.core.dbengine
Class PostgresDbEngine

java.lang.Object
  extended by net.sf.basedb.core.dbengine.AbstractDbEngine
      extended by net.sf.basedb.core.dbengine.PostgresDbEngine
All Implemented Interfaces:
DbEngine

public class PostgresDbEngine
extends AbstractDbEngine
implements DbEngine

Database engine for Postgres.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2010-08-17 10:01:25 +0200 (Tue, 17 Aug 2010) $

Constructor Summary
PostgresDbEngine()
          Create PostgresDbEngine.
 
Method Summary
 boolean analyzeAfterBatchOperation()
          Return true.
 boolean caseInsensitiveComparison()
          Returns FALSE.
 boolean checkForInvalidNumberOperation()
          Returns TRUE.
 String getAnalyzeTableSql(String catalog, String schema, String table)
          Generate ANALYZE <schema>.
 String getCreateIndexSql(String catalog, String schema, String table, String name, Set<String> columns, boolean unique)
          Generate ALTER TABLE <schema>.
 String getDropIndexSql(String catalog, String schema, String table, String name, boolean unique)
          Generate ALTER TABLE <schema>.
 String getOptimizeTableSql(String catalog, String schema, String table)
          Generate VACUUM FULL <schema>.
private  String getQuotedName(String name)
          Put quotes (") around the name.
 String inspectSchemaGenerationSQL(String sql, org.hibernate.dialect.Dialect dialect, boolean update)
          Skip all "create index" statements since Hibernate doesn't generate those with unique names.
 String rlike(String value, String regexp)
          Return <value> ~ <regexp>.
 boolean selectOrderByColumnsIfDistinct()
          Returns TRUE.
 boolean supportColumnAliasInGroupBy()
          Returns TRUE.
 boolean supportColumnAliasInHaving()
          Returns FALSE.
 boolean supportColumnAliasInOrderBy()
          Returns TRUE.
 boolean supportsColumnAliasInWhere()
          Returns FALSE.
 boolean useThetaJoin()
          Always false.
 
Methods inherited from class net.sf.basedb.core.dbengine.AbstractDbEngine
abs, castToDate, exp, getCaseSensitiveVarchar, isValidColumnName, isValidName, isValidTableName, ln, makeSafeCreateTable, power
 
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, exp, getCaseSensitiveVarchar, isValidColumnName, isValidTableName, ln, makeSafeCreateTable, power
 

Constructor Detail

PostgresDbEngine

public PostgresDbEngine()
Create PostgresDbEngine.

Method Detail

useThetaJoin

public boolean useThetaJoin()
Always false.

Specified by:
useThetaJoin in interface DbEngine
Overrides:
useThetaJoin in class AbstractDbEngine
Returns:
TRUE for theta join, FALSE for ansi join

getCreateIndexSql

public String getCreateIndexSql(String catalog,
                                String schema,
                                String table,
                                String name,
                                Set<String> columns,
                                boolean unique)
Generate ALTER TABLE <schema>.<table> ADD CONSTRAINT <name> UNIQUE (<columns>) for a unique index, CREATE INDEX <schema>.<name> ON <schema>.<table> (<columns>) for other indexes. The catalog parameter is not supported.

Specified by:
getCreateIndexSql 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
unique - If the index must contain unique values or not
Returns:
The SQL to execute

getDropIndexSql

public String getDropIndexSql(String catalog,
                              String schema,
                              String table,
                              String name,
                              boolean unique)
Generate ALTER TABLE <schema>.<table> DROP CONSTRAINT <name> for unique indexes, DROP INDEX <schema>.<name> for other indexes. The catalog parameter is not supported.

Specified by:
getDropIndexSql 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
unique - If the index contains unique values or not
Returns:
The SQL to execute

analyzeAfterBatchOperation

public boolean analyzeAfterBatchOperation()
Return true. Otherwise queries may take a very long time since indexes may not be used properly.

Specified by:
analyzeAfterBatchOperation in interface DbEngine

getOptimizeTableSql

public String getOptimizeTableSql(String catalog,
                                  String schema,
                                  String table)
Generate VACUUM FULL <schema>.<table>. The catalog parameter is not supported.

Specified by:
getOptimizeTableSql 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 to optimize
Returns:
The SQL to execute
See Also:
DbEngine.getAnalyzeTableSql(String, String, String)

getAnalyzeTableSql

public String getAnalyzeTableSql(String catalog,
                                 String schema,
                                 String table)
Generate ANALYZE <schema>.<table>. The catalog parameter is not supported.

Specified by:
getAnalyzeTableSql 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 to analyze
Returns:
The SQL to execute, or null if not supported
See Also:
DbEngine.getOptimizeTableSql(String, String, String)

caseInsensitiveComparison

public boolean caseInsensitiveComparison()
Returns FALSE.

Specified by:
caseInsensitiveComparison in interface DbEngine
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 interface DbEngine
Overrides:
supportsColumnAliasInWhere in class AbstractDbEngine
Returns:
TRUE if column aliases are supported, FALSE otherwise

supportColumnAliasInOrderBy

public boolean supportColumnAliasInOrderBy()
Returns TRUE.

Specified by:
supportColumnAliasInOrderBy in interface DbEngine
Overrides:
supportColumnAliasInOrderBy in class AbstractDbEngine
Returns:
TRUE if column aliases are supported, FALSE otherwise

supportColumnAliasInGroupBy

public boolean supportColumnAliasInGroupBy()
Returns TRUE.

Specified by:
supportColumnAliasInGroupBy in interface DbEngine
Overrides:
supportColumnAliasInGroupBy in class AbstractDbEngine
Returns:
TRUE if column aliases are supported, FALSE otherwise

supportColumnAliasInHaving

public boolean supportColumnAliasInHaving()
Returns FALSE.

Specified by:
supportColumnAliasInHaving in interface DbEngine
Overrides:
supportColumnAliasInHaving in class AbstractDbEngine
Returns:
TRUE if column aliases are supported, FALSE otherwise

checkForInvalidNumberOperation

public boolean checkForInvalidNumberOperation()
Returns TRUE.

Specified by:
checkForInvalidNumberOperation in interface DbEngine
Overrides:
checkForInvalidNumberOperation in class AbstractDbEngine
Returns:
TRUE if we need to check the numbers, FALSE otherwise

selectOrderByColumnsIfDistinct

public boolean selectOrderByColumnsIfDistinct()
Returns TRUE.

Specified by:
selectOrderByColumnsIfDistinct in interface DbEngine
Overrides:
selectOrderByColumnsIfDistinct in class AbstractDbEngine
Returns:
TRUE if order by columns must be selected, FALSE otherwise

rlike

public String rlike(String value,
                    String regexp)
Return <value> ~ <regexp>.

Specified by:
rlike in interface DbEngine
Overrides:
rlike in class AbstractDbEngine
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

inspectSchemaGenerationSQL

public String inspectSchemaGenerationSQL(String sql,
                                         org.hibernate.dialect.Dialect dialect,
                                         boolean update)
Skip all "create index" statements since Hibernate doesn't generate those with unique names. PostgreSQL users should always run the ./updateindexes.sh tool which will create the missing indexes.

Specified by:
inspectSchemaGenerationSQL in interface DbEngine
Overrides:
inspectSchemaGenerationSQL in class AbstractDbEngine
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

getQuotedName

private String getQuotedName(String name)
Put quotes (") around the name.


2.17.2: 2011-06-17