|
WebObjects 5.2 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.webobjects.eoaccess.EOSQLExpression
EOSQLExpression is an abstract superclass that defines how to build SQL
statements for adaptor channels. You don't typically use instances of
EOSQLExpression; rather, you can use EOSQLExpression subclasses written to
work with a particular RDBMS (relational database management system)
and corresponding adaptor. A concrete
subclass of EOSQLExpression overrides many of its methods in terms of the
query language syntax for its specific RDBMS. EOSQLExpression objects are
used internally by the Framework, and unless you are creating a concrete
adaptor, you won't ordinarily need to interact with EOSQLExpression
objects itself. You would create and use an EOSQLExpression
object when you want to send a SQL statement directly to the server.
In this case, you simply create an expression with the
EOSQLExpressionFactory's method expressionForString
, and send
that expression object to an adaptor channel using EOAdaptorChannel's method
evaluateExpression
.
See EOSQLExpression Concepts for more information.
Inner Class Summary | |
static interface |
EOSQLExpression.SQLValue
This interface defines API for objects that can provide values for themselves to be used in SQL statements. |
Field Summary | |
static String |
BindVariableAttributeKey
A key for the attribute that uses the bind variable. |
static String |
BindVariableColumnKey
A key for the column name to be used in SQL. |
static String |
BindVariableNameKey
The key for the name of a bind variable. |
static String |
BindVariablePlaceHolderKey
A key for the placeholder string to be used in SQL. |
static String |
BindVariableValueKey
A key for the value of the bind variable. |
Constructor Summary | |
EOSQLExpression(EOEntity entity)
Creates a new EOSQLExpression rooted to an EOEntity . |
Method Summary | |
void |
addBindVariableDictionary(NSDictionary binding)
Adds binding to this object's array of bind variable
dictionaries. |
void |
addCreateClauseForAttribute(EOAttribute attribute)
Adds the SQL string for creating attribute to a
comma-separated list of attribute creation clauses. |
void |
addInsertListAttribute(EOAttribute attribute,
Object value)
Adds the SQL string for attribute to a comma-separated
list of attributes and value to a comma-separated list
of values. |
void |
addJoinClause(String leftName,
String rightName,
int semantic)
Creates a new join clause by invoking assembleJoinClause and adds
it to the receiver's join clause string. |
void |
addOrderByAttributeOrdering(EOSortOrdering sortOrdering)
Adds an attribute-direction pair ("LAST_NAME asc", for example) to the receiver's ORDER BY string. |
void |
addSelectListAttribute(EOAttribute attribute)
Adds a SQL string for attribute to a comma-separated
list of attribute names for use in a SELECT statement. |
void |
addUpdateListAttribute(EOAttribute attribute,
Object value)
Adds an attribute-value assignment ("LAST_NAME = 'Thomas'", for example) to a comma-separated list for use in an UPDATE statement. |
NSMutableDictionary |
aliasesByRelationshipPath()
Returns a dictionary of table aliases. |
String |
allowsNullClauseForConstraint(boolean flag)
Returns according to flag an adaptor specific string for use
in a CREATE TABLE statement. |
void |
appendItemToListString(String itemString,
StringBuffer listString)
Adds itemString to a comma-separated list. |
String |
assembleDeleteStatementWithQualifier(EOQualifier qualifier,
String tableList,
String whereClause)
This method is invoked from prepareDeleteExpressionForQualifier
to return an SQL DELETE statement. |
String |
assembleInsertStatementWithRow(NSDictionary row,
String tableList,
String columnList,
String valueList)
This method is invoked from prepareInsertExpressionWithRow to
return an SQL INSERT statement. |
String |
assembleJoinClause(String leftName,
String rightName,
int semantic)
This method is invoked from addJoinClause to return
a 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)
This method is invoked from prepareSelectExpressionWithAttributes
to return an SQL SELECT statement. |
String |
assembleUpdateStatementWithRow(NSDictionary row,
EOQualifier qualifier,
String tableList,
String updateList,
String whereClause)
This method is invoked from prepareUpdateExpressionWithRow
to return an SQL UPDATE statement. |
NSArray |
bindVariableDictionaries()
Returns the bind variable dictionaries. |
abstract NSMutableDictionary |
bindVariableDictionaryForAttribute(EOAttribute attribute,
Object value)
Implemented by subclasses to create and return the bind variable dictionary for attribute and value . |
String |
columnTypeStringForAttribute(EOAttribute attribute)
Returns an adaptor specific type string for attribute
that's suitable for use in a CREATE TABLE statement. |
EOEntity |
entity()
Returns the receiver's entity. |
String |
externalNameQuoteCharacter()
Returns a String with the character used to quote SQL identifiers that use unusual characters which would not otherwise be legal. |
String |
formatSQLString(String sqlString,
String format)
Applies the format specified by format to a SQL string
sqlString . |
String |
formatStringValue(String string)
Formats string for use as a string constant in a SQL statement. |
String |
formatValueForAttribute(Object value,
EOAttribute attribute)
This method should be overridden by subclasses to return a string representation of value suitable for use in an SQL statement,
depending on attribute 's externalType . |
String |
joinClauseString()
Returns the part of the receiver's WHERE clause that specifies join conditions. |
void |
joinExpression()
Builds up the joinClauseString for use in a SELECT statement. |
String |
listString()
Returns a comma-separated list of attributes or "attribute = value" assignments. |
String |
lockClause()
Overridden by subclasses to return the SQL string used in a SELECT statement to lock selected rows. |
boolean |
mustUseBindVariableForAttribute(EOAttribute attribute)
Returns true if the receiver must use bind variables for
attribute , false otherwise. |
String |
orderByString()
Returns the comma-separated list of "attribute direction" pairs ("LAST_NAME asc, FIRST_NAME asc", for example) for use in a SELECT statement. |
void |
prepareConstraintStatementForRelationship(EORelationship relationship,
NSArray sourceColumns,
NSArray destinationColumns)
Sets the receiver's statement to an adaptor specific
constraint for relationship. |
void |
prepareDeleteExpressionForQualifier(EOQualifier qualifier)
Generates a DELETE statement. |
void |
prepareInsertExpressionWithRow(NSDictionary row)
Generates an INSERT statement. |
void |
prepareSelectExpressionWithAttributes(NSArray attributes,
boolean lock,
EOFetchSpecification fetchSpec)
Generates a SELECT statement. |
void |
prepareUpdateExpressionWithRow(NSDictionary row,
EOQualifier qualifier)
Generates an UPDATE statement. |
void |
setStatement(String statement)
Sets the receiver's SQL statement to statement ,
which should be a valid expression in the target query language. |
void |
setUseAliases(boolean useAliases)
Tells the receiver whether or not to use table aliases. |
void |
setUseBindVariables(boolean flag)
Sets according to flag whether all instances of
EOSQLExpression subclasses use bind variables. |
static void |
setUseQuotedExternalNames(boolean bool)
Deprecated. This static method is inappropriate in Java. Subclasses should implement their own policy on quoting identifiers. |
boolean |
shouldUseBindVariableForAttribute(EOAttribute attribute)
Returns true if the receiver can provide a bind variable
dictionary for attribute , false otherwise. |
char |
sqlEscapeChar()
Returns the char used for the ESCAPE clause in an SQL LIKE expression. |
String |
sqlPatternFromShellPattern(String pattern)
Translates a "like" qualifier to an SQL LIKE expression. |
String |
sqlPatternFromShellPatternWithEscapeCharacter(String pattern,
char escapeChar)
Like sqlPatternFromShellPattern except that escapeCharacter
allows you to specify a character for escaping the SQL wild card characters
"%" and "_". |
String |
sqlStringForAttribute(EOAttribute attribute)
Returns the SQL string for attribute , complete with a table
alias if the receiver uses table aliases. |
String |
sqlStringForAttributeNamed(String name)
Returns the SQL string for the attribute name , complete
with a table alias if the receiver uses table aliases. |
String |
sqlStringForAttributePath(NSArray path)
Returns the SQL string for path , complete with a table alias
if the receiver uses table aliases. |
String |
sqlStringForCaseInsensitiveLike(String valueString,
String keyString)
Overridden by subclasses to return a case insensitive comparison of valueString and keyString . |
String |
sqlStringForConjoinedQualifiers(NSArray qualifiers)
Creates and returns an SQL string that is the result of interposing the word "AND" between the SQL strings for the qualifiers in qualifiers . |
String |
sqlStringForData(NSData data)
Returns the SQL string for a data of type NSData. |
String |
sqlStringForDisjoinedQualifiers(NSArray qualifiers)
Creates and returns a SQL string that is the result of interposing the word "OR" between the SQL strings for the qualifiers in qualifiers . |
String |
sqlStringForKeyComparisonQualifier(EOKeyComparisonQualifier qualifier)
Creates and returns a SQL string that is the result of interposing an operator between the SQL strings for the right and left keys in qualifier . |
String |
sqlStringForKeyValueQualifier(EOKeyValueQualifier qualifier)
Creates and returns a SQL string that is the result of interposing an operator between the SQL strings for qualifier 's key
and value. |
String |
sqlStringForNegatedQualifier(EOQualifier qualifier)
Creates and returns a SQL string that is the result of surrounding the SQL string for qualifier in parentheses and appending
it to the word "not". |
static String |
sqlStringForNumber(Number number)
Returns the SQL string for number . |
String |
sqlStringForQualifier(EOQualifierSQLGeneration qualifier)
Returns a SQL statement for qualifier suitable for
inclusion in a WHERE clause. |
String |
sqlStringForSchemaObjectName(String name)
Returns name enclosed in the external name quote character
if the receiver uses quoted external names, otherwise simply returns
name unaltered. |
String |
sqlStringForSelector(NSSelector selector,
Object value)
Returns a SQL operator for selector and value . |
static String |
sqlStringForString(String string)
Returns the SQL string for string . |
String |
sqlStringForValue(Object value,
String keyPath)
Returns a string for value appropriate for use in an
SQL statement. |
String |
statement()
An SQL statement can be assigned to an EOSQLExpression object directly using expressionForString or using
setStatement . |
String |
tableListWithRootEntity(EOEntity entity)
Returns the comma-separated list of tables for use in a SELECT, UPDATE, or DELETE statement's FROM clause. |
String |
toString()
Returns a readable description of the SQL expression. |
boolean |
useAliases()
Returns true if the receiver generates statements with
table aliases, false otherwise. |
boolean |
useBindVariables()
Queries if instances use bind variables. |
static boolean |
useQuotedExternalNames()
Deprecated. This static method is inappropriate in Java. Subclasses should implement their own policy on quoting identifiers. |
String |
valueList()
Returns the comma-separated list of values used in an INSERT statement. |
String |
whereClauseString()
Returns the part of the receiver's WHERE clause that qualifies rows. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final String BindVariableAttributeKey
bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute, java.lang.Object)
public static final String BindVariableColumnKey
bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute, java.lang.Object)
public static final String BindVariableNameKey
bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute, java.lang.Object)
public static final String BindVariablePlaceHolderKey
bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute, java.lang.Object)
public static final String BindVariableValueKey
bindVariableDictionaryForAttribute(com.webobjects.eoaccess.EOAttribute, java.lang.Object)
Constructor Detail |
public EOSQLExpression(EOEntity entity)
EOEntity
.entity
- an EOEntityEOEntity
Method Detail |
public void addBindVariableDictionary(NSDictionary binding)
binding
to this object's array of bind variable
dictionaries. binding
is generally created using
bindVariableDictionaryForAttribute
and is added to the
bind variable dictionaries in sqlStringForValue
when this
receiver uses a bind variable for the specified attribute.binding
- specifies binding to the object arraybindVariableDictionaries()
,
bindVariableDictionaryForAttribute(
EOAttribute attribute, Object value)
,
sqlStringForValue(Object value, String keyPath)
,
EOSQLExpression
public void addCreateClauseForAttribute(EOAttribute attribute)
attribute
to a
comma-separated list of attribute creation clauses. The list is constructed
for use in a CREATE TABLE statement produced by
createTableStatementsForEntityGroup
.
One can use listString
to access the creation clauses.EOSQLExpression's implementation creates clauses in the following form:
WhereCOLUMN_NAME COLUMN_TYPE ALLOWS_NULL_CLAUSE
columnTypeStringForAttribute
for attribute
.
allowsNullClauseForConstraint
with true
if
attribute
allowsNull
or with false
otherwise.
attribute
- an EOAttributelistString()
,
columnTypeStringForAttribute(EOAttribute anEOAttribute)
,
allowsNullClauseForConstraint(boolean aBoolean)
,
EOSchemaGeneration.createTableStatementsForEntityGroup(NSArray entityGroup)
,
EOAttribute.allowsNull()
public void addInsertListAttribute(EOAttribute attribute, Object value)
attribute
to a comma-separated
list of attributes and value
to a comma-separated list
of values. Both lists are constructed for use in an INSERT statement.
You can use the methods listString
and valueList
to access the attributes and value lists.
Invokes appendItemToListString
to add an SQL string for
attribute
to the receiver's listString
, and again to
add a formatted SQL string for value
to the receiver's
valueList
.
attribute
- an EOAttribute to be addedvalue
- an value of object to be addedlistString()
,
valueList()
,
appendItemToListString(String aString,
StringBuffer aStringBuffer)
,
sqlStringForAttribute(EOAttribute anEOAttribute)
,
sqlStringForValue(Object value, String keyPath)
,
formatValueForAttribute(Object value, EOAttribute attribute)
public void addJoinClause(String leftName, String rightName, int semantic)
assembleJoinClause
and adds
it to the receiver's join clause string. Separates join conditions already
in the join clause string with the word "and". Invoked from
joinExpression
.leftName
- specifies name at leftrightName
- specifies name at rightsemantic
- properties of joinjoinClauseString()
,
assembleJoinClause(String aString,
String aString, int anInt)
,
joinExpression()
public void addOrderByAttributeOrdering(EOSortOrdering sortOrdering)
sortOrdering
's selector is
EOSortOrdering.CompareCaseInsensitiveAscending
or
EOSortOrdering.CompareCaseInsensitiveAscending
,
the string generated has the format "upper(attribute) direction".
Method orderByString
can be used to access the ORDER BY string.
This method invokes appendItemToListString
to add the
attribute-direction pair.sortOrdering
- the kind of sort ordering wantedorderByString()
,
appendItemToListString(String aString, StringBuffer aStringBuffer)
,
sqlStringForAttributeNamed(String name)
,
EOSortOrdering
public void addSelectListAttribute(EOAttribute attribute)
attribute
to a comma-separated
list of attribute names for use in a SELECT statement. The SQL string
for attribute
is formatted with its "read" format.
This method invokes appendItemToListString
to add the
attribute name.attribute
- the EOAttribute whose name will be added
to listString
appendItemToListString(String aString, StringBuffer aStringBuffer)
,
listString()
,
sqlStringForAttribute(EOAttribute anEOAttribute)
,
formatSQLString(String sqlString, String format)
,
EOAttribute.readFormat()
public void addUpdateListAttribute(EOAttribute attribute, Object value)
value
with attribute
's "write" format.
Method listString
can be used to access the list. This method
invokes appendItemToListString
to add the attribute-value
assignment.attribute
- the EOAttribute that contributes the
left-hand-side of the assignmentvalue
- the value that contributes the
right-hand-side of the assignmentlistString()
,
appendItemToListString(String aString, StringBuffer aStringBuffer)
,
formatSQLString(String sqlString, String format)
,
EOAttribute.writeFormat()
public NSMutableDictionary aliasesByRelationshipPath()
sqlStringForAttributePath
.sqlStringForAttributePath(NSArray aNSArray)
,
tableListWithRootEntity(EOEntity entity)
public String allowsNullClauseForConstraint(boolean flag)
flag
an adaptor specific string for use
in a CREATE TABLE statement. The returned string indicates whether a
column allows null
values. EOSQLExpression's implementation
returns the empty string if flag is true, "NOT NULL" otherwise. A subclass
should override this if its database server's semantics are different.flag
- boolean for whether or not columan allows NULLnull
values, in the correct adaptor formataddCreateClauseForAttribute(EOAttribute anEOAttribute)
public void appendItemToListString(String itemString, StringBuffer listString)
itemString
to a comma-separated list.
If listString
already has entries, this method appends a
comma followed by itemString
.itemString
- specifies item as stringlistString
- specifies a comma-separated list of attributesaddSelectListAttribute(EOAttribute anEOAttribute)
,
addInsertListAttribute(EOAttribute anEOAttribute, Object anObject)
,
addUpdateListAttribute(EOAttribute attribute, Object value)
,
addOrderByAttributeOrdering(EOSortOrdering sortOrdering)
public String assembleDeleteStatementWithQualifier(EOQualifier qualifier, String tableList, String whereClause)
prepareDeleteExpressionForQualifier
to return an SQL DELETE statement. The statement is of the form:
DELETE FROM tableList SQL_WHERE whereClause
qualifier
- an EOQualifier for finding the row to delete
the WHERE clause in a particular waytableList
- SQL table listwhereClause
- SQL WHERE clauseprepareDeleteExpressionForQualifier(EOQualifier qualifier)
public String assembleInsertStatementWithRow(NSDictionary row, String tableList, String columnList, String valueList)
prepareInsertExpressionWithRow
to
return an SQL INSERT statement. The statement is of the form:
or, ifINSERT INTO tableList (columnList) VALUES valueList
columnList
is null
:
INSERT INTOtableList
VALUESvalueList
row
- an NSDictionary containing the row datatablelist
- SQL table listcolumnList
- SQL column listvalueList
- SQL value listprepareInsertExpressionWithRow(NSDictionary row)
public String assembleJoinClause(String leftName, String rightName, int semantic)
addJoinClause
to return
a JOIN clause. The clause is of the form:
where operator is "=" for an inner join, "*=" for a left-outer join, and "=*" for a right-outer join.leftName operator rightName
leftName
- specifies leftname
rightName
- specifies rightname
semantic
- specifies semantic
addJoinClause(String aString, String aString, int anInt)
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)
prepareSelectExpressionWithAttributes
to return an SQL SELECT statement. The statment is of the form:
IfSELECT columnList FROM tableList lockClause WHERE whereClause AND joinClause ORDER BY orderByClause
lockClause
is null
, it is omitted from
the statement. Similarly, if orderByClause
is
null
, the "ORDER BY orderByClause" is omitted. If either
whereClause
or joinClause
is null
,
the "AND" and null
-valued argument are omitted. If both are
null
, the entire WHERE clause
is omitted. attributes, lock, qualifer, fetchOrder
arguments to
prepareSelectExpressionWithAttributes
from which the other
assembleSelect... arguments were derived. They are provided for subclasses
that need to generate the clauses of the SELECT statement in a
particular way.attributes
- an NSArray of attributeslock
- flag for locking rows in databasequalifier
- an EOQualifier for selecting rowsfetchOrder
- specifies fetch orderselectString
- SQL SELECT keyword, possibly with DISTINCTcolumnList
- SQL column listtableList
- SQL table listwhereClause
- SQL WHERE clausejoinClause
- specifies join condition to add to WHERE clauseorderByClause
- SQL ORDER BY clauselockClause
- specifies clause for lockprepareSelectExpressionWithAttributes(NSArray attributes, boolean lock, EOFetchSpecification fetchSpec)
public String assembleUpdateStatementWithRow(NSDictionary row, EOQualifier qualifier, String tableList, String updateList, String whereClause)
prepareUpdateExpressionWithRow
to return an SQL UPDATE statement. The statement is of the form:
UPDATE tableList SET updateList WHERE whereClause
row
and qualifier
are the arguments to
prepareUpdateExpressionWithRow
from which updateList
and
whereClause
were derived. They are provided for subclasses that
need to generate the clauses of the UPDATE statement in a
particular way.row
- an NSDictionary containing the row dataqualifier
- an EOQualifier for finding the row to updatetableList
- SQL table listupdateList
- SQL update listwhereClause
- SQL where clauseprepareUpdateExpressionWithRow(NSDictionary row, EOQualifier qualifier)
public NSArray bindVariableDictionaries()
addBindVariableDictionary(NSDictionary binding)
,
EOSQLExpression(com.webobjects.eoaccess.EOEntity)
public abstract NSMutableDictionary bindVariableDictionaryForAttribute(EOAttribute attribute, Object value)
attribute
and value
. The
dictionary returned from this method must contain
the following key-value pairs:
Key | Corresponding Value | |
---|---|---|
BindVariableNameKey | Name of the bind variable for attribute | |
BindVariablePlaceHolderKey | Placeholder string used in the SQL statement | |
BindVariableAttributeKey | attribute |
|
BindVariableValueKey | value |
An adaptor subclass may define additional entries as required by its RDBMS.
Invoked from sqlStringForValue
when the message
mustUseBindVariableForAttribute
returns true
or when the
receiver's class uses bind variables and the message
shouldUseBindVariableForAttribute
returns true
.
attribute
- the EOAttribute associated with the bind
variable dictionaryvalue
- the value associated with the bind variable
dictionaryattribute
and value
useBindVariables()
,
sqlStringForValue(Object value, String keyPath)
,
mustUseBindVariableForAttribute(EOAttribute attribute)
,
shouldUseBindVariableForAttribute(EOAttribute attribute)
,
EOSQLExpression
public String columnTypeStringForAttribute(EOAttribute attribute)
attribute
that's suitable for use in a CREATE TABLE statement. EOSQLExpression's
implementation creates a string based on anAttribute's
externalType
, precision, and width as follows:
If Condition | Generated String | |
---|---|---|
precision is non-zero | externalType(precision, scale) | |
precision is zero and width is non-zero | externalType(scale) | |
precision and width are zero | externalType |
attribute
- the EOAttribute associated with adaptor specific
type stringattribute
(EOAttribute anEOAttribute)
public EOEntity entity()
public String externalNameQuoteCharacter()
sqlStringForSchemaObjectName(String aString)
public String formatSQLString(String sqlString, String format)
format
to a SQL string
sqlString
.sqlString
- the SQL string to be formattedformat
- this could be either an EOAttribute's
readFormat
or writeFormat
format
is null
EOAttribute.readFormat()
,
EOAttribute.writeFormat()
,
EOAttribute
public String formatStringValue(String string)
string
for use as a string constant in a SQL statement.
EOSQLExpression's implementation
encloses the string in single quotes, escaping any single quotes already present in string.string
- the string to be formattedjava.lang.IllegalArgumentException
- If string
is null
public String formatValueForAttribute(Object value, EOAttribute attribute)
value
suitable for use in an SQL statement,
depending on attribute
's externalType
. For example,
a subclass might format a date using a special database-specific syntax
or standard form or truncate numbers to attribute's precision and scale.
EOSQLExpression's implementation merely returns the string representation
of value
.value
- an object to be used in a SQL statementattribute
- an EOAttribute to be used in influencing the formatEOAttribute
public String joinClauseString()
joinExpression
and the
whereClauseString
make up a statement's WHERE clause.
If the receiver's statement doesn't contain join conditions, this method
returns an empty string.
An EOSQLExpression's joinClauseString
is generally set by invoking
joinExpression
.joinExpression()
,
whereClauseString()
,
whereClauseString()
public void joinExpression()
joinClauseString
for use in a SELECT statement.
For each relationship path in the aliasesByRelationshipPath
dictionary, this method invokes addJoinClause
for each of the
relationship's EOJoin objects.
If the aliasesByRelationshipPath
dictionary only has one entry (the entry
for the EOSQLExpression's entity), the joinClauseString
is empty.
You must invoke this method after invoking addSelectListAttribute
for each attribute to be selected and after sending
sqlStringForSQLExpression(this)
to the qualifier for the SELECT statement.
(These methods build up the aliasesByRelationshipPath
dictionary by
invoking sqlStringForAttributePath
.)whereClauseString()
,
joinClauseString()
,
aliasesByRelationshipPath()
,
addJoinClause(String aString, String aString, int anInt)
,
addSelectListAttribute(EOAttribute anEOAttribute)
,
sqlStringForAttributePath(NSArray aNSArray)
,
EOJoin
public String listString()
listString
is built up with successive invocations of
addInsertListAttribute
, addSelectListAttribute
, or
addUpdateListAttribute
for INSERT statements, SELECT statements,
and UPDATE statements, respectively. The contents of listString
vary
according to the type of statement the receiver is building:
Type of Statement | Sample listString Contents | |
---|---|---|
INSERT | FIRST_NAME, LAST_NAME, EMPLOYEE_ID | |
UPDATE | FIRST_NAME = "Timothy", LAST_NAME = "Richardson" | |
SELECT | t0.FIRST_NAME, t0.LAST_NAME, t1.DEPARTMENT_NAME |
addInsertListAttribute(EOAttribute anEOAttribute, Object anObject)
,
addSelectListAttribute(EOAttribute anEOAttribute)
,
addUpdateListAttribute(EOAttribute attribute, Object value)
public String lockClause()
public boolean mustUseBindVariableForAttribute(EOAttribute attribute)
true
if the receiver must use bind variables for
attribute
, false
otherwise. EOSQLExpression's
implementation returns false
. An SQL expression subclass
that uses bind variables should override this method to return true
if the underlying RDBMS requires that bind variables be used for
attributes with attribute's
external type.attribute
- the EOAttribute associated with the bind
variable dictionarytrue
if the receiver must
use bind variables for attribute
shouldUseBindVariableForAttribute(EOAttribute anEOAttribute)
,
bindVariableDictionaryForAttribute(EOAttribute attribute, Object value)
public String orderByString()
addOrderByAttributeOrdering(EOSortOrdering sortOrdering)
public void prepareConstraintStatementForRelationship(EORelationship relationship, NSArray sourceColumns, NSArray destinationColumns)
statement
to an adaptor specific
constraint for relationship.
EOSQLExpression's implementation generates statements of the form:
WhereALTER TABLE TABLE_NAME ADD CONSTRAINT CONSTRAINT_NAME FOREIGN KEY (SOURCE_KEY_LIST) REFERENCES DESTINATION_TABLE_NAME (DESTINATION_KEY_LIST)
TABLE_NAME
is the external name of the
receiver's entity.CONSTRAINT_NAME
is the external name of
the receiver's entity, relationship's
name,
and the string "FK", concatenated with underbars between
them (EMPLOYEE_MANAGER_FK, for example),SOURCE_KEY_LIST
is a comma-separated list of
the source columns in sourceColumns
.DESTINATION_TABLE_NAME
is the external name of
relationship's
destination entity.DESTINATION_KEY_LIST
is a comma-separated list of
the destination columns in destinationColumns
relationship
- specifies relationshipsourceColumns
- specifies array of source columnsdestinationColumns
- specifies destination columnsstatement()
,
EOSchemaGeneration.foreignKeyConstraintStatementsForRelationship(EORelationship relationship)
public void prepareDeleteExpressionForQualifier(EOQualifier qualifier)
whereClauseString
.tableListWithRootEntity
to get the table name for the
FROM clause.assembleDeleteStatementWithQualifier
.qualifier
- the argument to
assembleDeleteStatementWithQualifier
from which table name for the FROM clause
was derivedwhereClauseString()
,
tableListWithRootEntity(EOEntity entity)
,
assembleDeleteStatementWithQualifier(EOQualifier qualifier, String tableList, String whereClause)
,
EOSQLExpressionFactory.deleteStatementWithQualifier(EOQualifier qualifier, EOEntity entity)
,
EOSQLExpressionFactory.deleteStatementWithQualifier(EOQualifier qualifier, EOEntity entity)
public void prepareInsertExpressionWithRow(NSDictionary row)
addInsertListAttribute
for each entry in
row
to prepare the comma-separated list of attributes
and the corresponding list of values.tableListWithRootEntity
to get the table name.assembleInsertStatementWithRow
.row
- specifies row which is to be insertedaddInsertListAttribute(EOAttribute anEOAttribute,
Object anObject)
,
assembleInsertStatementWithRow(NSDictionary row
, String tableList, String columnList, String valueList)
,
tableListWithRootEntity(EOEntity entity)
,
EOSQLExpressionFactory.insertStatementForRow(NSDictionary row, EOEntity entity)
public void prepareSelectExpressionWithAttributes(NSArray attributes, boolean lock, EOFetchSpecification fetchSpec)
addSelectListAttribute
for each entry in
attributes
to prepare the comma-separated list of
attributes.fetchSpec
's qualifier to generate the receiver's
whereClauseString
}.addOrderByAttributeOrdering
for each
EOAttributeOrdering object in fetchSpec
. First conjoins the
qualifier in fetchSpec
with the restricting qualifier,
if any, of the receiver's entity.joinExpression
to generate the receiver's
joinClauseString
.tableListWithRootEntity
to get the
comma-separated list of tables for the FROM clause.lock
is true
, invokes lockClause
to get the SQL string to lock selected rows.assembleSelectStatementWithAttributes
.attributes
- specifies array of attributeslock
- specifies flagfetchSpec
- specifies fetch specificationEOSQLExpressionFactory.selectStatementForAttributes(NSArray attributes, boolean bool, EOFetchSpecification fetchSpec, EOEntity entity)
,
assembleSelectStatementWithAttributes(NSArray attributes, boolean lock, EOQualifier qualifier, NSArray fetchOrder, String selectString, String columnList, String tableList, String whereClause, String joinClause, String orderByClause, String lockClause)
,
addSelectListAttribute(EOAttribute anEOAttribute)
,
whereClauseString()
,
addOrderByAttributeOrdering(EOSortOrdering sortOrdering)
,
joinExpression()
,
joinClauseString()
,
tableListWithRootEntity(EOEntity entity)
,
lockClause()
public void prepareUpdateExpressionWithRow(NSDictionary row, EOQualifier qualifier)
addUpdateListAttribute
for each entry in
row
to prepare the comma-separated list of
"attribute = value" assignments.whereClauseString
using
qualifer
.tableListWithRootEntity
to get the table
name for the FROM clause.assembleUpdateStatementWithRow
.row
- specifies row in which update will occurqualifier
- specifies qualifier which generates the
receiver's whereClauseString
EOSQLExpressionFactory.updateStatementForRow(
NSDictionary row, EOQualifier qualifier, EOEntity entity)
,
addUpdateListAttribute(EOAttribute attribute,
Object value)
,
whereClauseString()
,
tableListWithRootEntity(EOEntity entity)
,
lockClause()
,
assembleUpdateStatementWithRow(NSDictionary row, EOQualifier qualifier, String tableList, String updateList, String whereClause)
public void setStatement(String statement)
statement
,
which should be a valid expression in the target query language.
This method can be used instead of a prepare...
method to directly assign an SQL string to an EOSQLExpression object.
This method does not perform substitutions or formatting of any kind.statement
- specifies receiver's SQL statementEOSQLExpressionFactory.expressionForString(String string)
,
statement()
public void setUseAliases(boolean useAliases)
useAliases
- pass in true
for affirmation,
false
otherwiseuseAliases()
public void setUseBindVariables(boolean flag)
flag
whether all instances of
EOSQLExpression subclasses use bind variables.flag
- a boolean flag to indicate if instances
should use bind variablesuseBindVariables()
,
EOSQLExpression
public static void setUseQuotedExternalNames(boolean bool)
externalNameQuoteCharacter()
public boolean shouldUseBindVariableForAttribute(EOAttribute attribute)
true
if the receiver can provide a bind variable
dictionary for attribute
, false
otherwise.
Bind variables aren't used for values associated with this attribute when
useBindVariables
returns false
. EOSQLExpression's
implementation returns false
. An SQL expression subclass should
override this method to return true
if the receiver should use
bind variables for attributes with attribute's
external type.
It should also return true
for any attribute for which the
receiver must use bind variables.attribute
- the EOAttribute associated with the bind
variable dictionarytrue
if the receiver can
provide a bind variable dictionary for
attribute
mustUseBindVariableForAttribute(EOAttribute attribute)
,
useBindVariables()
public char sqlEscapeChar()
public String sqlPatternFromShellPattern(String pattern)
sqlStringForKeyValueQualifier
when the qualifier argument is an EOKeyValueQualifier object whose selector is
EOQualifier.QualifierOperatorLike. EOSQLExpression's implementation performs the following
substitutions:
Character in pattern | Substitution string | |
---|---|---|
* | % | |
? | _ | |
% | \% | |
_ | \_ |
sqlEscapeChar
,
typically backslash '\\' as shown.pattern
- qualifier pattern stringsqlEscapeChar
,
sqlStringForKeyValueQualifier
,
EOKeyValueQualifier
public String sqlPatternFromShellPatternWithEscapeCharacter(String pattern, char escapeChar)
sqlPatternFromShellPattern
except that escapeCharacter
allows you to specify a character for escaping the SQL wild card characters
"%" and "_".pattern
- specifies pattern to be translatedescapeCharacter
- SQL escape charactersqlPatternFromShellPattern(String pattern)
public String sqlStringForAttribute(EOAttribute attribute)
attribute
, complete with a table
alias if the receiver uses table aliases. Invoked from
sqlStringForAttributeNamed
when the attribute name is not a path.attribute
- specifies EOAttribute corresponding to SQL stringattribute
sqlStringForAttributeNamed(String name)
,
sqlStringForAttributePath(NSArray aNSArray)
,
useAliases()
public String sqlStringForAttributeNamed(String name)
name
, complete
with a table alias if the receiver uses table aliases. Generates the
return value using sqlStringForAttributePath
if name
is an attribute path ("department.name", for example); otherwise, uses
sqlStringForAttribute
.name
- specifies EOAttribute corresponding to SQL stringname
sqlStringForAttribute(EOAttribute attribute)
,
sqlStringForAttributePath(NSArray aNSArray)
public String sqlStringForAttributePath(NSArray path)
path
, complete with a table alias
if the receiver uses table aliases. Invoked from
sqlStringForAttributeNamed
when the specified attribute name is a
path ("department.location.officeNumber", for example). path
is an array of any number of EORelationship objects followed by an EOAttribute
object. The EORelationship and EOAttribute objects each correspond to a
component in path. For example, if the attribute name argument to
sqlStringForAttributeNamed
is "department.location.officeNumber",
path
is an array containing the following objects in
the order listed:
aliasesByRelationshipPath
dictionary.path
- specify path corresponding to SQL stringpath
sqlStringForAttribute(EOAttribute attribute)
,
sqlStringForAttributeNamed(String name)
,
aliasesByRelationshipPath()
public String sqlStringForCaseInsensitiveLike(String valueString, String keyString)
valueString
and keyString
. For example,
a subclass implementation might return the string
"UPPER(keyString
) LIKE UPPER(valueString
)".valueString
- specifies valueString
keyString
- specifies keyString
valueString
and
keyString
public String sqlStringForConjoinedQualifiers(NSArray qualifiers)
qualifiers
. If the SQL string for a qualifier contains
only white space, it isn't included in the return value. The return
value is enclosed in parentheses if the SQL strings for two or more
qualifiers were ANDed together.qualifiers
- specifies qualifierspublic String sqlStringForData(NSData data)
data
of type NSData. The default
implementation returns the hexadecimal equivalent of data
.data
- the NSData to be converted to SQL stringdata
public String sqlStringForDisjoinedQualifiers(NSArray qualifiers)
qualifiers
. If the SQL string for a qualifier contains
only white space, it isn't included in the return value. The return
value is enclosed in parentheses if the SQL strings for two or more
qualifiers were ORed together.qualifiers
- specifies qualifiersqualifiers
public String sqlStringForKeyComparisonQualifier(EOKeyComparisonQualifier qualifier)
qualifier
. Determines the SQL operator by invoking
sqlStringForSelector
with qualifier
's selector
and null
for the value. Generates SQL strings for
qualifier
's keys by invoking
sqlStringForAttributeNamed
to get SQL strings. This method also
formats the strings for the right and left keys using
formatSQLString
with the corresponding attributes' "read" formats.qualifier
- specifies qualifiersqualifier
sqlStringForSelector(NSSelector aNSSelector, Object anObject)
,
sqlStringForAttributeNamed(String name)
,
formatSQLString(String sqlString, String format)
public String sqlStringForKeyValueQualifier(EOKeyValueQualifier qualifier)
qualifier
's key
and value. Determines the SQL operator by invoking
sqlStringForSelector
with qualifier's
selector
and value. Generates an SQL string for qualifier's
key
by invoking sqlStringForAttributeNamed
to get an SQL string and
formatSQLString
with the corresponding attribute's "read" format.
Similarly, generates an SQL string for qualifier's
value by
invoking sqlStringForValue
to get an SQL string and
formatValueForAttribute
to format it. (First invokes
sqlPatternFromShellPattern
for the value if
qualifier
's selector is
EOQualifier.QualifierOperatorLike
.)qualifier
- specifies qualifierqualifier's
key and valuesqlStringForSelector(NSSelector aNSSelector, Object anObject)
,
sqlStringForAttributeNamed(String name)
,
formatSQLString(String sqlString, String format)
,
sqlStringForValue(Object value, String keyPath)
,
formatValueForAttribute(Object value, EOAttribute attribute)
,
sqlPatternFromShellPattern(String pattern)
public String sqlStringForNegatedQualifier(EOQualifier qualifier)
qualifier
in parentheses and appending
it to the word "not". For example, if the string
for qualifier
is "FIRST_NAME = 'John'",
sqlStringForNegatedQualifier
returns the string
"not (FIRST_NAME = 'John')". If the SQL string for qualifier contains
only white space, this method returns null
.qualifier
- specifies qualifierqualifier
in parentheses
and appending it to the word "not".public static String sqlStringForNumber(Number number)
number
.number
- the number to be converted to SQL stringnumber
public String sqlStringForQualifier(EOQualifierSQLGeneration qualifier)
qualifier
suitable for
inclusion in a WHERE clause. Invoked from an EOSQLExpression while
it's preparing a SELECT, UPDATE, or DELETE statement.qualifier
- an EOQualifierqualifier
suitable for inclusion in a WHERE clausewhereClauseString()
public String sqlStringForSchemaObjectName(String name)
name
enclosed in the external name quote character
if the receiver uses quoted external names, otherwise simply returns
name
unaltered.name
- specifies namename
enclosed in the external
name quote character if the receiver uses quoted
external names otherwise returns
name
unalteredexternalNameQuoteCharacter()
public String sqlStringForSelector(NSSelector selector, Object value)
selector
and value
.
The possible values for selector
are defined as constants
in EOQualifier. The following table summarizes
EOSQLExpression's default mapping:
Selector (EOQualifier constant) | SQL Operator | |
---|---|---|
QualifierOperatorEqual | "is" if value is
NullValue , "=" otherwise | |
QualifierOperatorNotEqual | "is not" if value is NullValue , "<>"
otherwise | |
QualifierOperatorLessThan | "<" | |
QualifierOperatorGreaterThan | ">" | |
QualifierOperatorLessThanOrEqualTo | "<=" | |
QualifierOperatorGreaterThanOrEqualTo | ">=" | |
QualifierOperatorLike | "like" |
selector
- specifies selectorvalue
- specifies valueselector
and value
IllegalStateException
- if selector is an unknown
operatorsqlStringForKeyComparisonQualifier(EOKeyComparisonQualifier anEOKeyComparisonQualifier)
,
sqlStringForKeyValueQualifier(EOKeyValueQualifier qualifier)
,
EOQualifier
,
NSKeyValueCoding.NullValue
public static String sqlStringForString(String string)
string
.string
- the String to be converted to SQL stringstring
public String sqlStringForValue(Object value, String keyPath)
value
appropriate for use in an
SQL statement. If the receiver uses a bind variable for the attribute
named keyPath
, then sqlStringForValue
gets the bind
variable dictionary for the attribute, adds it to the receiver's array
of bind variables dictionaries, and returns the value for the binding's
BindVariablePlaceHolderKey
. Otherwise, this method invokes
formatValueForAttribute
and returns the formatted string for
value
.value
- specifies valuekeyPath
- specifies key pathvalue
appropriate
for use in an SQL statementBindVariablePlaceHolderKey
,
mustUseBindVariableForAttribute(EOAttribute attribute)
,
shouldUseBindVariableForAttribute(EOAttribute attribute)
,
useBindVariables()
,
bindVariableDictionaries()
,
addBindVariableDictionary(NSDictionary binding)
,
formatValueForAttribute(Object value, EOAttribute attribute)
public String statement()
expressionForString
or using
setStatement
. Generally, however, an EOSQLExpression's statement
is built up using one of the following methods:
prepareSelectExpressionWithAttributes
prepareInsertExpressionWithRow
prepareUpdateExpressionWithRow
prepareDeleteExpressionForQualifier
setStatement(String aString)
,
EOSQLExpressionFactory.expressionForString(String string)
,
prepareSelectExpressionWithAttributes(
NSArray attributes, boolean lock, EOFetchSpecification fetchSpec)
,
prepareInsertExpressionWithRow(NSDictionary row)
,
prepareUpdateExpressionWithRow(NSDictionary row, EOQualifier qualifier)
,
prepareDeleteExpressionForQualifier(EOQualifier qualifier)
public String tableListWithRootEntity(EOEntity entity)
entity
-"EMPLOYEE", for example. If the receiver does use
table aliases (only in SELECT statements by default), the table list is a
comma separated list of table names and their aliases,
for example:
EMPLOYEE t0, DEPARTMENT t1
tableListWithRootEntity
creates a string containing the table name
for entity
and a corresponding table alias
("EMPLOYEE t0", for example). For each entry in
aliasesByRelationshipPath
, this method appends a new table name
and table alias.entity
- specifies receiver's entityuseAliases()
,
aliasesByRelationshipPath()
public String toString()
toString
in class Object
public boolean useAliases()
true
if the receiver generates statements with
table aliases, false
otherwise. For example,
the following SELECT statement uses table aliases:
SELECT t0.FIRST_NAME, t0.LAST_NAME, t1.NAME FROM EMPLOYEE t0, DEPARTMENT t1 WHERE t0.DEPARTMENT_ID = t1.DEPARTMENT_IDThe EMPLOYEE table has the alias t0, and the DEPARTMENT table has the alias t1. By default, EOSQLExpression uses table aliases only in SELECT statements. Enterprise Objects Framework assumes that INSERT, UPDATE, and DELETE statements are single-table operations.
true
if the receiver generates statements
with table aliases, false
otherwiseuseAliases()
,
aliasesByRelationshipPath()
,
EOSQLExpression
public boolean useBindVariables()
true
if instances use bind variables,
false
otherwisesetUseBindVariables(boolean flag)
,
EOSQLExpression
public static boolean useQuotedExternalNames()
externalNameQuoteCharacter()
public String valueList()
is "'Shaun', 'Hayes', 1319, 23, 4600". An EOSQLExpression's valueList is generated a value at a time withINSERT EMPLOYEE (FIRST_NAME, LAST_NAME, EMPLOYEE_ID, DEPARTMENT_ID, SALARY) VALUES ('Shaun', 'Hayes', 1319, 23, 4600)
addInsertListAttribute
messages.addInsertListAttribute(EOAttribute anEOAttribute, Object anObject)
public String whereClauseString()
whereClauseString
does not specify join conditions; the
joinClauseString
does that. Together, the whereClauseString
and the joinClauseString
make up a statement's where clause. For example, a
qualifier for an Employee entity specifies that a statement only affects
employees who belong to the Finance department and whose monthly salary is
greater than $4500. Assume the corresponding where clause looks like this:
EOSQLExpression generates both aWHERE EMPLOYEE.SALARY > 4500 AND DEPARTMENT.NAME = 'Finance' AND EMPLOYEE.DEPARTMENT_ID = DEPARTMENT.DEPARTMENT_ID
whereClauseString
and a joinClauseString
for this qualifier. The whereClauseString
qualifies the rows and looks
like this:
The joinClauseString specifies the join conditions between the EMPLOYEE table and the DEPARTMENT table and looks like this:EMPLOYEE.SALARY > 4500 AND DEPARTMENT.NAME = 'Finance'
EMPLOYEE.DEPARTMENT_ID = DEPARTMENT.DEPARTMENT_ID
joinClauseString()
,
whereClauseString()
,
EOQualifierSQLGeneration
|
Last updated Fri Feb 21 13:15:00 PST 2003. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |