org.dbmaintain.database.impl
Class PostgreSqlDatabase

java.lang.Object
  extended by org.dbmaintain.database.Database
      extended by org.dbmaintain.database.impl.PostgreSqlDatabase

public class PostgreSqlDatabase
extends Database

Implementation of Database for a PostgreSql database.

Author:
Tim Ducheyne, Sunteya, Filip Neven

Field Summary
 
Fields inherited from class org.dbmaintain.database.Database
databaseConnection, identifierProcessor, schemaNames
 
Constructor Summary
PostgreSqlDatabase(DatabaseConnection databaseConnection, IdentifierProcessor identifierProcessor)
           
 
Method Summary
 void disableReferentialConstraints(String schemaName)
          Disables all referential constraints (e.g. foreign keys) on all table in the schema
protected  void disableReferentialConstraints(String schemaName, String tableName)
           
 void disableValueConstraints(String schemaName)
          Disables all value constraints (e.g. not null) on all tables in the schema
protected  void disableValueConstraints(String schemaName, String tableName)
           
 void dropSequence(String schemaName, String sequenceName)
          Drops the sequence with the given name from the database Note: the sequence name is surrounded with quotes, making it case-sensitive.
 void dropTrigger(String schemaName, String triggerName)
          Drops the trigger with the given name from the database.
 Set<String> getColumnNames(String schemaName, String tableName)
          Gets the names of all columns of the given table.
 Set<String> getSequenceNames(String schemaName)
          Retrieves the names of all the sequences in the database schema.
 long getSequenceValue(String schemaName, String sequenceName)
          Returns the value of the sequence with the given name.
 String getSupportedDatabaseDialect()
           
 Set<String> getTableNames(String schemaName)
          Returns the names of all tables in the database.
 Set<String> getTriggerNames(String schemaName)
          Retrieves the names of all the triggers in the database schema.
 Set<String> getTypeNames(String schemaName)
          Retrieves the names of all user-defined types in the database schema.
 Set<String> getViewNames(String schemaName)
          Retrieves the names of all the views in the database schema.
 void incrementSequenceToValue(String schemaName, String sequenceName, long newSequenceValue)
          Sets the next value of the sequence with the given sequence name to the given sequence value.
 void setDatabaseDefaultSchema()
          Sets the current schema of the database.
 boolean supportsCascade()
          Cascade are supported.
 boolean supportsSequences()
          Sequences are supported.
 boolean supportsSetDatabaseDefaultSchema()
          Setting the default schema is supported.
 boolean supportsTriggers()
          Triggers are supported.
 boolean supportsTypes()
          Types are supported
 
Methods inherited from class org.dbmaintain.database.Database
disableReferentialConstraints, disableValueConstraints, dropMaterializedView, dropMaterializedView, dropRule, dropSequence, dropStoredProcedure, dropStoredProcedure, dropSynonym, dropSynonym, dropTable, dropTable, dropTrigger, dropType, dropType, dropView, dropView, getColumnNames, getDatabaseInfo, getDatabaseName, getDataSource, getDefaultSchemaName, getIdentifierQuoteString, getIdentityColumnNames, getIdentityColumnNames, getLongDataType, getMaterializedViewNames, getMaterializedViewNames, getRuleNames, getSchemaNames, getSequenceNames, getSequenceValue, getSQLHandler, getStoredIdentifierCase, getStoredProcedureNames, getStoredProcedureNames, getSynonymNames, getSynonymNames, getTableNames, getTextDataType, getTriggerNames, getTypeNames, getViewNames, incrementIdentityColumnToValue, incrementIdentityColumnToValue, incrementSequenceToValue, isQuoted, qualified, qualified, quoted, removeIdentifierQuotes, setSettingIdentityColumnValueEnabled, setSettingIdentityColumnValueEnabled, supportsIdentityColumns, supportsMaterializedViews, supportsRules, supportsStoredProcedures, supportsSynonyms, toCorrectCaseIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostgreSqlDatabase

public PostgreSqlDatabase(DatabaseConnection databaseConnection,
                          IdentifierProcessor identifierProcessor)
Method Detail

getSupportedDatabaseDialect

public String getSupportedDatabaseDialect()
Specified by:
getSupportedDatabaseDialect in class Database
Returns:
the database dialect supported by this db support class, not null

getTableNames

public Set<String> getTableNames(String schemaName)
Returns the names of all tables in the database.

Specified by:
getTableNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all tables in the database

getColumnNames

public Set<String> getColumnNames(String schemaName,
                                  String tableName)
Gets the names of all columns of the given table.

