Project Wonder 5.0

com.webobjects.jdbcadaptor
Class PostgresqlExpression

java.lang.Object
  extended by com.webobjects.eoaccess.EOSQLExpression
      extended by com.webobjects.jdbcadaptor.JDBCExpression
          extended by com.webobjects.jdbcadaptor.PostgresqlExpression

public class PostgresqlExpression
extends com.webobjects.jdbcadaptor.JDBCExpression

Postgres needs special handling of NSData conversion, special escape char, has a regex query selector and handles JOIN clauses correctly.

Author:
ak: Regex, NSData, Giorgio Valoti: refactoring, typecasting, schema building, Arturo Perez: JOIN clauses, David Teran: Timestamps handling, Tim Cummings: case sensitive table and column names, cug: hacks for identifier quoting while creating tables

Nested Class Summary
 class PostgresqlExpression.JoinClause
          Helper class that stores a join definition and helps PostgresqlExpression to assemble the correct join clause.
 
Nested classes/interfaces inherited from class com.webobjects.eoaccess.EOSQLExpression
com.webobjects.eoaccess.EOSQLExpression.SQLValue
 
Field Summary
static com.webobjects.foundation.NSSelector CASE_INSENSITIVE_REGEX_OPERATOR
          Selector used for case insensitive regular expressions.
static com.webobjects.foundation.NSSelector REGEX_OPERATOR
          Selector used for case sensitive regular expressions.
 
Fields inherited from class com.webobjects.jdbcadaptor.JDBCExpression
_externalQuoteChar, _inSelect, _jdbcInfo, _rtrimFunctionName
 
Fields inherited from class com.webobjects.eoaccess.EOSQLExpression
_aliasesByRelationshipPath, _bindings, _contextStack, _defaultDateFormatter, _entity, _joinClauseString, _listString, _NibbleToHex, _orderByString, _statement, _upperFunctionName, _useAliases, _valueListString, _whereClauseString, BindVariableAttributeKey, BindVariableColumnKey, BindVariableNameKey, BindVariablePlaceHolderKey, BindVariableValueKey
 
Constructor Summary
PostgresqlExpression(com.webobjects.eoaccess.EOEntity entity)
          Overridden to remove the rtrim usage.
 
Method Summary
 void addCreateClauseForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
           
 void addJoinClause(java.lang.String leftName, java.lang.String rightName, int semantic)
          Overriden to not call the super implementation.
 java.lang.String allowsNullClauseForConstraint(boolean allowsNull)
          cug: Quick hack for bug in WebObjects 5.4 where the "not null" statement is added without a space, and "addCreateClauseForAttribute" is not called anymore.
 java.lang.String assembleJoinClause(java.lang.String leftName, java.lang.String rightName, int semantic)
          Overriden to contruct a valid SQL92 JOIN clause as opposed to the Oracle-like SQL the superclass produces.
 java.lang.String assembleSelectStatementWithAttributes(com.webobjects.foundation.NSArray attributes, boolean lock, com.webobjects.eocontrol.EOQualifier qualifier, com.webobjects.foundation.NSArray fetchOrder, java.lang.String selectString, java.lang.String columnList, java.lang.String tableList, java.lang.String whereClause, java.lang.String joinClause, java.lang.String orderByClause, java.lang.String lockClause)
          Overriden to handle correct placements of join conditions and to handle DISTINCT fetches with compareCaseInsensitiveA(De)scending sort orders.
 com.webobjects.foundation.NSMutableDictionary bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute eoattribute, java.lang.Object obj)
          Overridden to fix an issue with NStimestamp classes and "T" value-typed attributes.
 java.lang.String columnTypeStringForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
          Overrides the parent implementation to provide support for array data types.
 java.lang.String externalNameQuoteCharacter()
          Overridden because PostgreSQL does not use the default quote character in EOSQLExpression.externalNameQuoteCharacter() which is an empty string.
 java.lang.String formatValueForAttribute(java.lang.Object obj, com.webobjects.eoaccess.EOAttribute eoattribute)
          Overridden because the original version throws when the data contains negative byte values.
 java.lang.String joinClauseString()
          Overrides the parent implementation to compose the final string expression for the join clauses.
 boolean mustUseBindVariableForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
          Overridden to return true only if bind variables are enabled or the is a data type.
 void prepareConstraintStatementForRelationship(com.webobjects.eoaccess.EORelationship relationship, com.webobjects.foundation.NSArray sourceColumns, com.webobjects.foundation.NSArray destinationColumns)
          Overrides the parent implementation to add an INITIALLY DEFERRED to the generated statement.
 void prepareSelectExpressionWithAttributes(com.webobjects.foundation.NSArray nsarray, boolean flag, com.webobjects.eocontrol.EOFetchSpecification eofetchspecification)
          Overridden so we can get the fetch limit from the fetchSpec.
