PostgresqlExpression Class Reference

Inherits com::webobjects::jdbcadaptor::JDBCExpression.

Collaboration diagram for PostgresqlExpression:

Collaboration graph
[legend]

List of all members.

Classes

class  JoinClause

Public Member Functions

void addCreateClauseForAttribute (EOAttribute attribute)
void addJoinClause (String leftName, String rightName, int semantic)
String allowsNullClauseForConstraint (boolean allowsNull)
String assembleJoinClause (String leftName, String rightName, int semantic)
String assembleSelectStatementWithAttributes (NSArray attributes, boolean lock, EOQualifier qualifier, NSArray fetchOrder, String selectString, String columnList, String tableList, String whereClause, String joinClause, String orderByClause, String lockClause)
NSMutableDictionary bindVariableDictionaryForAttribute (EOAttribute eoattribute, Object obj)
String columnTypeStringForAttribute (EOAttribute attribute)
String externalNameQuoteCharacter ()
String formatValueForAttribute (Object obj, EOAttribute eoattribute)
String joinClauseString ()
boolean mustUseBindVariableForAttribute (EOAttribute attribute)
 PostgresqlExpression (EOEntity entity)
void prepareConstraintStatementForRelationship (EORelationship relationship, NSArray sourceColumns, NSArray destinationColumns)
void prepareSelectExpressionWithAttributes (NSArray nsarray, boolean flag, EOFetchSpecification eofetchspecification)
void setUseBindVariables (boolean value)
boolean shouldUseBindVariableForAttribute (EOAttribute attribute)
char sqlEscapeChar ()
String sqlStringForAttribute (EOAttribute attribute)
String sqlStringForData (NSData data)
String sqlStringForSelector (NSSelector selector, Object value)
String sqlStringForValue (Object v, String kp)
String tableListWithRootEntity (EOEntity entity)
boolean useBindVariables ()

Static Public Member Functions

static String replaceStringByStringInString (String old, String newString, String buffer)

Static Public Attributes

static final NSSelector CASE_INSENSITIVE_REGEX_OPERATOR = new NSSelector( "~*", new Class[]{ Object.class })
static final NSSelector REGEX_OPERATOR = new NSSelector( "~", new Class[]{ Object.class })

Protected Member Functions

boolean shouldAllowNull (EOAttribute attribute)

Private Member Functions

String customFunctionForStringComparison ()
boolean disableBindVariables ()
boolean disableTypeCasting ()
boolean enableBooleanQuoting ()
boolean enableIdentifierQuoting ()
EOEntity entityForKeyPath (String keyPath)
String fixBigDecimal (BigDecimal value, EOAttribute eoattribute)
boolean isDataAttribute (EOAttribute attribute)
boolean isDateAttribute (EOAttribute eoattribute)
boolean isTimestampAttribute (EOAttribute eoattribute)
NSArray quoteArrayContents (NSArray a)
String quoteIdentifier (String identifier)
boolean useLowercaseForCaseInsensitiveLike ()

Private Attributes

NSMutableArray _alreadyJoined = new NSMutableArray()
Boolean _disableBindVariables = null
Boolean _disableTypeCasting = null
Boolean _enableBooleanQuoting
Boolean _enableIdentifierQuoting
int _fetchLimit
Boolean _useLowercaseForCaseInsensitiveLike

Static Private Attributes

static Method _bigDecimalToString = null
static final NSTimestampFormatter DATE_FORMATTER = new NSTimestampFormatter("%Y-%m-%d")
static final String EXTERNAL_NAME_QUOTE_CHARACTER = "\""
static final char HEX_VALUES []
static final char SQL_ESCAPE_CHAR = '|'
static final NSTimestampFormatter TIMESTAMP_FORMATTER = new NSTimestampFormatter("%Y-%m-%d %H:%M:%S.%F")


Detailed Description

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


Constructor & Destructor Documentation

