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

ExpressionSQLPrinter

public class ExpressionSQLPrinter extends Object

Purpose: Expression SQL printer.

Responsibilities:

  • Print an expression in SQL format.
  • Replaces FIELD types with field names from the descriptor.
  • Replaces PARAMETER types with row or object values.
  • Calls accessor to print primitive types.
author
Dorin Sandu
since
TOPLink/Java 1.0

Fields Summary
protected AbstractSession
session
Stores the current session. The session accessor is used to print all the primitive types.
protected SQLCall
call
Stores the call being created.
protected AbstractRecord
translationRow
Stores the row. Used to print PARAMETER nodes.
protected boolean
shouldPrintQualifiedNames
Indicates whether fully qualified field names (owner + table) should be used or not.
protected Writer
writer
protected boolean
requiresDistinct
Used for distincts in functions.
protected boolean
isFirstElementPrinted
Constructors Summary
public ExpressionSQLPrinter(AbstractSession session, AbstractRecord translationRow, SQLCall call, boolean printQualifiedNames)

        this.session = session;
        this.translationRow = translationRow;
        this.call = call;
        this.shouldPrintQualifiedNames = printQualifiedNames;
        this.requiresDistinct = false;
        isFirstElementPrinted = false;
    
Methods Summary
protected oracle.toplink.essentials.queryframework.SQLCallgetCall()
Return the call.

        return call;
    
public oracle.toplink.essentials.internal.databaseaccess.DatabasePlatformgetPlatform()
INTERNAL: Return the database platform specific information.

        return session.getPlatform();
    
protected oracle.toplink.essentials.internal.sessions.AbstractSessiongetSession()

        return session;
    
protected oracle.toplink.essentials.internal.sessions.AbstractRecordgetTranslationRow()
INTERNAL: Return the row for translation

        return translationRow;
    
public java.io.WritergetWriter()

        return writer;
    
public booleanisFirstElementPrinted()
INTERNAL: Used in figuring out when to print a comma in the select clause

        return isFirstElementPrinted;
    
public voidprintExpression(oracle.toplink.essentials.expressions.Expression expression)

        translateExpression(expression);
    
public voidprintField(oracle.toplink.essentials.internal.helper.DatabaseField field)

        if (field == null) {
            return;
        }

        try {
            // Print the field using either short or long notation i.e. owner + table name.
            if (shouldPrintQualifiedNames()) {
                getWriter().write(field.getQualifiedName());
            } else {
                getWriter().write(field.getName());
            }
        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }
    
public voidprintNull(oracle.toplink.essentials.internal.expressions.ConstantExpression nullValueExpression)

        if(session.getPlatform().shouldBindLiterals()) {
            DatabaseField field = null;
            Expression localBase = nullValueExpression.getLocalBase();
            if(localBase.isFieldExpression()) {
                field = ((FieldExpression)localBase).getField();
            } else if(localBase.isQueryKeyExpression()) {
                field = ((QueryKeyExpression)localBase).getField();
            }
            session.getPlatform().appendLiteralToCall(getCall(), getWriter(), field);
        } else {
            session.getPlatform().appendLiteralToCall(getCall(), getWriter(), null);
        }
    
public voidprintParameter(oracle.toplink.essentials.internal.expressions.ParameterExpression expression)

        try {
            getCall().appendTranslationParameter(getWriter(), expression, getPlatform());

        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }
    
public voidprintParameter(oracle.toplink.essentials.internal.helper.DatabaseField field)

        getCall().appendTranslation(getWriter(), field);
    
public voidprintPrimitive(java.lang.Object value)

        if (value instanceof Vector) {
            printValuelist((Vector)value);
            return;
        }

        session.getPlatform().appendLiteralToCall(getCall(), getWriter(), value);
    
public voidprintString(java.lang.String value)

        try {
            getWriter().write(value);

        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }
    
public voidprintValuelist(java.util.Vector values)

        try {
            Enumeration valuesEnum = values.elements();
            while (valuesEnum.hasMoreElements()) {
                Object value = valuesEnum.nextElement();
                session.getPlatform().appendLiteralToCall(getCall(), getWriter(), value);
                if (valuesEnum.hasMoreElements()) {
                    getWriter().write(", ");
                }
            }
        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }
    
public booleanrequiresDistinct()
If a distinct has been set the DISTINCT clause will be printed. This is required for batch reading.

        return requiresDistinct;
    
protected voidsetCall(oracle.toplink.essentials.queryframework.SQLCall call)

        this.call = call;
    
public voidsetIsFirstElementPrinted(boolean isFirstElementPrinted)
INTERNAL: Used in figuring out when to print a comma in the select clause

        this.isFirstElementPrinted = isFirstElementPrinted;
    
public voidsetRequiresDistinct(boolean requiresDistinct)
If a distinct has been set the DISTINCT clause will be printed. This is required for batch reading.

        this.requiresDistinct = requiresDistinct;
    
protected voidsetSession(oracle.toplink.essentials.internal.sessions.AbstractSession theSession)

        session = theSession;
    
protected voidsetShouldPrintQualifiedNames(boolean shouldPrintQualifiedNames)

        this.shouldPrintQualifiedNames = shouldPrintQualifiedNames;
    
protected voidsetTranslationRow(oracle.toplink.essentials.internal.sessions.AbstractRecord theRow)
INTERNAL: Set the row for translation

        translationRow = theRow;
    
public voidsetWriter(java.io.Writer writer)

        this.writer = writer;
    
public booleanshouldPrintParameterValues()

        return getTranslationRow() != null;
    
protected booleanshouldPrintQualifiedNames()

        return shouldPrintQualifiedNames;
    
protected voidtranslateExpression(oracle.toplink.essentials.expressions.Expression theExpression)
Translate an expression i.e. call the appropriate translation method for the expression based on its type. The translation method is then responsible for translating the subexpressions.

        theExpression.printSQL(this);