com.sibvisions.rad.persist.jdbc
Class PostgreSQLDBAccess

java.lang.Object
  extended by com.sibvisions.rad.persist.jdbc.DBAccess
      extended by com.sibvisions.rad.persist.jdbc.PostgreSQLDBAccess
All Implemented Interfaces:
IDBAccess

public class PostgreSQLDBAccess
extends DBAccess

The PostgreSQLDBAccess is the implementation for Postgres databases.

See Also:
DBAccess

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
DBAccess.ColumnMetaDataInfo
 
Field Summary
static int TYPE_ENUM
          the enum datatype.
 
Fields inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
logger, LONGNVARCHAR, NCHAR, NCLOB, NVARCHAR, QUOTE, SQLXML
 
Constructor Summary
PostgreSQLDBAccess()
          Constructs a new OracleDBAccess Object.
 
Method Summary
protected  Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData, Object pValue)
          Enables the database specific implementation to handle/convert special objects.
protected  String createWhereColumn(ServerMetaData pServerMetaData, CompareCondition pCompare, String pColumnName)
          Creates the where column.
protected  String createWhereParam(ServerMetaData pServerMetaData, CompareCondition pCompare)
          Creates the where parameter.
 SQLException formatSQLException(SQLException pSqlException)
          Adds the SQL Error Code into the message of the SQL Exception.
 DBAccess.ColumnMetaDataInfo getColumnMetaData(String pFromClause, String[] pQueryColumns, String pBeforeQueryColumns, String pWhereClause, String pAfterWhereClause, String pWritebackTable, String[] pWritebackColumns)
          Returns the meta data information for the specified query, and configures all columns with defaults.
 String getDatabaseSpecificLockStatement(String pWritebackTable, ServerMetaData pServerMetaData, ICondition pPKFilter)
          Returns the database specific statement to lock the specified row in the database.
 Hashtable<String,Object> getDefaultValues(String pCatalog, String pSchema, String pTable)
          Gets all default column values of a specific table.
 Object[] insertDatabaseSpecific(String pWritebackTable, String pInsertStatement, ServerMetaData pServerMetaData, Object[] pNewDataRow, String pDummyColumn)
          Returns the newly inserted row from an Database specific insert statement.
 boolean isAutoQuote(String pName)
          It returns true if this name should be automated quoted.
protected  boolean isEnum(ServerColumnMetaData pColumnMetaData)
          Gets whether the given column has an enum as datatype.
protected  int setColumnsToStore(PreparedStatement pInsert, ServerColumnMetaData[] pServerColumnMetaData, int[] iaWriteables, Object[] pNew, Object[] pOld)
          Sets the values of all changed columns to store from the value Object[]s into the PreparedStatement and returns the last used parameter index.
protected  boolean setDatabaseSpecificType(ResultSetMetaData pMetaData, int pColumnIndex, ServerColumnMetaData pColumnMetaData)
          Enables the database specific implementation to change the metadata before the default settings are made.
 void setUsername(String pUsername)
          Sets the user name to connect with.
protected  Object translateDefaultValue(String pColumnName, int pDataType, String pDefaultValue)
          Translates a default value from a column to the datatype object.
 
Methods inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
close, commit, convertValueToDatabaseSpecificObject, createReplace, delete, executeFunction, executeProcedure, executeSql, executeStatement, executeUpdate, fetch, formatSQLException, getAllowedValues, getAutomaticLinkColumnName, getAutomaticLinkColumnNameTranslation, getConnection, getDBAccess, getDBAccess, getDBAccess, getDBProperties, getDBProperty, getDefaultAllowedValues, getDefaultSchema, getDriver, getFKs, getFromClause, getMaxTime, getPassword, getPK, getPreparedStatement, getQueryColumns, getSelectStatement, getTableForSynonym, getUKs, getUrl, getUsername, getWHEREClause, insert, insertAnsiSQL, isOpen, isTypeEqual, lockRow, lockRowInternal, open, quote, quoteAllways, registerDBAccessClass, removeDBSpecificQuotes, removeQuotes, rollback, setAutomaticLinkColumnNameTranslation, setConnection, setDBProperties, setDBProperty, setDefaultSchema, setDriver, setFilterParameter, setMaxTime, setPassword, setQueryTimeOut, setQuoteCharacters, setUrl, splitSchemaTable, supportsGetGeneratedKeys, toString, translateQuotes, translateValue, update, updateAnsiSQL, updateDatabaseSpecific
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_ENUM