static java.lang.String replaceStringByStringInString(java.lang.String old, java.lang.String newString, java.lang.String buffer)
          Replaces a given string by another string in a string.
 void setUseBindVariables(boolean value)
          Overridden to set the disableBindVariables value correctly.
protected  boolean shouldAllowNull(com.webobjects.eoaccess.EOAttribute attribute)
           
 boolean shouldUseBindVariableForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
          Overridden to return true only if bind variables are enabled or the is a data type.
 char sqlEscapeChar()
          Overridden because Postgres uses "|" instead of "\" like any other database system.
 java.lang.String sqlStringForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
          Overridden because the original version does not correctly quote mixed case fields in all cases.
 java.lang.String sqlStringForData(com.webobjects.foundation.NSData data)
          Overridden because the original version throws an exception when the data contains negative byte values.
 java.lang.String sqlStringForSelector(com.webobjects.foundation.NSSelector selector, java.lang.Object value)
          Overriden so we can put a regex-match qualifier in the display groups query bindings.
 java.lang.String sqlStringForValue(java.lang.Object v, java.lang.String kp)
          Overrides the parent implementation to: add typecasts after the value, i.e.
 java.lang.String tableListWithRootEntity(com.webobjects.eoaccess.EOEntity entity)
          Overridden because the original version does not correctly quote mixed case table names in all cases.
 boolean useBindVariables()
          Overriddden to return the negated value of disableBindVariables().
 
Methods inherited from class com.webobjects.jdbcadaptor.JDBCExpression
addSelectListAttribute, appendItemToListString, appendItemToOrderByString, appendItemToValueListString, jdbcInfo, lockClause, setJDBCInfo
 
Methods inherited from class com.webobjects.eoaccess.EOSQLExpression
_aliasForRelatedAttributeRelationshipPath, _aliasForRelationshipPath, _defaultDateFormatter, _entityForRelationshipPathOrigin, _flattenRelPathEntity, _listString, _orderByString, _rootEntityForExpression, _setEntity, _sqlStringForJoinSemanticMatchSemantic, _stringForDate, _truncatedString, _truncatedStringForData, _valueList, addBindVariableDictionary, addInsertListAttribute, addOrderByAttributeOrdering, addUpdateListAttribute, aliasesByRelationshipPath, appendItemToListString, assembleDeleteStatementWithQualifier, assembleInsertStatementWithRow, assembleUpdateStatementWithRow, bindVariableDictionaries, entity, formatSQLString, formatStringValue, joinExpression, listString, orderByString, prepareDeleteExpressionForQualifier, prepareInsertExpressionWithRow, prepareUpdateExpressionWithRow, setStatement, setUseAliases, setUseQuotedExternalNames, sqlPatternFromShellPattern, sqlPatternFromShellPatternWithEscapeCharacter, sqlStringForAttributeNamed, sqlStringForAttributePath, sqlStringForCaseInsensitiveLike, sqlStringForConjoinedQualifiers, sqlStringForDisjoinedQualifiers, sqlStringForKeyComparisonQualifier, sqlStringForKeyValueQualifier, sqlStringForNegatedQualifier, sqlStringForNumber, sqlStringForQualifier, sqlStringForSchemaObjectName, sqlStringForString, statement, toString, useAliases, useQuotedExternalNames, valueList, whereClauseString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CASE_INSENSITIVE_REGEX_OPERATOR

public static final com.webobjects.foundation.NSSelector CASE_INSENSITIVE_REGEX_OPERATOR
Selector used for case insensitive regular expressions.


REGEX_OPERATOR

public static final com.webobjects.foundation.NSSelector REGEX_OPERATOR
Selector used for case sensitive regular expressions.

Constructor Detail

PostgresqlExpression

public PostgresqlExpression(com.webobjects.eoaccess.EOEntity entity)
Overridden to remove the rtrim usage. The original implementation will remove every trailing space from character based column which should not be OK for Postgres.

Method Detail

bindVariableDictionaryForAttribute

public com.webobjects.foundation.NSMutableDictionary bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute eoattribute,
                                                                                        java.lang.Object obj)
Overridden to fix an issue with NStimestamp classes and "T" value-typed attributes.