Specified by:
getColumnNames in class Database
Parameters:
tableName - The table, not null
schemaName - The schema, not null
Returns:
The names of the columns of the table with the given name

getViewNames

public Set<String> getViewNames(String schemaName)
Retrieves the names of all the views in the database schema.

Specified by:
getViewNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all views in the database

getSequenceNames

public Set<String> getSequenceNames(String schemaName)
Retrieves the names of all the sequences in the database schema.

Overrides:
getSequenceNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all sequences in the database

getTriggerNames

public Set<String> getTriggerNames(String schemaName)
Retrieves the names of all the triggers in the database schema.

The drop trigger statement is not compatible with standard SQL in Postgresql. You have to do drop trigger 'trigger-name' ON 'table name' instead of drop trigger 'trigger-name'.

To circumvent this, this method will return the trigger names as follows: 'trigger-name' ON 'table name'

Overrides:
getTriggerNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all triggers in the database, not null

dropSequence

public void dropSequence(String schemaName,
                         String sequenceName)
Drops the sequence with the given name from the database Note: the sequence name is surrounded with quotes, making it case-sensitive.

The method is overriden to handle columns of type serial. For these columns, the sequence should be dropped using cascade. Thanks to Peter Oxenham for reporting this issue (UNI-28).

Overrides:
dropSequence in class Database
Parameters:
sequenceName - The sequence to drop (case-sensitive), not null
schemaName - The schema, not null

dropTrigger

public void dropTrigger(String schemaName,
                        String triggerName)
Drops the trigger with the given name from the database.

The drop trigger statement is not compatible with standard SQL in Postgresql. You have to do drop trigger 'trigger-name' ON 'table name' instead of drop trigger 'trigger-name'.

To circumvent this, this method expects trigger names as follows: 'trigger-name' ON 'table name'

Overrides:
dropTrigger in class Database
Parameters:
triggerName - The trigger to drop as 'trigger-name' ON 'table name', not null
schemaName - The schema, not null

getTypeNames

public Set<String> getTypeNames(String schemaName)
Retrieves the names of all user-defined types in the database schema.

Overrides:
getTypeNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all types in the database

disableReferentialConstraints

public void disableReferentialConstraints(String schemaName)
Disables all referential constraints (e.g. foreign keys) on all table in the schema

Specified by:
disableReferentialConstraints in class Database
Parameters:
schemaName - The schema, not null

disableReferentialConstraints

protected void disableReferentialConstraints(String schemaName,
                                             String tableName)

disableValueConstraints

public void disableValueConstraints(String schemaName)
Disables all value constraints (e.g. not null) on all tables in the schema

Specified by:
disableValueConstraints in class Database
Parameters:
schemaName - The schema, not null

disableValueConstraints

protected void disableValueConstraints(String schemaName,
                                       String tableName)

getSequenceValue

public long getSequenceValue(String schemaName,
                             String sequenceName)
Returns the value of the sequence with the given name.

Note: this can have the side-effect of increasing the sequence value.

Overrides:
getSequenceValue in class Database
Parameters:
sequenceName - The sequence, not null
schemaName - The schema, not null
Returns:
The value of the sequence with the given name

incrementSequenceToValue

public void incrementSequenceToValue(String schemaName,
                                     String sequenceName,
                                     long newSequenceValue)
Sets the next value of the sequence with the given sequence name to the given sequence value.

Overrides:
incrementSequenceToValue in class Database
Parameters:
sequenceName - The sequence, not null
newSequenceValue - The value to set
schemaName - The schema, not null

setDatabaseDefaultSchema

public void setDatabaseDefaultSchema()
Sets the current schema of the database. If a current schema is set, it does not need to be specified explicitly in the scripts.

Overrides:
setDatabaseDefaultSchema in class Database

supportsSequences

public boolean supportsSequences()
Sequences are supported.

Overrides:
supportsSequences in class Database
Returns:
True

supportsTriggers

public boolean supportsTriggers()
Triggers are supported.

Overrides:
supportsTriggers in class Database
Returns:
True

supportsTypes

public boolean supportsTypes()
Types are supported

Overrides:
supportsTypes in class Database
Returns:
true

supportsCascade

public boolean supportsCascade()
Cascade are supported.

Overrides:
supportsCascade in class Database
Returns:
True

supportsSetDatabaseDefaultSchema

public boolean supportsSetDatabaseDefaultSchema()
Setting the default schema is supported.

Overrides:
supportsSetDatabaseDefaultSchema in class Database
Returns:
True


Copyright © 2011. All Rights Reserved.