public static final int TYPE_ENUM
the enum datatype.

See Also:
Constant Field Values
Constructor Detail

PostgreSQLDBAccess

public PostgreSQLDBAccess()
Constructs a new OracleDBAccess Object.

Method Detail

getDatabaseSpecificLockStatement

public String getDatabaseSpecificLockStatement(String pWritebackTable,
                                               ServerMetaData pServerMetaData,
                                               ICondition pPKFilter)
                                        throws DataSourceException
Returns the database specific statement to lock the specified row in the database.

Overrides:
getDatabaseSpecificLockStatement in class DBAccess
Parameters:
pWritebackTable - the table to use.
pServerMetaData - the MetaDataColumn array to use.
pPKFilter - the PK filter with the values to use.
Returns:
the database specific statement to lock the specified row in the database.
Throws:
DataSourceException - if some parts are missing for the statement

insertDatabaseSpecific

public Object[] insertDatabaseSpecific(String pWritebackTable,
                                       String pInsertStatement,
                                       ServerMetaData pServerMetaData,
                                       Object[] pNewDataRow,
                                       String pDummyColumn)
                                throws DataSourceException
Returns the newly inserted row from an Database specific insert statement.
Database specific derivations of DBAcces need to implement it database specific.

Overrides:
insertDatabaseSpecific in class DBAccess
Parameters:
pWritebackTable - the table to use for the insert
pInsertStatement - the SQL Statement to use for the insert
pServerMetaData - the meta data to use.
pNewDataRow - the new row (Object[]) with the values to insert
pDummyColumn - null, if all writeable columns are null, but for a correct INSERT it have to be minimum one column to use in the syntax.
Returns:
the newly inserted row from an Oracle Database.
Throws:
DataSourceException - if an Exception occur during insert to the storage

getDefaultValues

public Hashtable<String,Object> getDefaultValues(String pCatalog,
                                                 String pSchema,
                                                 String pTable)
                                          throws DataSourceException
Gets all default column values of a specific table.

Overrides:
getDefaultValues in class DBAccess
Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table name
Returns:
a Hashtable with the column name as key and the default value as value. It only contains columns with a default value
Throws:
DataSourceException - if the database access throws an exception

translateDefaultValue

protected Object translateDefaultValue(String pColumnName,
                                       int pDataType,
                                       String pDefaultValue)
                                throws Exception
Translates a default value from a column to the datatype object.

Overrides:
translateDefaultValue in class DBAccess
Parameters:
pColumnName - the column name to translate
pDataType - the datatype of the column
pDefaultValue - the original default value from the database
Returns:
the default value with the datatype of the column or null if the default value is not valid
Throws:
Exception - if the type translation causes an error or the datatype is not supported

formatSQLException

public SQLException formatSQLException(SQLException pSqlException)
Adds the SQL Error Code into the message of the SQL Exception.

Overrides:
formatSQLException in class DBAccess
Parameters:
pSqlException - the SQL Exception to use.
Returns:
the SQLException with the modified error message with SQL Error Code.

setColumnsToStore

protected int setColumnsToStore(PreparedStatement pInsert,
                                ServerColumnMetaData[] pServerColumnMetaData,
                                int[] iaWriteables,
                                Object[] pNew,
                                Object[] pOld)
                         throws DataSourceException
Sets the values of all changed columns to store from the value Object[]s into the PreparedStatement and returns the last used parameter index.