Overrides:
bindVariableDictionaryForAttribute in class com.webobjects.jdbcadaptor.JDBCExpression

addJoinClause

public void addJoinClause(java.lang.String leftName,
                          java.lang.String rightName,
                          int semantic)
Overriden to not call the super implementation.

Overrides:
addJoinClause in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
leftName - the table name on the left side of the clause
rightName - the table name on the right side of the clause
semantic - the join semantic

assembleJoinClause

public java.lang.String assembleJoinClause(java.lang.String leftName,
                                           java.lang.String rightName,
                                           int semantic)
Overriden to contruct a valid SQL92 JOIN clause as opposed to the Oracle-like SQL the superclass produces.

Overrides:
assembleJoinClause in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
leftName - the table name on the left side of the clause
rightName - the table name on the right side of the clause
semantic - the join semantic
Returns:
the join clause

assembleSelectStatementWithAttributes

public java.lang.String assembleSelectStatementWithAttributes(com.webobjects.foundation.NSArray attributes,
                                                              boolean lock,
                                                              com.webobjects.eocontrol.EOQualifier qualifier,
                                                              com.webobjects.foundation.NSArray fetchOrder,
                                                              java.lang.String selectString,
                                                              java.lang.String columnList,
                                                              java.lang.String tableList,
                                                              java.lang.String whereClause,
                                                              java.lang.String joinClause,
                                                              java.lang.String orderByClause,
                                                              java.lang.String lockClause)
Overriden to handle correct placements of join conditions and to handle DISTINCT fetches with compareCaseInsensitiveA(De)scending sort orders.

Overrides:
assembleSelectStatementWithAttributes in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
attributes - the attributes to select
lock - flag for locking rows in the database
qualifier - the qualifier to restrict the selection
fetchOrder - specifies the fetch order
columnList - the SQL columns to be fetched
tableList - the the SQL tables to be fetched
whereClause - the SQL where clause
joinClause - the SQL join clause
orderByClause - the SQL sort order clause
lockClause - the SQL lock clause
Returns:
the select statement

columnTypeStringForAttribute

public java.lang.String columnTypeStringForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
Overrides the parent implementation to provide support for array data types.

Overrides:
columnTypeStringForAttribute in class com.webobjects.jdbcadaptor.JDBCExpression
Parameters:
attribute - the EOattribute
Returns:
the PostgreSQL specific type string for attribute

formatValueForAttribute

public java.lang.String formatValueForAttribute(java.lang.Object obj,
                                                com.webobjects.eoaccess.EOAttribute eoattribute)
Overridden because the original version throws when the data contains negative byte values.

Overrides:
formatValueForAttribute in class com.webobjects.jdbcadaptor.JDBCExpression
Parameters:
obj - the object used in the SQL statement
eoattribute - the attribute associated with obj
Returns:
the formatted string

joinClauseString

public java.lang.String joinClauseString()
Overrides the parent implementation to compose the final string expression for the join clauses.

Overrides:
joinClauseString in class com.webobjects.eoaccess.EOSQLExpression

prepareConstraintStatementForRelationship

public void prepareConstraintStatementForRelationship(com.webobjects.eoaccess.EORelationship relationship,
                                                      com.webobjects.foundation.NSArray sourceColumns,
                                                      com.webobjects.foundation.NSArray destinationColumns)
Overrides the parent implementation to add an INITIALLY DEFERRED to the generated statement. Useful you want to generate the schema-building SQL from a pure java environment. cug: Also handles identifier quoting now

Overrides:
prepareConstraintStatementForRelationship in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
relationship - the relationship
sourceColumns - the source columns for the constraints
destinationColumns - the destination columns for the constraints

prepareSelectExpressionWithAttributes

public void prepareSelectExpressionWithAttributes(com.webobjects.foundation.NSArray nsarray,
                                                  boolean flag,
                                                  com.webobjects.eocontrol.EOFetchSpecification eofetchspecification)
Overridden so we can get the fetch limit from the fetchSpec.

Overrides:
prepareSelectExpressionWithAttributes in class com.webobjects.jdbcadaptor.JDBCExpression
Parameters:
nsarray - the array of attributes
flag - locking flag
eofetchspecification - the fetch specification

sqlEscapeChar

public char sqlEscapeChar()
Overridden because Postgres uses "|" instead of "\" like any other database system.

Overrides:
sqlEscapeChar in class com.webobjects.eoaccess.EOSQLExpression

externalNameQuoteCharacter

