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

SQLInsertStatement

public class SQLInsertStatement extends SQLModifyStatement

Purpose: Print INSERT statement.

Responsibilities:

  • Print INSERT 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(200);
        try {
            writer.write("INSERT ");
            writer.write("INTO ");
            writer.write(getTable().getQualifiedName());
            writer.write(" (");

            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()) {
                throw QueryException.objectToInsertIsEmpty(getTable());
            }

            for (int i = 0; i < fieldsForTable.size(); i++) {
                writer.write(((DatabaseField)fieldsForTable.elementAt(i)).getName());
                if ((i + 1) < fieldsForTable.size()) {
                    writer.write(", ");
                }
            }
            writer.write(") VALUES (");

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

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