org.unitils.core.dbsupport
Class PostgreSqlDbSupport

java.lang.Object
  extended by org.unitils.core.dbsupport.DbSupport
      extended by org.unitils.core.dbsupport.PostgreSqlDbSupport

public class PostgreSqlDbSupport
extends DbSupport

Implementation of DbSupport for a PostgreSql database.

Author:
Tim Ducheyne, Sunteya, Filip Neven

Field Summary
 
Fields inherited from class org.unitils.core.dbsupport.DbSupport
PROPKEY_IDENTIFIER_QUOTE_STRING, PROPKEY_STORED_IDENTIFIER_CASE
 
Constructor Summary
PostgreSqlDbSupport()
          Creates support for PostgreSql databases.
 
Method Summary
 void disableReferentialConstraints()
          Disables all referential constraints (e.g. foreign keys) on all table in the schema
protected  void disableReferentialConstraints(String tableName)
           
 void disableValueConstraints()
          Disables all value constraints (e.g. not null) on all tables in the schema
protected  void disableValueConstraints(String tableName)
           
 void dropSequence(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 triggerName)
          Drops the trigger with the given name from the database.
 Set<String> getColumnNames(String tableName)
          Gets the names of all columns of the given table.
 Set<String> getSequenceNames()
          Retrieves the names of all the sequences in the database schema.
 long getSequenceValue(String sequenceName)
          Returns the value of the sequence with the given name.
 Set<String> getTableNames()
          Returns the names of all tables in the database.
 Set<String> getTriggerNames()
          Retrieves the names of all the triggers in the database schema.
 Set<String> getTypeNames()
          Retrieves the names of all user-defined types in the database schema.
 Set<String> getViewNames()
          Retrieves the names of all the views in the database schema.
 void incrementSequenceToValue(String sequenceName, long newSequenceValue)
          Sets the next value of the sequence with the given sequence name to the given sequence value.
 boolean supportsCascade()
          Cascade are supported.
 boolean supportsSequences()
          Sequences are supported.
 boolean supportsTriggers()
          Triggers are supported.
 boolean supportsTypes()
          Types are supported
 
Methods inherited from class org.unitils.core.dbsupport.DbSupport
dropMaterializedView, dropSynonym, dropTable, dropType, dropView, getDatabaseDialect, getIdentifierQuoteString, getIdentityColumnNames, getLongDataType, getMaterializedViewNames, getSchemaName, getSQLHandler, getStoredIdentifierCase, getSynonymNames, getTextDataType, incrementIdentityColumnToValue, init, qualified, quoted, supportsIdentityColumns, supportsMaterializedViews, supportsSynonyms, toCorrectCaseIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostgreSqlDbSupport

public PostgreSqlDbSupport()
Creates support for PostgreSql databases.

Method Detail

getTableNames

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

Specified by:
getTableNames in class DbSupport
Returns:
The names of all tables in the database

getColumnNames

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

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

getViewNames

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

Specified by:
getViewNames in class DbSupport
Returns:
The names of all views in the database

getSequenceNames

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

Overrides:
getSequenceNames in class DbSupport
Returns:
The names of all sequences in the database

getTriggerNames

public Set<String> getTriggerNames()
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 DbSupport
Returns:
The names of all triggers in the database, not null

dropSequence

public void dropSequence(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 DbSupport
Parameters:
sequenceName - The sequence to drop (case-sensitive), not null

dropTrigger

public void dropTrigger(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 DbSupport
Parameters:
triggerName - The trigger to drop as 'trigger-name' ON 'table name', not null

getTypeNames

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

Overrides:
getTypeNames in class DbSupport
Returns:
The names of all types in the database

disableReferentialConstraints

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

Specified by:
disableReferentialConstraints in class DbSupport

disableReferentialConstraints

protected void disableReferentialConstraints(String tableName)

disableValueConstraints

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

Specified by:
disableValueConstraints in class DbSupport

disableValueConstraints

protected void disableValueConstraints(String tableName)

getSequenceValue

public long getSequenceValue(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 DbSupport
Parameters:
sequenceName - The sequence, not null
Returns:
The value of the sequence with the given name

incrementSequenceToValue

public void incrementSequenceToValue(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 DbSupport
Parameters:
sequenceName - The sequence, not null
newSequenceValue - The value to set

supportsSequences

public boolean supportsSequences()
Sequences are supported.

Overrides:
supportsSequences in class DbSupport
Returns:
True

supportsTriggers

public boolean supportsTriggers()
Triggers are supported.

Overrides:
supportsTriggers in class DbSupport
Returns:
True

supportsTypes

public boolean supportsTypes()
Types are supported

Overrides:
supportsTypes in class DbSupport
Returns:
true

supportsCascade

public boolean supportsCascade()
Cascade are supported.

Overrides:
supportsCascade in class DbSupport
Returns:
True


Copyright © 2011. All Rights Reserved.