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

br.com.objectos.sql.InsertValues2 Maven / Gradle / Ivy

/*
 * Copyright 2014-2015 Objectos, Fábrica de Software LTDA.
 *
 * 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.
 */
package br.com.objectos.sql;

import java.util.List;

import br.com.objectos.db.Dialect;
import br.com.objectos.db.GeneratedKeyListener;
import br.com.objectos.db.InsertBuilder;
import br.com.objectos.db.InsertableValue;
import br.com.objectos.db.ParameterBinder;

/**
 * @author [email protected] (Marcio Endo)
 */
public class InsertValues2
    extends InsertNode
    implements
    InsertValues,
    InsertableRow2,
    InsertableRow2.Values {

  final InsertValue val1;
  final InsertValue val2;

  InsertValues2(InsertNode previous, T1 val1, T2 val2) {
    super(previous);
    this.val1 = InsertValue.of(val1);
    this.val2 = InsertValue.of(val2);
  }

  private InsertValues2(InsertNode previous, InsertValue val1, InsertValue val2) {
    super(previous);
    this.val1 = val1;
    this.val2 = val2;
  }

  @Override
  public InsertQuery compile(Dialect dialect) {
    return new SimpleInsertQuery(dialect, this);
  }

  @Override
  public InsertOnDuplicateKey onDuplicateKey() {
    return new InsertOnDuplicateKey(this);
  }

  @Override
  public InsertValues2 onGeneratedKey(GeneratedKeyListener listener) {
    return new OnGeneratedKey<>(this, val1, val2, listener);
  }

  @Override
  public InsertValues2 values(T1 val1, T2 val2) {
    return new More<>(this, val1, val2);
  }

  @Override
  ParameterBinder bind0(ParameterBinder binder) {
    val1.bind(binder);
    val2.bind(binder);
    return binder;
  }

  @Override
  InsertBuilder write0(InsertBuilder sql) {
    return sql.values(val1, val2);
  }

  private static class OnGeneratedKey
      extends InsertValues2 {

    private final GeneratedKeyListener listener;

    public OnGeneratedKey(InsertNode previous,
                          InsertValue val1,
                          InsertValue val2,
                          GeneratedKeyListener listener) {
      super(previous, val1, val2);
      this.listener = listener;
    }

    @Override
    void acceptListenerList(List listenerList) {
      super.acceptListenerList(listenerList);
      listenerList.add(listener);
    }

    @Override
    ParameterBinder bind0(ParameterBinder binder) {
      return binder;
    }

    @Override
    InsertBuilder write0(InsertBuilder sql) {
      return sql;
    }

  }

  private static class More
      extends InsertValues2 {

    public More(InsertNode previous, T1 val1, T2 val2) {
      super(previous, val1, val2);
    }

    @Override
    InsertBuilder write0(InsertBuilder sql) {
      return sql.moreValues(val1, val2);
    }

  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy