FileDocCategorySizeDatePackage
SQLUpdateStatement.javaAPI DocGlassfish v2 API4344Tue May 22 16:54:34 BST 2007oracle.toplink.essentials.internal.expressions

SQLUpdateStatement

public class SQLUpdateStatement extends SQLModifyStatement

Purpose: Print UPDATE statement.

Responsibilities:

  • Print UPDATE statement.
author
Dorin Sandu
since
TOPLink/Java 1.0

Fields Summary
Constructors Summary
Methods Summary
protected oracle.toplink.essentials.queryframework.SQLCallbuildCallWithoutReturning(oracle.toplink.essentials.internal.sessions.AbstractSession session)
Append the string containing the SQL insert string for the given table.

        SQLCall call = new SQLCall();
        call.returnNothing();

        Writer writer = new CharArrayWriter(100);
        try {
            writer.write("UPDATE ");
            writer.write(getTable().getQualifiedName());
            writer.write(" SET ");

            Vector fieldsForTable = new Vector();
            for (Enumeration fieldsEnum = getModifyRow().keys(); fieldsEnum.hasMoreElements();) {
                DatabaseField field = (DatabaseField)fieldsEnum.nextElement();
                if (field.getTable().equals(getTable()) || (!field.hasTableName())) {
                    fieldsForTable.addElement(field);
                }
            }

            if (fieldsForTable.isEmpty()) {
                return null;
            }

            for (int i = 0; i < fieldsForTable.size(); i++) {
                DatabaseField field = (DatabaseField)fieldsForTable.elementAt(i);
                writer.write(field.getName());
                writer.write(" = ");
                call.appendModify(writer, field);

                if ((i + 1) < fieldsForTable.size()) {
                    writer.write(", ");
                }
            }

            if (!(getWhereClause() == null)) {
                writer.write(" WHERE ");
                ExpressionSQLPrinter printer = new ExpressionSQLPrinter(session, getTranslationRow(), call, false);
                printer.setWriter(writer);
                printer.printExpression(getWhereClause());
            }

            call.setSQLString(writer.toString());
            return call;
        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }