FileDocCategorySizeDatePackage
FieldExpression.javaAPI DocGlassfish v2 API9676Tue May 22 16:54:32 BST 2007oracle.toplink.essentials.internal.expressions

FieldExpression

public class FieldExpression extends DataExpression
Field expressions represent a field of a table. Their base is either a table or object expression. This is used for mapping queries and to allow queries on non-mapped field or tables.

Fields Summary
protected DatabaseField
field
protected transient DatabaseField
aliasedField
Constructors Summary
public FieldExpression()
FieldExpression constructor comment.

        super();
    
public FieldExpression(DatabaseField newField)
FieldExpression constructor comment.

        super();
        field = newField;
    
public FieldExpression(DatabaseField newField, Expression myBase)
FieldExpression constructor comment.

        super();
        field = newField;
        baseExpression = myBase;
    
Methods Summary
public voidclearAliases()
INTERNAL:

        super.clearAliases();
        aliasedField = null;
    
public java.lang.StringdescriptionOfNodeType()
INTERNAL: Used for debug printing.

        return "Field";
    
public oracle.toplink.essentials.internal.helper.DatabaseFieldgetAliasedField()
INTERNAL: Return the field appropriately aliased

        if (aliasedField == null) {
            initializeAliasedField();
        }
        return aliasedField;

    
private oracle.toplink.essentials.internal.helper.DatabaseTablegetAliasedTable()
Return the alias for our table

        DataExpression base = (DataExpression)getBaseExpression();
        if (!getField().hasTableName()) {
            base.getDescriptor().buildField(getField());
        }

        DatabaseTable alias = base.aliasForTable(getField().getTable());
        if (alias == null) {
            return getField().getTable();
        } else {
            return alias;
        }
    
public oracle.toplink.essentials.internal.helper.DatabaseFieldgetClonedField()
INTERNAL: If there are any fields associated with this expression, return them

        return (DatabaseField)getField().clone();
    
public java.util.VectorgetClonedFields()
INTERNAL: If there are any fields associated with this expression, return them

        Vector result = new Vector(1);
        result.addElement(getField().clone());
        return result;
    
public oracle.toplink.essentials.internal.helper.DatabaseFieldgetField()
INTERNAL:

        return field;
    
public java.util.VectorgetFields()
INTERNAL: Return all the fields

        Vector result = new Vector(1);
        result.addElement(getField());
        return result;
    
private voidinitializeAliasedField()
INTERNAL: Alias the database field for our current environment

        DatabaseField tempField = (DatabaseField)getField().clone();
        DatabaseTable aliasedTable = getAliasedTable();

        //  Put in a special check here so that if the aliasing does nothing we don't cache the
        // result because it's invalid. This saves us from caching premature data if e.g. debugging
        // causes us to print too early"
        //	if (aliasedTable.equals(getField().getTable())) {
        //		return;
        //	} else {
        aliasedField = tempField;
        aliasedField.setTable(aliasedTable);
        //	}
    
public booleanisAttribute()
INTERNAL:

        return true;
    
public booleanisFieldExpression()

        return true;
    
public voidprintJava(oracle.toplink.essentials.internal.expressions.ExpressionJavaPrinter printer)
INTERNAL: Print java for project class generation

        getBaseExpression().printJava(printer);
        printer.printString(".getField(\"" + getField().getQualifiedName() + "\")");
    
public voidprintSQL(oracle.toplink.essentials.internal.expressions.ExpressionSQLPrinter printer)
INTERNAL: Print SQL onto the stream, using the ExpressionPrinter for context

        printer.printField(getAliasedField());
    
public oracle.toplink.essentials.expressions.ExpressionrebuildOn(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

        FieldExpression expression = new FieldExpression(getField(), getBaseExpression().rebuildOn(newBase));
        expression.setSelectIfOrderedBy(selectIfOrderedBy());
        return expression;
    
public voidsetField(oracle.toplink.essentials.internal.helper.DatabaseField newField)
INTERNAL: Set the field in the mapping.

        field = newField;
    
public oracle.toplink.essentials.expressions.ExpressiontwistedForBaseAndContext(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"

        Expression twistedBase = getBaseExpression().twistedForBaseAndContext(newBase, context);
        return twistedBase.getField(getField());
    
public voidvalidateNode()
Do any required validation for this node. Throw an exception if it's incorrect.

        DataExpression base = (DataExpression)getBaseExpression();
        if (getField().getTable().hasName()) {
            Vector tables = base.getOwnedTables();
            if ((tables != null) && (!tables.contains((getField().getTable())))) {
                throw QueryException.invalidTableForFieldInExpression(getField());
            }
        }
    
public java.lang.ObjectvalueFromObject(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.

        // Joins not supported.
        if (getBuilder() != getBaseExpression()) {
            throw QueryException.cannotConformExpression();
        }

        // For bug 2780817 get the mapping directly from the object.  In EJB 2.0 
        // inheritance, each child must override mappings defined in an abstract 
        // class with its own.
        DatabaseMapping mapping = session.getDescriptor(object.getClass()).getObjectBuilder().getMappingForField(getField());
        if (mapping == null) {
            throw QueryException.cannotConformExpression();
        }

        return mapping.valueFromObject(object, getField(), session);
    
public voidwriteDescriptionOn(java.io.BufferedWriter writer)
INTERNAL: Used to print a debug form of the expression tree.

        writer.write(getField().toString());
    
public voidwriteFields(oracle.toplink.essentials.internal.expressions.ExpressionSQLPrinter printer, java.util.Vector newFields, oracle.toplink.essentials.internal.expressions.SQLSelectStatement statement)
INTERNAL: called from SQLSelectStatement.writeFieldsFromExpression(...)

        DatabaseField field = getField();

        if (field != null) {
            newFields.addElement(field);
            writeField(printer, field, statement);
        }