PostgresqlExpression ( 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.


Member Function Documentation

void addCreateClauseForAttribute ( EOAttribute  attribute  ) 

void addJoinClause ( String  leftName,
String  rightName,
int  semantic 
)

Overriden to not call the super implementation.

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

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.

String assembleJoinClause ( String  leftName,
String  rightName,
int  semantic 
)

Overriden to contruct a valid SQL92 JOIN clause as opposed to the Oracle-like SQL the superclass produces.

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

String assembleSelectStatementWithAttributes ( NSArray  attributes,
boolean  lock,
EOQualifier  qualifier,
NSArray  fetchOrder,
String  selectString,
String  columnList,
String  tableList,
String  whereClause,
String  joinClause,
String  orderByClause,
String  lockClause 
)

Overriden to handle correct placements of join conditions and to handle DISTINCT fetches with compareCaseInsensitiveA(De)scending sort orders.

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

NSMutableDictionary bindVariableDictionaryForAttribute ( EOAttribute  eoattribute,
Object  obj 
)

Overridden to fix an issue with NStimestamp classes and "T" value-typed attributes.

String columnTypeStringForAttribute ( EOAttribute  attribute  ) 

Overrides the parent implementation to provide support for array data types.

Parameters:
attribute the EOattribute
Returns:
the PostgreSQL specific type string for attribute

String customFunctionForStringComparison (  )  [private]

Checks the system property com.webobjects.jdbcadaptor.PostgresqlExpression.customFunctionForStringComparison to use a custom function for caseInsensitive compares and order by clauses.

This property overrides the useLowercaseForCaseInsensitiveLike definition.

Returns:
The name of the custom function to be used for comparison or null to use the default function

boolean disableBindVariables (  )  [private]

Checks the system property com.webobjects.jdbcadaptor.PostgresqlExpression.disableBindVariables to enable or disable bind variables in general.

Returns:

boolean disableTypeCasting (  )  [private]

Checks the system property com.webobjects.jdbcadaptor.PostgresqlExpression.disableTypeCasting to enable or disable typecasting (appending somepostgrestype) for attributes.

Returns:

boolean enableBooleanQuoting (  )  [private]

Checks the system property com.webobjects.jdbcadaptor.PostgresqlExpression.enableBooleanQuoting to enable or disable quoting (default) of boolean items.

Returns:

boolean enableIdentifierQuoting (  )  [private]

Checks the system property com.webobjects.jdbcadaptor.PostgresqlExpression.enableIdentifierQuoting to enable or disable quoting (default) of schema names, table names and field names. Required if names which are case sensitive or reserved words or have special characters.

Returns:

EOEntity entityForKeyPath ( String  keyPath  )  [private]

Utility that traverses a key path to find the last destination entity

Parameters:
keyPath the key path
Returns:
the entity at the end of the keypath

String externalNameQuoteCharacter (  ) 

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

String fixBigDecimal ( BigDecimal  value,
EOAttribute  eoattribute 
) [private]

Fixes an incompatibility with JDK 1.5 and using toString() instead of toPlainString() for BigDecimals. From what I understand, you will only need this if you disable bind variables.

Parameters:
value 
eoattribute 
Returns:
Author:
ak

String formatValueForAttribute ( Object  obj,
EOAttribute  eoattribute 
)

Overridden because the original version throws when the data contains negative byte values.

Parameters:
obj the object used in the SQL statement
eoattribute the attribute associated with obj
Returns:
the formatted string

boolean isDataAttribute ( EOAttribute  attribute  )  [private]

Helper to check for data columns that are not keys.

Parameters:
eoattribute 
Returns:

boolean isDateAttribute ( EOAttribute  eoattribute  )  [private]

Helper to check for timestamp columns that have a "D" value type.

Parameters:
eoattribute 
Returns:

boolean isTimestampAttribute ( EOAttribute  eoattribute  )  [private]

Helper to check for timestamp columns that have a "T" value type.

Parameters:
eoattribute 
Returns:

String joinClauseString (  ) 

Overrides the parent implementation to compose the final string expression for the join clauses.

boolean mustUseBindVariableForAttribute ( EOAttribute  attribute  ) 

Overridden to return true only if bind variables are enabled or the is a data type.

void prepareConstraintStatementForRelationship ( EORelationship  relationship,
NSArray  sourceColumns,
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

Parameters:
relationship the relationship
sourceColumns the source columns for the constraints
destinationColumns the destination columns for the constraints

void prepareSelectExpressionWithAttributes ( NSArray  nsarray,
boolean  flag,
EOFetchSpecification  eofetchspecification 
)

Overridden so we can get the fetch limit from the fetchSpec.

Parameters:
nsarray the array of attributes
flag locking flag
eofetchspecification the fetch specification

NSArray quoteArrayContents ( NSArray  a  )  [private]

Takes an array of strings and quotes every single string, if set to do so

Parameters:
a - array of strings
Returns:
array of quoted or unquoted strings, depends on enableIdentifierQuoting

String quoteIdentifier ( String  identifier  )  [private]

Quotes the string if necessary (checks the Property)

Parameters:
identifier - the string to quote
Returns:
quoted or unquoted string (check with enableIdentifierQuoting)

static String replaceStringByStringInString ( String  old,
String  newString,
String  buffer 
) [static]

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.

void setUseBindVariables ( boolean  value  ) 

Overridden to set the disableBindVariables value correctly.

Parameters:
value 

boolean shouldAllowNull ( EOAttribute  attribute  )  [protected]

boolean shouldUseBindVariableForAttribute ( 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.

String sqlStringForAttribute ( 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.

Parameters:
attribute the attribute (column name) to be converted to a SQL string
Returns:
SQL string for the attribute

String sqlStringForData ( 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.

Parameters:
data the data to be converted to a SQL string
Returns:
the SQL string for raw data

String sqlStringForSelector ( NSSelector  selector,
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.

Parameters:
selector the selector that specifies the SQL operator
value the value to be associated with selector
Returns:
the SQL operator string

String sqlStringForValue ( Object  v,
String  kp 
)

Overrides the parent implementation to:

  • add typecasts after the value, i.e. '2'char, which is required with certain PostgreSQL versions (<=7.4.x) for the correct query processing, particularly with index usage.
  • quotes values if bind variables are disabled on this attribute.
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).
Parameters:
v the value
kp the keypath associated with the value

String tableListWithRootEntity ( 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.

Returns:
the SQL string for the table names

boolean useBindVariables (  ) 

Overriddden to return the negated value of disableBindVariables().

boolean useLowercaseForCaseInsensitiveLike (  )  [private]

Checks the system property com.webobjects.jdbcadaptor.PostgresqlExpression.useLowercaseForCaseInsensitiveLike to use the "lower" function for caseInsensitive compares

Returns:


Member Data Documentation

Holds array of join clauses.

Method _bigDecimalToString = null [static, private]

Method to get the string value from a BigDecimals from.

Boolean _disableBindVariables = null [private]

If true, queries will be created by using

Boolean _disableTypeCasting = null [private]

If true, don't use typecasting, ie: 'some text'varcchar(255)

Boolean _enableBooleanQuoting [private]

Boolean _enableIdentifierQuoting [private]

int _fetchLimit [private]

Fetch spec limit ivar

final NSSelector CASE_INSENSITIVE_REGEX_OPERATOR = new NSSelector( "~*", new Class[]{ Object.class }) [static]

Selector used for case insensitive regular expressions.

final NSTimestampFormatter DATE_FORMATTER = new NSTimestampFormatter("%Y-%m-%d") [static, private]

formatter to use when handling date columns

final String EXTERNAL_NAME_QUOTE_CHARACTER = "\"" [static, private]

Quote character when using case sensitive queries.

final char HEX_VALUES[] [static, private]

Initial value:

 {
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F'
    }
Lookup table for conversion of bytes -> hex.

final NSSelector REGEX_OPERATOR = new NSSelector( "~", new Class[]{ Object.class }) [static]

Selector used for case sensitive regular expressions.

final char SQL_ESCAPE_CHAR = '|' [static, private]

SQL escape character

final NSTimestampFormatter TIMESTAMP_FORMATTER = new NSTimestampFormatter("%Y-%m-%d %H:%M:%S.%F") [static, private]

formatter to use when handling timestamps


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:42:33 2012 for Project Wonder by  doxygen 1.5.8