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, ICloseable

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.BlobFileHandle, DBAccess.ParameterizedStatement
 
Field Summary
static int TYPE_ENUM
          the enum datatype.
 
Fields inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
BFILE, LONGNVARCHAR, NCHAR, NCLOB, NVARCHAR, QUOTE, SQLXML, TIMESTAMPWITHLOCALTIMEZONE, TIMESTAMPWITHTIMEZONE
 
Constructor Summary
PostgreSQLDBAccess()
          Constructs a new OracleDBAccess Object.
 
Method Summary
protected  java.lang.Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData, java.lang.Object pValue)
          Enables the database specific implementation to handle/convert special objects.
protected  java.lang.String createWhereColumn(ServerMetaData pServerMetaData, CompareCondition pCompare, java.lang.String pColumnName)
          Creates the where column.
protected  java.lang.String createWhereParam(ServerMetaData pServerMetaData, CompareCondition pCompare)
          Creates the where parameter.
 java.sql.SQLException formatSQLException(java.sql.SQLException pSqlException)
          Adds the SQL Error Code into the message of the SQL Exception.
protected  ServerColumnMetaData[] getColumnMetaDataIntern(java.lang.String pFromClause, java.lang.String[] pQueryColumns, java.lang.String pBeforeQueryColumns, java.lang.String pWhereClause, java.lang.String pAfterWhereClause)
          Returns the meta data information for the specified query, and configures all columns with defaults.
 java.lang.String getDatabaseSpecificLockStatement(java.lang.String pWritebackTable, ServerMetaData pServerMetaData, ICondition pPKFilter)
          Returns the database specific statement to lock the specified row in the database.
protected  java.util.Map<java.lang.String,java.lang.Object> getDefaultValuesIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Gets all default column values of a specific table.
protected  TableInfo getTableInfoIntern(java.lang.String pWriteBackTable)
          Returns the meta data information for the specified query, and configures all columns with defaults.