Overrides:
setColumnsToStore in class DBAccess
Parameters:
pInsert - the PreparedStatement to initialize
pServerColumnMetaData - the column meta data to use.
iaWriteables - the writable columns as int index array
pNew - the new values Object[]
pOld - the old values Object[]
Returns:
the last used parameter index of the PreparedStatement.
Throws:
DataSourceException - if the values can't set into the PreparedStatement

isAutoQuote

public boolean isAutoQuote(String pName)
Description copied from class: DBAccess
It returns true if this name should be automated quoted. e.g. in Oracle default all isUppercase(), so if the name has one loweCase character, then AutoQuote is true to quote this name.

Overrides:
isAutoQuote in class DBAccess
Parameters:
pName - the name to quote.
Returns:
true if this name should be automated quoted.

setUsername

public void setUsername(String pUsername)
Description copied from class: DBAccess
Sets the user name to connect with.

Overrides:
setUsername in class DBAccess
Parameters:
pUsername - the user name

getColumnMetaData

public DBAccess.ColumnMetaDataInfo getColumnMetaData(String pFromClause,
                                                     String[] pQueryColumns,
                                                     String pBeforeQueryColumns,
                                                     String pWhereClause,
                                                     String pAfterWhereClause,
                                                     String pWritebackTable,
                                                     String[] pWritebackColumns)
                                              throws DataSourceException
Description copied from class: DBAccess
Returns the meta data information for the specified query, and configures all columns with defaults.

Overrides:
getColumnMetaData in class DBAccess
Parameters:
pFromClause - the from clause with query tables and join definitions
pQueryColumns - the query columns
pBeforeQueryColumns - the before query columns
pWhereClause - the last where condition in query
pAfterWhereClause - the after where clause in query
pWritebackTable - the write back table to use for the isWriteable() state (Optional)
pWritebackColumns - the write back columns to use for the isWriteable() state (Optional)
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

convertDatabaseSpecificObjectToValue

protected Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData,
                                                      Object pValue)
Enables the database specific implementation to handle/convert special objects. Some databases have datatypes that are not defined in the standard. This datatypes have specific classes in the JDBC drivers. With this method it is possible to convert the values of specific JDBC driver classes into usable objects. We can not send any JDBC object to the client!

Overrides:
convertDatabaseSpecificObjectToValue in class DBAccess
Parameters:
pColumnMetaData - the column metadata
pValue - the read object
Returns:
the value to use

setDatabaseSpecificType

protected boolean setDatabaseSpecificType(ResultSetMetaData pMetaData,
                                          int pColumnIndex,
                                          ServerColumnMetaData pColumnMetaData)
                                   throws SQLException
Enables the database specific implementation to change the metadata before the default settings are made.

Overrides:
setDatabaseSpecificType in class DBAccess
Parameters:
pMetaData - the metadata from the resultset
pColumnIndex - the column index in the resultset metadata
pColumnMetaData - the newly created and pre-configured column metadata
Returns:
true if column metadata are changed and the default settings should not be applied, false to apply the standard settings
Throws:
SQLException - if metadata access fails

createWhereParam

protected String createWhereParam(ServerMetaData pServerMetaData,
                                  CompareCondition pCompare)
Creates the where parameter. That is normally a single question mark, but it depends on the database if conversions are needed.

Overrides:
createWhereParam in class DBAccess
Parameters:
pServerMetaData - the server metadata
pCompare - the compare condition
Returns:
the parameter representation for where clause

createWhereColumn

protected String createWhereColumn(ServerMetaData pServerMetaData,
                                   CompareCondition pCompare,
                                   String pColumnName)
Creates the where column. That is normally just the column name, but it depends on the database if conversions are needed.

Overrides:
createWhereColumn in class DBAccess
Parameters:
pServerMetaData - the server metadata
pCompare - the compare condition
pColumnName - the column name to use
Returns:
the column name representation for where clause

isEnum

protected boolean isEnum(ServerColumnMetaData pColumnMetaData)
                  throws DataSourceException
Gets whether the given column has an enum as datatype.

Parameters:
pColumnMetaData - the column metadata
Returns:
true if the column has an enum datatype, false otherwise
Throws:
DataSourceException - if enum detection fails


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.