content: /*
   * Copyright 1999-2012 Alibaba Group.
   *  
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *  
   *      http://www.apache.org/licenses/LICENSE-2.0
   *  
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  /**
   * (created at 2011-5-19)
   */
  package com.alibaba.cobar.parser.ast.stmt.dml;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.List;
  
  import com.alibaba.cobar.parser.ast.expression.Expression;
  import com.alibaba.cobar.parser.ast.expression.primary.Identifier;
  import com.alibaba.cobar.parser.ast.fragment.Limit;
  import com.alibaba.cobar.parser.ast.fragment.OrderBy;
  import com.alibaba.cobar.parser.ast.fragment.tableref.TableReferences;
  import com.alibaba.cobar.parser.util.Pair;
  import com.alibaba.cobar.parser.visitor.SQLASTVisitor;
  
  /**
   * @author <a href="mailto:shuo.qius@alibaba-inc.com">QIU Shuo</a>
   */
  public class DMLUpdateStatement extends DMLStatement {
      private final boolean lowPriority;
      private final boolean ignore;
      private final TableReferences tableRefs;
      private final List<Pair<Identifier, Expression>> values;
      private final Expression where;
      private final OrderBy orderBy;
      private final Limit limit;
  
      public DMLUpdateStatement(boolean lowPriority, boolean ignore, TableReferences tableRefs,
                                List<Pair<Identifier, Expression>> values, Expression where, OrderBy orderBy, Limit limit) {
          this.lowPriority = lowPriority;
          this.ignore = ignore;
          if (tableRefs == null)
              throw new IllegalArgumentException("argument tableRefs is null for update stmt");
          this.tableRefs = tableRefs;
          if (values == null || values.size() <= 0) {
              this.values = Collections.emptyList();
          } else if (!(values instanceof ArrayList)) {
              this.values = new ArrayList<Pair<Identifier, Expression>>(values);
          } else {
              this.values = values;
          }
          this.where = where;
          this.orderBy = orderBy;
          this.limit = limit;
      }
  
      public boolean isLowPriority() {
          return lowPriority;
      }
  
      public boolean isIgnore() {
          return ignore;
      }
  
      public TableReferences getTableRefs() {
          return tableRefs;
      }
  
      public List<Pair<Identifier, Expression>> getValues() {
          return values;
      }
  
      public Expression getWhere() {
          return where;
      }
  
      public OrderBy getOrderBy() {
          return orderBy;
      }
  
      public Limit getLimit() {
          return limit;
      }
  
      @Override
      public void accept(SQLASTVisitor visitor) {
          visitor.visit(this);
      }
  }
  