Methods Summary |
---|
public void | addChild(oracle.toplink.essentials.expressions.Expression child)
getChildren().addElement(child);
|
public oracle.toplink.essentials.internal.helper.DatabaseTable | aliasForTable(oracle.toplink.essentials.internal.helper.DatabaseTable table)INTERNAL:
Find the alias for a given table
return getBaseExpression().aliasForTable(table);
|
public oracle.toplink.essentials.expressions.Expression | create(oracle.toplink.essentials.expressions.Expression base, java.lang.Object singleArgument, oracle.toplink.essentials.expressions.ExpressionOperator operator)INTERNAL:
baseExpression = base;
addChild(base);
Expression arg = Expression.from(singleArgument, base);
addChild(arg);
setOperator(operator);
return this;
|
public oracle.toplink.essentials.expressions.Expression | create(oracle.toplink.essentials.expressions.Expression base, java.util.Vector arguments, oracle.toplink.essentials.expressions.ExpressionOperator operator)INTERNAL:
baseExpression = base;
addChild(base);
for (Enumeration e = arguments.elements(); e.hasMoreElements();) {
Expression arg = Expression.from(e.nextElement(), base);
addChild(arg);
}
setOperator(operator);
return this;
|
public oracle.toplink.essentials.expressions.Expression | createWithBaseLast(oracle.toplink.essentials.expressions.Expression base, java.lang.Object singleArgument, oracle.toplink.essentials.expressions.ExpressionOperator anOperator)INTERNAL:
added for Trim support. TRIM([trim_character FROM] string_primary)
baseExpression = base;
Expression arg = Expression.from(singleArgument, base);
addChild(arg);
addChild(base);
setOperator(anOperator);
return this;
|
public java.lang.String | descriptionOfNodeType()INTERNAL:
Used for debug printing.
return "Function";
|
public boolean | doesConform(java.lang.Object object, oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow, oracle.toplink.essentials.queryframework.InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean isObjectUnregistered)INTERNAL:
Check if the object conforms to the expression in memory.
This is used for in-memory querying.
If the expression in not able to determine if the object conform throw a not supported exception.
// Must check for NOT and negate entire base expression.
if (getOperator().getSelector() == ExpressionOperator.Not) {
return !getBaseExpression().doesConform(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
}
// Conform between or in function.
if ((getOperator().getSelector() == ExpressionOperator.Between) || (getOperator().getSelector() == ExpressionOperator.NotBetween)
||(getOperator().getSelector() == ExpressionOperator.In) || (getOperator().getSelector() == ExpressionOperator.NotIn)) {
// Extract the value from the left side.
Object leftValue = getBaseExpression().valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
// Extract the value from the arguments, skip the first child which is the base.
Vector rightValue = new Vector(getChildren().size());
for (int index = 1; index < getChildren().size(); index++) {
Object valueFromRight;
if (getChildren().elementAt(index) instanceof Expression) {
valueFromRight = ((Expression)getChildren().elementAt(index)).valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
} else {
valueFromRight = getChildren().elementAt(index);
}
//If valueFromRight is a Vector, then there is only one child other than the base, e.g. valueFromRight is a collection of constants.
//Then it should be the vector to be compared with. Don't add it to another collection.
if (valueFromRight instanceof Vector) {
rightValue = (Vector)valueFromRight;
//Single values should be added to the rightValue, which will be compared with leftValue.
} else {
rightValue.addElement(valueFromRight);
}
}
// If left is anyof collection of values, check each one.
// If the right had an anyof not supported will be thrown from the operator.
if (leftValue instanceof Vector) {
for (Enumeration leftEnum = (Enumeration)((Vector)leftValue).elements();
leftEnum.hasMoreElements();) {
Object tempLeft = leftEnum.nextElement();
if (getOperator().doesRelationConform(tempLeft, rightValue)) {
return true;
}
}
// Only return false if none of the values match.
return false;
} else {
return getOperator().doesRelationConform(leftValue, rightValue);
}
} else if ((getOperator().getSelector() == ExpressionOperator.IsNull) || (getOperator().getSelector() == ExpressionOperator.NotNull)) {
// Extract the value from the left side.
Object leftValue = getBaseExpression().valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
// If left is anyof collection of values, check each one.
if (leftValue instanceof Vector) {
for (Enumeration leftEnum = (Enumeration)((Vector)leftValue).elements();
leftEnum.hasMoreElements();) {
Object tempLeft = leftEnum.nextElement();
if (getOperator().doesRelationConform(tempLeft, null)) {
return true;
}
}
// Only return false if none of the values match.
return false;
} else {
return getOperator().doesRelationConform(leftValue, null);
}
}
// No other relation functions are supported.
// Non-relation functions are supported through valueFromObject().
throw QueryException.cannotConformExpression();
|
public oracle.toplink.essentials.expressions.Expression | getBaseExpression()
return baseExpression;
|
public oracle.toplink.essentials.expressions.ExpressionBuilder | getBuilder()Return the expression builder which is the ultimate base of this expression, or
null if there isn't one (shouldn't happen if we start from a root)
if (getBaseExpression() == null) {
return null;
}
return getBaseExpression().getBuilder();
|
public java.util.Vector | getChildren()
return children;
|
public java.util.Vector | getFields()INTERNAL: Not to be confused with the public getField(String)
This returns a collection of all fields associated with this object. Really
only applies to query keys representing an object or to expression builders.
return getBaseExpression().getFields();
|
public oracle.toplink.essentials.expressions.ExpressionOperator | getOperator()
return operator;
|
public oracle.toplink.essentials.expressions.ExpressionOperator | getPlatformOperator(oracle.toplink.essentials.internal.databaseaccess.DatabasePlatform platform)
if (platformOperator == null) {
initializePlatformOperator(platform);
}
return platformOperator;
|
public java.lang.Class | getResultType()
return resultType;
|
public boolean | hasResultType()
return resultType != null;
|
public void | initializePlatformOperator(oracle.toplink.essentials.internal.databaseaccess.DatabasePlatform platform)INTERNAL:
if (getOperator().isComplete()) {
platformOperator = getOperator();
return;
}
platformOperator = platform.getOperator(getOperator().getSelector());
if (platformOperator == null) {
throw QueryException.invalidOperator(getOperator().toString());
}
|
public boolean | isFunctionExpression()
return true;
|
protected boolean | isObjectComparison()INTERNAL:
Return if the represents an object comparison.
if (getChildren().size() != 1) {
return false;
}
int selector = getOperator().getSelector();
if ((selector != ExpressionOperator.IsNull) && (selector != ExpressionOperator.NotNull)) {
return false;
}
Expression base = getBaseExpression();
return (base.isObjectExpression() && (!((ObjectExpression)base).isAttribute()));
|
public void | iterateOn(oracle.toplink.essentials.internal.expressions.ExpressionIterator iterator)INTERNAL:
For iterating using an inner class
super.iterateOn(iterator);
for (Enumeration childrenEnum = getChildren().elements(); childrenEnum.hasMoreElements();) {
Expression child = (Expression)childrenEnum.nextElement();
child.iterateOn(iterator);
}
|
public oracle.toplink.essentials.expressions.Expression | normalize(oracle.toplink.essentials.internal.expressions.ExpressionNormalizer normalizer)INTERNAL:
Normalize into a structure that is printable.
Also compute printing information such as outer joins.
This checks for object isNull and notNull comparisons.
//This method has no validation but we should still make the method call for consistency
//bug # 2956674
//validation is moved into normalize to ensure that expressions are valid before we attempt to work with them
validateNode();
if (getChildren().isEmpty()) {
return this;
}
if (!isObjectComparison()) {
for (int index = 0; index < getChildren().size(); index++) {
getChildren().setElementAt(((Expression)getChildren().elementAt(index)).normalize(normalizer), index);
}
return this;
} else {
//if not normalising we must still validate the corresponding node to make sure that they are valid
//bug # 2956674
for (int index = 0; index < getChildren().size(); index++) {
((Expression)getChildren().elementAt(index)).validateNode();
}
}
// This code is executed only in the case of an is[not]Null on an
// object attribute.
ObjectExpression base = (ObjectExpression)getBaseExpression();
// For cr2334, fix code so that normalize is first called on base expressions.
// I.e. if base itself had a base expression this expression would not be normalized.
base.getBaseExpression().normalize(normalizer);
// Switch to null foreign key comparison (i.e. get('c').isNull() to getField('C_ID').isNull()).
// For bug 3105559 also must handle aggregates: get("period").isNull();
Expression foreignKeyJoin = base.getMapping().buildObjectJoinExpression(base, (Object)null, getSession());
if (getOperator().getSelector() == ExpressionOperator.NotNull) {
foreignKeyJoin = foreignKeyJoin.not();
}
return foreignKeyJoin;
|
protected void | postCopyIn(java.util.Dictionary alreadyDone)INTERNAL:
Used for cloning.
super.postCopyIn(alreadyDone);
baseExpression = baseExpression.copiedVersionFrom(alreadyDone);
Vector oldChildren = children;
children = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
for (int i = 0; i < oldChildren.size(); i++) {
addChild((Expression)(((Expression)oldChildren.elementAt(i)).copiedVersionFrom(alreadyDone)));
}
|
public void | printInCollection(java.util.Vector items, oracle.toplink.essentials.internal.expressions.ExpressionSQLPrinter printer, oracle.toplink.essentials.expressions.ExpressionOperator operator)INTERNAL: Print the collection in "IN" onto the SQL stream. Go through the collection to print out each element.
((Expression)items.elementAt(0)).printSQL(printer);
printer.printString(operator.getDatabaseStrings()[0]);
for (int i = 1; i < items.size() - 1; i++) {
Expression item = (Expression)items.elementAt(i);
item.printSQL(printer);
printer.printString(", ");
}
((Expression)items.elementAt(items.size() - 1)).printSQL(printer);
printer.printString(operator.getDatabaseStrings()[1]);
|
public void | printJava(oracle.toplink.essentials.internal.expressions.ExpressionJavaPrinter printer)INTERNAL:
Print java for project class generation
ExpressionOperator realOperator = getPlatformOperator(printer.getPlatform());
realOperator.printJavaCollection(getChildren(), printer);
|
public void | printSQL(oracle.toplink.essentials.internal.expressions.ExpressionSQLPrinter printer)INTERNAL:
Print SQL
ExpressionOperator realOperator;
realOperator = getPlatformOperator(printer.getPlatform());
//In or NotIn operator only comes with " IN (" and ")" since the number of elements are unknown. Need to go through
//the collection to print out each element.
if (realOperator.getSelector() == ExpressionOperator.In || realOperator.getSelector() == ExpressionOperator.NotIn) {
printInCollection(getChildren(), printer, realOperator);
} else {
realOperator.printCollection(getChildren(), printer);
}
|
public oracle.toplink.essentials.expressions.Expression | rebuildOn(oracle.toplink.essentials.expressions.Expression newBase)INTERNAL:
This expression is built on a different base than the one we want. Rebuild it and
return the root of the new tree
Expression newLocalBase = getBaseExpression().rebuildOn(newBase);
Vector newChildren = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(getChildren().size());
for (int i = 1; i < getChildren().size(); i++) {// Skip the first one, since it's also the base
newChildren.addElement(((Expression)children.elementAt(i)).rebuildOn(newBase));
}
newLocalBase.setSelectIfOrderedBy(getBaseExpression().selectIfOrderedBy());
FunctionExpression rebuilt = (FunctionExpression) newLocalBase.performOperator(getOperator(), newChildren);
rebuilt.setResultType(this.getResultType()); //copy over result type.
return rebuilt;
|
public void | setBaseExpression(oracle.toplink.essentials.expressions.Expression expression)Sets the base of the expression
Added to allow creation of functions which take the column name
as something other than the first option.
Creation date: (9/11/00 4:04:03 PM)
baseExpression = expression;
|
public void | setLocalBase(oracle.toplink.essentials.expressions.Expression exp)
getBaseExpression().setLocalBase(exp);
|
public void | setOperator(oracle.toplink.essentials.expressions.ExpressionOperator theOperator)
operator = theOperator;
|
public void | setResultType(java.lang.Class resultType)
this.resultType = resultType;
|
public oracle.toplink.essentials.expressions.Expression | twistedForBaseAndContext(oracle.toplink.essentials.expressions.Expression newBase, oracle.toplink.essentials.expressions.Expression context)INTERNAL:
Rebuild myself against the base, with the values of parameters supplied by the context
expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping)
into part of some larger expression. You normally would not call this directly, instead calling twist
See the comment there for more details"
if (getChildren().isEmpty()) {
return (Expression)clone();
}
Vector newChildren = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(getChildren().size());
// For functions the base is the first child, we only want the arguments so start at the second.
for (int index = 1; index < getChildren().size(); index++) {
newChildren.addElement(((Expression)children.elementAt(index)).twistedForBaseAndContext(newBase, context));
}
// Aply the function to the twisted old base.
Expression oldBase = (Expression)getChildren().elementAt(0);
return oldBase.twistedForBaseAndContext(newBase, context).performOperator(getOperator(), newChildren);
|
public java.lang.Object | valueFromObject(java.lang.Object object, oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow, oracle.toplink.essentials.queryframework.InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean isObjectUnregistered)INTERNAL:
Return the value for in memory comparison.
This is only valid for valueable expressions.
Object baseValue = getBaseExpression().valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
Vector arguments = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(getChildren().size());
for (int index = 1; index < getChildren().size(); index++) {
if (getChildren().elementAt(index) instanceof Expression) {
arguments.addElement(((Expression)getChildren().elementAt(index)).valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered));
} else {
arguments.addElement(getChildren().elementAt(index));
}
}
if (baseValue instanceof Vector) {// baseValue might be a vector, so the individual values must be extracted before applying the function call to them
Vector baseVector = new Vector();
for (Enumeration valuesToCompare = (Enumeration)((Vector)baseValue).elements();
valuesToCompare.hasMoreElements();) {
Object baseObject = (Object)valuesToCompare.nextElement();
if (baseObject == null) {
baseVector.addElement(baseObject);
} else {
baseVector.addElement(getOperator().applyFunction(baseObject, arguments));
}
}
return baseVector;
} else {
// Do not apply functions to null, just leave as null.
if (baseValue == null) {
return null;
} else {
return getOperator().applyFunction(baseValue, arguments);
}
}
|
public void | writeDescriptionOn(java.io.BufferedWriter writer)INTERNAL:
Used to print a debug form of the expression tree.
writer.write(operator.toString());
|
public void | writeFields(oracle.toplink.essentials.internal.expressions.ExpressionSQLPrinter printer, java.util.Vector newFields, oracle.toplink.essentials.internal.expressions.SQLSelectStatement statement)INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...)
//print ", " before each selected field except the first one
if (printer.isFirstElementPrinted()) {
printer.printString(", ");
} else {
printer.setIsFirstElementPrinted(true);
}
if (getBaseExpression().isDataExpression()) {
DatabaseField field = ((DataExpression)getBaseExpression()).getField();
if (field == null) {
// This means the select wants a *.
field = new DatabaseField("*");
field.setType(getResultType());
} else {
// Set the result type to the type specified for this function
// expression, if one has been set. Otherwise, use the mappings
// database field type.
if (hasResultType()) {
field = (DatabaseField) field.clone();
field.setType(getResultType());
}
}
newFields.addElement(field);
} else {
// This field is a complex function value so any name can be used.
DatabaseField field = new DatabaseField("*");
field.setType(getResultType());
newFields.addElement(field);
}
printSQL(printer);
|
public void | writeSubexpressionsTo(java.io.BufferedWriter writer, int indent)INTERNAL:
Used in SQL printing.
if (baseExpression != null) {
baseExpression.toString(writer, indent);
}
|