Project Wonder 5.0

com.webobjects.jdbcadaptor
Class DB2Expression

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

public class DB2Expression
extends JDBCExpression

DB2 use SQL92 join statements. Has a FETCH FIRST n ROWS statement for limit

Author:
simpson: Took the postgress plugin and made it into a db2 plugin, 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 DB2Expression.JoinClause
          Helper class that stores a join definition and helps DB2Expression to assemble the correct join clause.
 
Nested classes/interfaces inherited from class com.webobjects.eoaccess.EOSQLExpression
EOSQLExpression.SQLValue
 
Field Summary
protected  NSMutableArray _alreadyJoined
          Holds array of join clauses.
protected static Method _bigDecimalToString
          Method to get the string value from a BigDecimals from.
protected  int _fetchLimit
          Fetch spec limit ivar
protected static NSTimestampFormatter DATE_FORMATTER
          formatter to use when handling date columns
protected static NSTimestampFormatter TIMESTAMP_FORMATTER
          formatter to use when handling timestamps
 
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
DB2Expression(EOEntity entity)
          Overridden to remove the rtrim usage.
 
Method Summary
 void addCreateClauseForAttribute(EOAttribute attribute)
           
 void addJoinClause(String leftName, String rightName, int semantic)
          Overriden to not call the super implementation.
 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.
 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.
 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.
 NSMutableDictionary bindVariableDictionaryForAttribute(EOAttribute eoattribute, Object obj)
          Overridden to fix an issue with NStimestamp classes and "T" value-typed attributes.
 String formatValueForAttribute(Object obj, EOAttribute eoattribute)
          Overridden because the original version throws when the data contains negative byte values.
 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)
          cug: Also handles identifier quoting now
 void prepareSelectExpressionWithAttributes(NSArray nsarray, boolean flag, EOFetchSpecification eofetchspecification)
          Overridden so we can get the fetch limit from the fetchSpec.
static String replaceStringByStringInString(String old, String newString, 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(EOAttribute attribute)
           
 boolean shouldUseBindVariableForAttribute(EOAttribute attribute)
          Overridden to return true only if bind variables are enabled or the is a data type.
 String sqlStringForAttribute(EOAttribute attribute)
          Overridden because the original version does not correctly quote mixed case fields in all cases.
 String tableListWithRootEntity(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, columnTypeStringForAttribute, externalNameQuoteCharacter, 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, sqlEscapeChar, sqlPatternFromShellPattern, sqlPatternFromShellPatternWithEscapeCharacter, sqlStringForAttributeNamed, sqlStringForAttributePath, sqlStringForCaseInsensitiveLike, sqlStringForConjoinedQualifiers, sqlStringForData, sqlStringForDisjoinedQualifiers, sqlStringForKeyComparisonQualifier, sqlStringForKeyValueQualifier, sqlStringForNegatedQualifier, sqlStringForNumber, sqlStringForQualifier, sqlStringForSchemaObjectName, sqlStringForSelector, sqlStringForString, sqlStringForValue, 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

DATE_FORMATTER

protected static final NSTimestampFormatter DATE_FORMATTER
formatter to use when handling date columns


TIMESTAMP_FORMATTER

protected static final NSTimestampFormatter TIMESTAMP_FORMATTER
formatter to use when handling timestamps


_bigDecimalToString

protected static Method _bigDecimalToString
Method to get the string value from a BigDecimals from.


_alreadyJoined

protected NSMutableArray _alreadyJoined
Holds array of join clauses.


_fetchLimit

protected int _fetchLimit
Fetch spec limit ivar

Constructor Detail

DB2Expression

public DB2Expression(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 NSMutableDictionary bindVariableDictionaryForAttribute(EOAttribute eoattribute,
                                                              Object obj)
Overridden to fix an issue with NStimestamp classes and "T" value-typed attributes.

Overrides:
bindVariableDictionaryForAttribute in class JDBCExpression

addJoinClause

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

Overrides:
addJoinClause in class 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 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.

Overrides:
assembleJoinClause in class 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 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. Change from Postgrss to use Fetch First rows only rather then limit

Overrides:
assembleSelectStatementWithAttributes in class 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

formatValueForAttribute

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

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

joinClauseString

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

Overrides:
joinClauseString in class EOSQLExpression

prepareConstraintStatementForRelationship

public void prepareConstraintStatementForRelationship(EORelationship relationship,
                                                      NSArray sourceColumns,
                                                      NSArray destinationColumns)
cug: Also handles identifier quoting now

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

prepareSelectExpressionWithAttributes

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

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

shouldAllowNull

protected boolean shouldAllowNull(EOAttribute attribute)

addCreateClauseForAttribute

public void addCreateClauseForAttribute(EOAttribute attribute)
Overrides:
addCreateClauseForAttribute in class EOSQLExpression

allowsNullClauseForConstraint

public 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 JDBCExpression

sqlStringForAttribute

public 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.

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

tableListWithRootEntity

public 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.

Overrides:
tableListWithRootEntity in class EOSQLExpression
Returns:
the SQL string for the table names

useBindVariables

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

Overrides:
useBindVariables in class JDBCExpression

setUseBindVariables

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

Overrides:
setUseBindVariables in class EOSQLExpression
Parameters:
value -

shouldUseBindVariableForAttribute

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

Overrides:
shouldUseBindVariableForAttribute in class JDBCExpression

mustUseBindVariableForAttribute

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

Overrides:
mustUseBindVariableForAttribute in class JDBCExpression

replaceStringByStringInString

public static String replaceStringByStringInString(String old,
                                                   String newString,
                                                   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: Wed, Feb 22, 2012 • 07:00 AM EST

Copyright © 2002 – 2011 Project Wonder.