public java.lang.String externalNameQuoteCharacter()
Overridden because PostgreSQL does not use the default quote character in EOSQLExpression.externalNameQuoteCharacter() which is an empty string.

Overrides:
externalNameQuoteCharacter in class com.webobjects.jdbcadaptor.JDBCExpression

shouldAllowNull

protected boolean shouldAllowNull(com.webobjects.eoaccess.EOAttribute attribute)

addCreateClauseForAttribute

public void addCreateClauseForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
Overrides:
addCreateClauseForAttribute in class com.webobjects.eoaccess.EOSQLExpression

allowsNullClauseForConstraint

public java.lang.String allowsNullClauseForConstraint(boolean allowsNull)
cug: Quick hack for bug in WebObjects 5.4 where the "not null" statement is added without a space, and "addCreateClauseForAttribute" is not called anymore. Will probably change.

Overrides:
allowsNullClauseForConstraint in class com.webobjects.jdbcadaptor.JDBCExpression

sqlStringForAttribute

public java.lang.String sqlStringForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
Overridden because the original version does not correctly quote mixed case fields in all cases. SELECT statements were OK (useAliases is true) INSERT, UPDATE, DELETE didn't quote mixed case field names.

Overrides:
sqlStringForAttribute in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
attribute - the attribute (column name) to be converted to a SQL string
Returns:
SQL string for the attribute

tableListWithRootEntity

public java.lang.String tableListWithRootEntity(com.webobjects.eoaccess.EOEntity entity)
Overridden because the original version does not correctly quote mixed case table names in all cases. SELECT statements were OK (useAliases is true) INSERT, UPDATE, DELETE didn't quote mixed case field names.

Overrides:
tableListWithRootEntity in class com.webobjects.eoaccess.EOSQLExpression
Returns:
the SQL string for the table names

sqlStringForData

public java.lang.String sqlStringForData(com.webobjects.foundation.NSData data)
Overridden because the original version throws an exception when the data contains negative byte values. This method is only for smaller values like binary primary keys or such.

Overrides:
sqlStringForData in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
data - the data to be converted to a SQL string
Returns:
the SQL string for raw data

sqlStringForSelector

public java.lang.String sqlStringForSelector(com.webobjects.foundation.NSSelector selector,
                                             java.lang.Object value)
Overriden so we can put a regex-match qualifier in the display groups query bindings. You can bind '~*' or '~' to queryOperator.someKey and '.*foo' to queryMatch.someKey and will get the correct results.

Overrides:
sqlStringForSelector in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
selector - the selector that specifies the SQL operator
value - the value to be associated with selector
Returns:
the SQL operator string

sqlStringForValue

public java.lang.String sqlStringForValue(java.lang.Object v,
                                          java.lang.String kp)
Overrides the parent implementation to: NULL values are excluded from casting.
You can set the System default com.webobjects.jdbcadaptor.PostgresqlExpression.disableTypeCasting to true to disable both fixes (the former you might want to disable when PG says it can't cast a certain value and the second when you have values with a greater resolution already in the DB).

Overrides:
sqlStringForValue in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
v - the value
kp - the keypath associated with the value

useBindVariables

public boolean useBindVariables()
Overriddden to return the negated value of disableBindVariables().

Overrides:
useBindVariables in class com.webobjects.jdbcadaptor.JDBCExpression

setUseBindVariables

public void setUseBindVariables(boolean value)
Overridden to set the disableBindVariables value correctly.

Overrides:
setUseBindVariables in class com.webobjects.eoaccess.EOSQLExpression
Parameters:
value -

shouldUseBindVariableForAttribute

public boolean shouldUseBindVariableForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
Overridden to return true only if bind variables are enabled or the is a data type.

Overrides:
shouldUseBindVariableForAttribute in class com.webobjects.jdbcadaptor.JDBCExpression

mustUseBindVariableForAttribute

public boolean mustUseBindVariableForAttribute(com.webobjects.eoaccess.EOAttribute attribute)
Overridden to return true only if bind variables are enabled or the is a data type.

Overrides:
mustUseBindVariableForAttribute in class com.webobjects.jdbcadaptor.JDBCExpression

replaceStringByStringInString

public static java.lang.String replaceStringByStringInString(java.lang.String old,
                                                             java.lang.String newString,
                                                             java.lang.String buffer)
Replaces a given string by another string in a string.

Parameters:
old - string to be replaced
newString - to be inserted
buffer - string to have the replacement done on it
Returns:
string after having all of the replacement done.

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.