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

SQLCall

public class SQLCall extends DatabaseCall implements QueryStringCall
Purpose: Used as an abstraction of an SQL call. A call is an SQL string with parameters.

Fields Summary
protected boolean
hasCustomSQLArguments
Constructors Summary
public SQLCall()
PUBLIC: Create a new SQL call.

        super();
        this.hasCustomSQLArguments = false;
    
public SQLCall(String sqlString)
PUBLIC: Create a new SQL call.

        this();
        setSQLString(sqlString);
    
Methods Summary
protected voidafterTranslateCustomQuery(java.util.Vector updatedParameters, java.util.Vector updatedParameterTypes)
INTERNAL: Set the data passed through setCustomSQLArgumentType and useCustomSQLCursorOutputAsResultSet methods.

        for (int i = 0; i < getParameters().size(); i++) {
            Integer parameterType = (Integer)getParameterTypes().elementAt(i);
            Object parameter = getParameters().elementAt(i);
            if ((parameterType == MODIFY) || (parameterType == OUT) || (parameterType == OUT_CURSOR) || ((parameterType == IN) && parameter instanceof DatabaseField)) {
                DatabaseField field = (DatabaseField)parameter;
                afterTranslateCustomQueryUpdateParameter(field, i, parameterType, updatedParameters, updatedParameterTypes);
            } else if (parameterType == INOUT) {
                DatabaseField outField = (DatabaseField)((Object[])parameter)[1];
                afterTranslateCustomQueryUpdateParameter(outField, i, parameterType, updatedParameters, updatedParameterTypes);
                if ((((Object[])parameter)[0] instanceof DatabaseField) && (((Object[])parameter)[0] != ((Object[])parameter)[1])) {
                    DatabaseField inField = (DatabaseField)((Object[])parameter)[0];
                    afterTranslateCustomQueryUpdateParameter(inField, i, parameterType, updatedParameters, updatedParameterTypes);
                }
            }
        }
    
protected voidafterTranslateCustomQueryUpdateParameter(oracle.toplink.essentials.internal.helper.DatabaseField field, int index, java.lang.Integer parameterType, java.util.Vector updatedParameters, java.util.Vector updatedParameterTypes)
INTERNAL: Set the data passed through setCustomSQLArgumentType and useCustomSQLCursorOutputAsResultSet methods.

        for (int j = 0; j < updatedParameters.size(); j++) {
            DatabaseField updateField = (DatabaseField)updatedParameters.elementAt(j);
            if (field.equals(updateField)) {
                Integer updateParameterType = (Integer)updatedParameterTypes.elementAt(j);
                if (updateParameterType == null) {
                    field.setType(updateField.getType());
                } else if (updateParameterType == OUT_CURSOR) {
                    if (parameterType == OUT) {
                        getParameterTypes().setElementAt(OUT_CURSOR, index);
                    } else {
                        throw ValidationException.cannotSetCursorForParameterTypeOtherThanOut(field.getName(), toString());
                    }
                }
                break;
            }
        }
    
public voidappendTranslationParameter(java.io.Writer writer, oracle.toplink.essentials.internal.expressions.ParameterExpression expression, oracle.toplink.essentials.internal.databaseaccess.DatabasePlatform platform)
INTERNAL: All values are printed as ? to allow for parameter binding or translation during the execute of the call.

        try {
            platform.writeParameterMarker(writer, expression);
        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }
        getParameters().addElement(expression);
        getParameterTypes().addElement(TRANSLATION);
    
public booleanhasCustomSQLArguments()
INTERNAL: Used to avoid misiterpreting the # in custom SQL.

        return hasCustomSQLArguments;
    
public booleanisQueryStringCall()

        return true;
    
public booleanisSQLCall()

        return true;
    
protected voidprepareInternal(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Called by prepare method only.

        if (hasCustomSQLArguments()) {
            // hold results of setCustomSQLArgumentType and useCustomSQLCursorOutputAsResultSet methods
            Vector updatedParameters = null;
            Vector updatedParameterTypes = null;
            if (getParameters().size() > 0) {
                updatedParameters = getParameters();
                setParameters(oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance());
                updatedParameterTypes = getParameterTypes();
                setParameterTypes(oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance());
            }

            translateCustomQuery();

            if (updatedParameters != null) {
                afterTranslateCustomQuery(updatedParameters, updatedParameterTypes);
            }
        }

        super.prepareInternal(session);
    
public voidsetCustomSQLArgumentType(java.lang.String customParameterName, java.lang.Class type)
PUBLIC: This method should only be used with custom SQL: it sets a type to OUT or INOUT parameter (prefixed with ### or #### in custom SQL string).

        DatabaseField field = new DatabaseField(customParameterName);
        field.setType(type);
        getParameters().add(field);
        getParameterTypes().add(null);
    
public voidsetHasCustomSQLArguments(boolean hasCustomSQLArguments)
INTERNAL: Used to avoid misiterpreting the # in custom SQL.

        this.hasCustomSQLArguments = hasCustomSQLArguments;
    
public voidsetSQLString(java.lang.String sqlString)
Set the SQL string.

        setSQLStringInternal(sqlString);
    
public voiduseCustomSQLCursorOutputAsResultSet(java.lang.String customParameterName)
PUBLIC: This method should only be used with custom SQL: Used for Oracle result sets through procedures. It defines OUT parameter (prefixed with ### in custom SQL string) as a cursor output.

        DatabaseField field = new DatabaseField(customParameterName);
        getParameters().add(field);
        getParameterTypes().add(OUT_CURSOR);
        setIsCursorOutputProcedure(true);