Package net.sf.basedb.core.dbengine
Class PostgresDbEngine
java.lang.Object
net.sf.basedb.core.dbengine.AbstractDbEngine
net.sf.basedb.core.dbengine.PostgresDbEngine
- All Implemented Interfaces:
DbEngine
Database engine for Postgres.
- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2021-02-18 08:02:06 +0100 (Thu, 18 Feb 2021) $
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Return true.private void
appendList
(StringBuilder sb, Collection<String> items) boolean
Returns FALSE.boolean
Returns TRUE.getAnalyzeTableSql
(String catalog, String schema, String table) GenerateANALYZE <schema>.<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.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 <schema>.<table> add constraint <name> unique (<columns>)
for a unique index,create index <name> on <schema>.<table> (<columns>)
for other indexes.getCreatePartialIndexSql
(String catalog, String schema, String table, String name, Set<String> columns, String condition) Creates a partial index which is the same as a regular index + 'WHERE [condition]';getCreatePrimaryKeySql
(String catalog, String schema, String table, String name, Set<String> columns) Generatealter table schema.table add constraint name primary key (columns)
.getCreateSchemaSql
(String catalog, String schema) Generatecreate schema <schema>
.getCreateTemporaryIdTable
(String table) CREATE TEMPORARY TABLE <table> (id integer PRIMARY KEY) ON COMMIT DROPgetDropForeignKeySql
(String catalog, String schema, String table, String name) Generatealter table <schema>.<table> DROP CONSTRAINT <name>
getDropIndexSql
(String catalog, String schema, String table, String name, boolean unique) Generatealter table <schema>.<table> drop constraint <name>
for unique indexes,drop index <schema>.<name>
for other indexes.getDropPrimaryKey
(String catalog, String schema, String table, String name) Generatealter table schema.table drop constraint name
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) GenerateVACUUM FULL <schema>.<table>
.Return<value> ~ <regexp>
.boolean
Returns TRUE.boolean
Returns TRUE.boolean
Returns FALSE.boolean
Returns TRUE.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
Always false.Methods inherited from class net.sf.basedb.core.dbengine.AbstractDbEngine
abs, castToDate, dropForeignKeysUsedInIndex, exp, getCaseSensitiveVarchar, getCatalogName, getMaxParametersInQuery, getQuotedName, getSchemaName, inspectSchemaGenerationSQL, 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, dropForeignKeysUsedInIndex, exp, getCaseSensitiveVarchar, getCatalogName, getMaxParametersInQuery, getQuotedName, getSchemaName, inspectSchemaGenerationSQL, isValidColumnName, isValidTableName, ln, makeSafeCreateTable, power
-
Constructor Details
-
PostgresDbEngine
public PostgresDbEngine()Create PostgresDbEngine.
-
-
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
-
getCreateSchemaSql
Generatecreate schema <schema>
. The catalog parameter is not supported.- 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 <schema>.<table> add constraint <name> unique (<columns>)
for a unique index,create index <name> on <schema>.<table> (<columns>)
for other indexes. The catalog 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
-
getCreatePartialIndexSql
public String getCreatePartialIndexSql(String catalog, String schema, String table, String name, Set<String> columns, String condition) Creates a partial index which is the same as a regular index + 'WHERE [condition]';- Specified by:
getCreatePartialIndexSql
in interfaceDbEngine
- Overrides:
getCreatePartialIndexSql
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 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
-
getDropIndexSql
public String getDropIndexSql(String catalog, String schema, String table, String name, boolean unique) Generatealter 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 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 <schema>.<table> DROP CONSTRAINT <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 schema.table add constraint name 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 schema.table drop constraint name
- 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 "nextval('sequenceName')" (assuming that the ID column is generated by a sequence)
- Since:
- 3.0
-
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 interfaceDbEngine
-
getOptimizeTableSql
GenerateVACUUM FULL <schema>.<table>
. The catalog 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 <schema>.<table>
. The catalog 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:
-
getCreateTemporaryIdTable
CREATE TEMPORARY TABLE <table> (id integer PRIMARY KEY) ON COMMIT DROP- Specified by:
getCreateTemporaryIdTable
in interfaceDbEngine
- Parameters:
table
- The name of the temporary table- Returns:
- SQL statement or null
- Since:
- 3.18
-
caseInsensitiveComparison
public boolean caseInsensitiveComparison()Returns FALSE.- 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 FALSE.- Specified by:
supportColumnAliasInHaving
in interfaceDbEngine
- Overrides:
supportColumnAliasInHaving
in classAbstractDbEngine
- Returns:
- TRUE if column aliases are supported, FALSE otherwise
-
checkForInvalidNumberOperation
public boolean checkForInvalidNumberOperation()Returns TRUE.- Specified by:
checkForInvalidNumberOperation
in interfaceDbEngine
- Overrides:
checkForInvalidNumberOperation
in classAbstractDbEngine
- Returns:
- TRUE if we need to check the numbers, FALSE otherwise
-
selectOrderByColumnsIfDistinct
public boolean selectOrderByColumnsIfDistinct()Returns TRUE.- Specified by:
selectOrderByColumnsIfDistinct
in interfaceDbEngine
- Overrides:
selectOrderByColumnsIfDistinct
in classAbstractDbEngine
- Returns:
- TRUE if order by columns must be selected, FALSE otherwise
-
rlike
Return<value> ~ <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
-
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
- Overrides:
useSavePointToContinueTransactionFromSqlFailure
in classAbstractDbEngine
- Returns:
- Always TRUE
-
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
-