protected  void initializeDataType(java.sql.ResultSetMetaData pResultSetMetaData, int pResultSetColumnIndex, ColumnMetaData pColumnMetaData)
          Initializes the datatype data of the ColumnMetaData with the given ResultSetMetaData.
 java.lang.Object[] insertDatabaseSpecific(java.lang.String pWritebackTable, java.lang.String pInsertStatement, ServerMetaData pServerMetaData, java.lang.Object[] pNewDataRow, java.lang.String pDummyColumn)
          Returns the newly inserted row from a Database specific insert statement.
 boolean isAutoQuote(java.lang.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(java.sql.PreparedStatement pInsert, ServerColumnMetaData[] pServerColumnMetaData, int[] iaWriteables, java.lang.Object[] pNew, java.lang.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.
 void setUsername(java.lang.String pUsername)
          Sets the user name to connect with.
 
Methods inherited from class com.sibvisions.rad.persist.jdbc.DBAccess
clearMetaData, clearMetaData, close, commit, commitOrRollbackBeforeClose, convertValueToDatabaseSpecificObject, createIdentifier, createReplace, createServerColumnMetaData, debug, delete, detectModified, error, eventConfigureConnection, eventUnconfigureConnection, executeFunction, executeFunction, executeProcedure, executeQuery, executeSql, executeSqlMulti, executeStatement, fetch, fetch, fetch, fetch, findAndCreateReducedCondition, findNamedParameters, fireEventConfigureConnection, fireEventUnconfigureConnection, formatSQLException, getAllowedValues, getAllowedValuesIntern, getAutomaticLinkColumnNameTranslation, getCloseQuoteCharacter, getColumnMetaData, getColumnMetaDataCreator, getColumnName, getConnection, getConnectionIntern, getConnectionPool, getDBAccess, getDBAccess, getDBAccess, getDBAccess, getDBAccess, getDBProperties, getDBProperty, getDefaultAllowedValues, getDefaultCursorCacheTimeout, getDefaultLargeObjectLimit, getDefaultSchema, getDefaultValues, getDiscardRowCount, getDriver, getForeignKeys, getForeignKeysIntern, getIdentifier, getLargeObjectLimit, getMaxColumnLength, getMaxTime, getMetaDataCacheOption, getMetaDataWhereClause, getObjectFromResultSet, getObjectFromResultSet, getOpenQuoteCharacter, getParameter, getParameter, getParameterizedSelectStatement, getPassword, getPreparedStatement, getPreparedStatement, getPrimaryKey, getPrimaryKeyIntern, getQueryTimeout, getRealQueryColumnName, getSelectStatement, getSelectStatement, getSQL, getTableForSynonym, getTableForSynonymIntern, getTableInfo, getTransactionTimeout, getUniqueKeys, getUniqueKeysIntern, getUrl, getUsername, getWhereClause, info, initializeColumnMetaData, initializeServerColumnMetaData, insert, insertAnsiSQL, isAutoCommit, isConnectionPoolEnabled, isJdbc, isLogEnabled, isMetaDataCacheEnabled, isModified, isOpen, isReleaseConnectionPending, isTypeEqual, lockRow, lockRowInternal, open, prepareConnection, quote, quoteAllways, registerDBAccessClass, releaseConnection, releaseConnectionIntern, removeDBSpecificQuotes, removeQuotes, rollback, setAutoCommit, setAutomaticLinkColumnNameTranslation, setColumnMetaDataCreator, setColumnMetaDataCreator, setConnection, setConnectionPool, setConnectionPoolEnabled, setDBProperties, setDBProperty, setDefaultCursorCacheTimeout, setDefaultLargeObjectLimit, setDefaultSchema, setDriver, setLargeObjectLimit, setMaxTime, setMetaDataCacheOption, setModified, setPassword, setQueryTimeout, setQuoteCharacters, setTransactionTimeout, setUrl, splitSchemaTable, supportsGetGeneratedKeys, toString, translateDefaultValue, 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 java.lang.String getDatabaseSpecificLockStatement(java.lang.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 java.lang.Object[] insertDatabaseSpecific(java.lang.String pWritebackTable,
                                                 java.lang.String pInsertStatement,
                                                 ServerMetaData pServerMetaData,
                                                 java.lang.Object[] pNewDataRow,
                                                 java.lang.String pDummyColumn)
                                          throws DataSourceException
Returns the newly inserted row from a Database specific insert statement.
Database specific derivations of DBAccess 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

getDefaultValuesIntern

protected java.util.Map<java.lang.String,java.lang.Object> getDefaultValuesIntern(java.lang.String pCatalog,
                                                                                  java.lang.String pSchema,
                                                                                  java.lang.String pTable)
                                                                           throws DataSourceException
Gets all default column values of a specific table.

Overrides:
getDefaultValuesIntern 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

formatSQLException

public java.sql.SQLException formatSQLException(java.sql.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(java.sql.PreparedStatement pInsert,
                                ServerColumnMetaData[] pServerColumnMetaData,
                                int[] iaWriteables,
                                java.lang.Object[] pNew,
                                java.lang.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(java.lang.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(java.lang.String pUsername)
Description copied from class: DBAccess
Sets the user name to connect with.

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

getColumnMetaDataIntern

protected ServerColumnMetaData[] getColumnMetaDataIntern(java.lang.String pFromClause,
                                                         java.lang.String[] pQueryColumns,
                                                         java.lang.String pBeforeQueryColumns,
                                                         java.lang.String pWhereClause,
                                                         java.lang.String pAfterWhereClause)
                                                  throws DataSourceException
Description copied from class: DBAccess
Returns the meta data information for the specified query, and configures all columns with defaults.

Overrides:
getColumnMetaDataIntern 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
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

getTableInfoIntern

protected TableInfo getTableInfoIntern(java.lang.String pWriteBackTable)
                                throws DataSourceException
Returns the meta data information for the specified query, and configures all columns with defaults.

Overrides:
getTableInfoIntern in class DBAccess
Parameters:
pWriteBackTable - the write back table 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 java.lang.Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData,
                                                                java.lang.Object pValue)
                                                         throws java.sql.SQLException
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
Throws:
java.sql.SQLException - if it fails.

initializeDataType

protected void initializeDataType(java.sql.ResultSetMetaData pResultSetMetaData,
                                  int pResultSetColumnIndex,
                                  ColumnMetaData pColumnMetaData)
                           throws java.sql.SQLException,
                                  DataSourceException
Initializes the datatype data of the ColumnMetaData with the given ResultSetMetaData.

Overrides:
initializeDataType in class DBAccess
Parameters:
pResultSetMetaData - the result set meta data.
pResultSetColumnIndex - the column index.
pColumnMetaData - the ColumnMetaData
Throws:
java.sql.SQLException - if an unwanted SQLException occurs
DataSourceException - if an know problem occurs during creation

createWhereParam

protected java.lang.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 java.lang.String createWhereColumn(ServerMetaData pServerMetaData,
                                             CompareCondition pCompare,
                                             java.lang.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.