FileDocCategorySizeDatePackage
ReportItem.javaAPI DocGlassfish v2 API8098Tue May 22 16:54:40 BST 2007oracle.toplink.essentials.internal.queryframework

ReportItem

public class ReportItem extends Object implements Serializable
Purpose: represents an item requested (i.e. field for SELECT)
author
Doug Clarke
since
2.0

Fields Summary
protected Expression
attributeExpression
Expression (partial) describing the attribute wanted
protected String
name
Name given for item, can be used to retieve value from result. Useful if same field retrieved multipe times
protected DatabaseMapping
mapping
Mapping which relates field to attribute, used to convert value and determine reference descriptor
protected ClassDescriptor
descriptor
Desriptor for object result that is not based on an expression
protected Class
resultType
Result type for this report item.
protected JoinedAttributeManager
joinManager
Stores the Join information for this item
protected int
resultIndex
Stores the row index for this item, given multiple results and joins
Constructors Summary
public ReportItem()

        super();
    
public ReportItem(String name, Expression attributeExpression)

        this.name = name;
        this.attributeExpression = attributeExpression;
        this.joinManager = new JoinedAttributeManager();
    
Methods Summary
public oracle.toplink.essentials.expressions.ExpressiongetAttributeExpression()

        return attributeExpression;
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptor()

        return this.descriptor;
    
public oracle.toplink.essentials.internal.queryframework.JoinedAttributeManagergetJoinedAttributeManager()
INTERNAL: Set the list of expressions that represent elements that are joined because of their mapping for this query.

        return this.joinManager;
    
public oracle.toplink.essentials.mappings.DatabaseMappinggetMapping()

        return mapping;
    
public java.lang.StringgetName()

        return name;
    
public intgetResultIndex()

        return resultIndex;
    
public java.lang.ClassgetResultType()

        return resultType;
    
public voidinitialize(oracle.toplink.essentials.queryframework.ReportQuery query)
INTERNAL: Looks up mapping for attribute during preExecute of ReportQuery

        if (getMapping() == null) {
            DatabaseMapping mapping = query.getLeafMappingFor(getAttributeExpression(), query.getDescriptor());
            if (mapping == null){
                if (getAttributeExpression() != null){
                    if (getAttributeExpression().isExpressionBuilder()) {
                        Class resultClass = ((ExpressionBuilder)getAttributeExpression()).getQueryClass();
                        if (resultClass == null){
                            resultClass = query.getReferenceClass();
                        }
                        setDescriptor(query.getSession().getDescriptor(resultClass));
                        if (getDescriptor().hasInheritance()){
                            ((ExpressionBuilder)getAttributeExpression()).setShouldUseOuterJoinForMultitableInheritance(true);
                        }
                    }
                }
            }else{
                //Bug4942640  Widen the check to support collection mapping too
                if (mapping.isForeignReferenceMapping()){
                    setDescriptor(mapping.getReferenceDescriptor());
                    if (getDescriptor().hasInheritance()){
                        ((QueryKeyExpression)getAttributeExpression()).setShouldUseOuterJoinForMultitableInheritance(true);
                    }
                } else if (mapping.isAbstractDirectMapping()){
                    setMapping((DatabaseMapping)mapping);
                } else {
                    throw QueryException.invalidExpressionForQueryItem(getAttributeExpression(), query);
                }
            }
            this.joinManager.setDescriptor(this.descriptor);
            this.joinManager.setBaseQuery(query);
            if (getAttributeExpression() != null){
                if (getAttributeExpression().getBuilder().wasQueryClassSetInternally()){
                    //rebuild if class was not set by user this ensures the query has the same base
                    this.attributeExpression = getAttributeExpression().rebuildOn(query.getExpressionBuilder());
                }
                this.joinManager.setBaseExpressionBuilder(this.attributeExpression.getBuilder());
            }else{
                this.joinManager.setBaseExpressionBuilder(query.getExpressionBuilder());
            }
            this.joinManager.prepareJoinExpressions(query.getSession());
        }
    
public booleanisContructorItem()

        return false;
    
public booleanisPlaceHolder()

return
true if there is no expression (null)

        return getAttributeExpression() == null;
    
public voidsetDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)

        this.descriptor = descriptor;
    
public voidsetMapping(oracle.toplink.essentials.mappings.DatabaseMapping mapping)

        this.mapping = mapping;
    
public voidsetResultIndex(int resultIndex)

        this.resultIndex = resultIndex;
        this.joinManager.setParentResultIndex(resultIndex);
    
public voidsetResultType(java.lang.Class resultType)

        this.resultType = resultType;
    
        // Set it on the attribute expression as well if it is a function.
        if (getAttributeExpression()!=null && getAttributeExpression().isFunctionExpression()) {
            ((FunctionExpression) getAttributeExpression()).setResultType(resultType);
        }
    
public java.lang.StringtoString()

        return "ReportQueryItem(" + getName() + " -> " + getAttributeExpression() + ")";