FileDocCategorySizeDatePackage
ResultSetMappingQuery.javaAPI DocGlassfish v2 API9412Tue May 22 16:54:50 BST 2007oracle.toplink.essentials.queryframework

ResultSetMappingQuery

public class ResultSetMappingQuery extends ObjectBuildingQuery

Purpose: Concrete class to perform read using raw SQL and the SQLResultSetMapping.

Responsibilities: Execute a selecting raw SQL string. Returns a List of results. Each item in the list will be another list consisting of the expected populated return types in the order they were specified in the SQLResultSetMapping

see
SQLResultSetMapping
author
Gordon Yorke
since
TopLink Java Essentials

Fields Summary
protected String
resultSetMappingName
protected SQLResultSetMapping
resultSetMapping
Constructors Summary
public ResultSetMappingQuery()
PUBLIC: Initialize the state of the query.

        super();
   
public ResultSetMappingQuery(Call call)
PUBLIC: Initialize the query to use the specified call.

        this();
        setCall(call);
    
public ResultSetMappingQuery(Call call, String sqlResultSetMappingName)
PUBLIC: Initialize the query to use the specified call and SQLResultSetMapping

        this();
        setCall(call);
        this.resultSetMappingName = sqlResultSetMappingName;
    
Methods Summary
protected java.util.ListbuildObjectsFromRecords(java.util.List databaseRecords)
INTERNAL: This method is used to build the results. Interpreting the SQLResultSetMapping.

        List results = new ArrayList(databaseRecords.size() );
        SQLResultSetMapping mapping = this.getSQLResultSetMapping();
        for (Iterator iterator = databaseRecords.iterator(); iterator.hasNext();){
            if (mapping.getResults().size()>1){
                Object[] resultElement = new Object[mapping.getResults().size()];
                DatabaseRecord record = (DatabaseRecord)iterator.next();
                for (int i = 0;i<mapping.getResults().size();i++){
                    resultElement[i] = ((SQLResult)mapping.getResults().get(i)).getValueFromRecord(record, this);
                }
                results.add(resultElement);
            }else if (mapping.getResults().size()==1) {
                DatabaseRecord record = (DatabaseRecord)iterator.next();
                results.add( ((SQLResult)mapping.getResults().get(0)).getValueFromRecord(record, this));
            }else {
                return results;
            }
        }
        return results;
        
    
public java.lang.Objectclone()
INTERNAL: Clone the query.

        ResultSetMappingQuery cloneQuery = (ResultSetMappingQuery)super.clone();
        cloneQuery.resultSetMapping = this.resultSetMapping;
        cloneQuery.resultSetMappingName = this.resultSetMappingName;
        return cloneQuery;
    
public voidconvertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this ResultSetMapping to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes.

param
classLoader

        resultSetMapping.convertClassNamesToClasses(classLoader);
    
public java.lang.ObjectexecuteDatabaseQuery()
INTERNAL: Executes the prepared query on the datastore.

        if (getSession().isUnitOfWork()) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();

            // Note if a nested unit of work this will recursively start a
            // transaction early on the parent also.
            if (isLockQuery()) {
                if ((!unitOfWork.getCommitManager().isActive()) && (!unitOfWork.wasTransactionBegunPrematurely())) {
                    unitOfWork.beginTransaction();
                    unitOfWork.setWasTransactionBegunPrematurely(true);
                }
            }
            if (unitOfWork.isNestedUnitOfWork()) {
                // execute in parent UOW then register normally here.
                UnitOfWorkImpl nestedUnitOfWork = (UnitOfWorkImpl)getSession();
                setSession(nestedUnitOfWork.getParent());
                Object result = executeDatabaseQuery();
                setSession(nestedUnitOfWork);
                Object clone = registerIndividualResult(result, unitOfWork, false, null);

                if (shouldUseWrapperPolicy()) {
                    clone = getDescriptor().getObjectBuilder().wrapObject(clone, unitOfWork);
                }
                return clone;
            }
        }
        session.validateQuery(this);// this will update the query with any settings

        if (getQueryId() == 0) {
            setQueryId(getSession().getNextQueryId());
        }

        Vector rows = getQueryMechanism().executeSelect();
        setExecutionTime(System.currentTimeMillis());
        // If using 1-m joins, must set all rows.
        return buildObjectsFromRecords(rows);
    
public oracle.toplink.essentials.queryframework.SQLResultSetMappinggetSQLResultSetMapping()
PUBLIC: This will be the SQLResultSetMapping that is used by this query to process the database results

        if (this.resultSetMapping == null && this.resultSetMappingName != null){
            this.resultSetMapping = this.getSession().getProject().getSQLResultSetMapping(this.resultSetMappingName);
        }
        return this.resultSetMapping;
    
public java.lang.StringgetSQLResultSetMappingName()
PUBLIC: Return the result set mapping name.

        return this.resultSetMappingName;
    
protected voidprepare()
INTERNAL: Prepare the receiver for execution in a session.

        if ((!shouldMaintainCache()) && shouldRefreshIdentityMapResult()) {
            throw QueryException.refreshNotPossibleWithoutCache(this);
        }

        getQueryMechanism().prepare();

        getQueryMechanism().prepareExecuteSelect();
    
public voidsetSQLResultSetMapping(oracle.toplink.essentials.queryframework.SQLResultSetMapping resultSetMapping)
PUBLIC: This will be the SQLResultSetMapping that is used by this query to process the database results

        this.resultSetMapping = resultSetMapping;
        this.resultSetMappingName = resultSetMapping.getName();
    
public voidsetSQLResultSetMappingName(java.lang.String name)
PUBLIC: This will be the SQLResultSetMapping that is used by this query to process the database results

        if (name == null && this.resultSetMapping == null){
            throw new IllegalArgumentException(ExceptionLocalization.buildMessage("null_sqlresultsetmapping_in_query"));
        }
        this.resultSetMappingName = name;