All Downloads are FREE. Search and download functionalities are using the official Maven repository.

studio.raptor.sqlparser.fast.command.dml.Update Maven / Gradle / Ivy

/*
 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
 * and the EPL 1.0 (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */
package studio.raptor.sqlparser.fast.command.dml;

import java.util.ArrayList;
import java.util.HashMap;
import studio.raptor.sqlparser.fast.api.ErrorCode;
import studio.raptor.sqlparser.fast.command.CommandInterface;
import studio.raptor.sqlparser.fast.command.Prepared;
import studio.raptor.sqlparser.fast.expression.Expression;
import studio.raptor.sqlparser.fast.expression.Parameter;
import studio.raptor.sqlparser.fast.message.ParseException;
import studio.raptor.sqlparser.fast.util.New;
import studio.raptor.sqlparser.fast.table.Column;

/**
 * This class represents the statement
 * UPDATE
 */
public class Update extends Prepared {

  private final ArrayList columns = New.arrayList();
  private final HashMap expressionMap = New.hashMap();
  private Expression condition;
  /**
   * The limit expression as specified in the LIMIT clause.
   */
  private Expression limitExpr;

  public Update() {
    super();
  }

  public void setCondition(Expression condition) {
    this.condition = condition;
  }

  /**
   * Add an assignment of the form column = expression.
   *
   * @param column the column
   * @param expression the expression
   */
  public void setAssignment(Column column, Expression expression) {
    if (expressionMap.containsKey(column)) {
      throw ParseException.get(ErrorCode.DUPLICATE_COLUMN_NAME_1, column
          .getName());
    }
    columns.add(column);
    expressionMap.put(column, expression);
    if (expression instanceof Parameter) {
      Parameter p = (Parameter) expression;
      p.setColumn(column);
    }
  }

  @Override
  public int getType() {
    return CommandInterface.UPDATE;
  }

  public void setLimit(Expression limit) {
    this.limitExpr = limit;
  }

  public Expression getCondition() {
    return condition;
  }

  public Expression getLimitExpr() {
    return limitExpr;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy