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

info.archinnov.achilles.generated.dsl.MultiClusteringEntity_Update Maven / Gradle / Ivy

package info.archinnov.achilles.generated.dsl;

import com.datastax.driver.core.querybuilder.NonEscapingSetAssignment;
import com.datastax.driver.core.querybuilder.NotEq;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Update;
import info.archinnov.achilles.generated.meta.entity.MultiClusteringEntity_AchillesMeta;
import info.archinnov.achilles.internals.dsl.query.update.AbstractUpdate;
import info.archinnov.achilles.internals.dsl.query.update.AbstractUpdateColumns;
import info.archinnov.achilles.internals.dsl.query.update.AbstractUpdateEnd;
import info.archinnov.achilles.internals.dsl.query.update.AbstractUpdateFrom;
import info.archinnov.achilles.internals.dsl.query.update.AbstractUpdateWhere;
import info.archinnov.achilles.internals.entities.MultiClusteringEntity;
import info.archinnov.achilles.internals.metamodel.AbstractEntityProperty;
import info.archinnov.achilles.internals.options.CassandraOptions;
import info.archinnov.achilles.internals.runtime.RuntimeEngine;
import info.archinnov.achilles.type.SchemaNameProvider;
import info.archinnov.achilles.validation.Validator;
import java.lang.Class;
import java.lang.Long;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;

public final class MultiClusteringEntity_Update extends AbstractUpdate {
  protected final MultiClusteringEntity_AchillesMeta meta;

  protected final Class entityClass = MultiClusteringEntity.class;

  public MultiClusteringEntity_Update(RuntimeEngine rte, MultiClusteringEntity_AchillesMeta meta) {
    super(rte);
    this.meta = meta;
  }

  /**
   * Generate an UPDATE FROM ... */
  public final MultiClusteringEntity_Update.F fromBaseTable() {
    final String currentKeyspace = meta.getKeyspace().orElse("unknown_keyspace_for_" + meta.entityClass.getCanonicalName());
    final Update.Where where = QueryBuilder.update(currentKeyspace, meta.getTableOrViewName()).where();
    return new MultiClusteringEntity_Update.F(where, new CassandraOptions());
  }

  /**
   * Generate an UPDATE FROM ... using the given SchemaNameProvider */
  public final MultiClusteringEntity_Update.F from(final SchemaNameProvider schemaNameProvider) {
    final String currentKeyspace = lookupKeyspace(schemaNameProvider, meta.entityClass);
    final String currentTable = lookupTable(schemaNameProvider, meta.entityClass);
    final Update.Where where = QueryBuilder.update(currentKeyspace, currentTable).where();
    return new MultiClusteringEntity_Update.F(where, CassandraOptions.withSchemaNameProvider(schemaNameProvider));
  }

  public class Cols extends AbstractUpdateColumns {
    Cols(Update.Where where, CassandraOptions cassandraOptions) {
      super(where, cassandraOptions);
    }

    public final Cols.Value value() {
      return new Cols.Value();
    }

    public final MultiClusteringEntity_Update.W_Id where() {
      return new MultiClusteringEntity_Update.W_Id(where, cassandraOptions);
    }

    public final class Value {
      /**
       * Generate an UPDATE FROM ... SET value = ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.Cols Set(final String value) {
        where.with(NonEscapingSetAssignment.of("value", QueryBuilder.bindMarker("value")));
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        return MultiClusteringEntity_Update.Cols.this;
      }

      /**
       * Generate an UPDATE FROM ... SET value = fromJson(?) */
      public final MultiClusteringEntity_Update.Cols Set_FromJSON(final String value_element) {
        where.with(NonEscapingSetAssignment.of("value", QueryBuilder.fromJson(QueryBuilder.bindMarker("value"))));
        boundValues.add(value_element);
        encodedValues.add(value_element);
        return MultiClusteringEntity_Update.Cols.this;
      }
    }
  }

  public class F extends AbstractUpdateFrom {
    F(Update.Where where, CassandraOptions cassandraOptions) {
      super(where, cassandraOptions);
    }

    public final F.Value value() {
      return new F.Value();
    }

    public final class Value {
      /**
       * Generate an UPDATE FROM ... SET value = ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.Cols Set(final String value) {
        where.with(NonEscapingSetAssignment.of("value", QueryBuilder.bindMarker("value")));
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        return new MultiClusteringEntity_Update.Cols(where, cassandraOptions);
      }

      /**
       * Generate an UPDATE FROM ... SET value = fromJson(?) */
      public final MultiClusteringEntity_Update.Cols Set_FromJSON(final String value_element) {
        where.with(NonEscapingSetAssignment.of("value", QueryBuilder.fromJson(QueryBuilder.bindMarker("value"))));
        boundValues.add(value_element);
        encodedValues.add(value_element);
        return new MultiClusteringEntity_Update.Cols(where, cassandraOptions);
      }
    }
  }

  public final class W_Id extends AbstractUpdateWhere {
    public W_Id(Update.Where where, CassandraOptions cassandraOptions) {
      super(where, cassandraOptions);
    }

    public final MultiClusteringEntity_Update.W_Id.Relation id() {
      return new MultiClusteringEntity_Update.W_Id.Relation();
    }

    public final class Relation {
      /**
       * Generate a SELECT ... FROM ... WHERE ... id = ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.W_C1 Eq(Long id) {
        where.and(QueryBuilder.eq("id", QueryBuilder.bindMarker("id")));
        boundValues.add(id);
        encodedValues.add(meta.id.encodeFromJava(id, Optional.of(cassandraOptions)));
        return new MultiClusteringEntity_Update.W_C1(where, cassandraOptions);
      }

      /**
       * Generate a SELECT ... FROM ... WHERE ... id IN ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.W_C1 IN(Long... id) {
        Validator.validateTrue(ArrayUtils.isNotEmpty(id), "Varargs for field '%s' should not be null/empty", "id");
        where.and(QueryBuilder.in("id",QueryBuilder.bindMarker("id")));
        final List varargs = Arrays.asList((Object[])id);
        final List encodedVarargs = Arrays.stream((Long[])id).map(x -> meta.id.encodeFromJava(x, Optional.of(cassandraOptions))).collect(Collectors.toList());
        boundValues.add(varargs);
        encodedValues.add(encodedVarargs);
        return new MultiClusteringEntity_Update.W_C1(where, cassandraOptions);
      }

      /**
       * Generate a SELECT ... FROM ... WHERE ... id  = fromJson(?)  */
      public final MultiClusteringEntity_Update.W_C1 Eq_FromJson(String id) {
        where.and(QueryBuilder.eq("id", QueryBuilder.fromJson(QueryBuilder.bindMarker("id"))));
        boundValues.add(id);
        encodedValues.add(id);
        return new MultiClusteringEntity_Update.W_C1(where, cassandraOptions);
      }
    }
  }

  public final class W_C1 extends AbstractUpdateWhere {
    public W_C1(Update.Where where, CassandraOptions cassandraOptions) {
      super(where, cassandraOptions);
    }

    public final MultiClusteringEntity_Update.W_C1.Relation c1() {
      return new MultiClusteringEntity_Update.W_C1.Relation();
    }

    public final class Relation {
      /**
       * Generate a SELECT ... FROM ... WHERE ... c1 = ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.W_C2 Eq(int c1) {
        where.and(QueryBuilder.eq("c1", QueryBuilder.bindMarker("c1")));
        boundValues.add(c1);
        encodedValues.add(meta.c1.encodeFromJava(c1, Optional.of(cassandraOptions)));
        return new MultiClusteringEntity_Update.W_C2(where, cassandraOptions);
      }

      /**
       * Generate a SELECT ... FROM ... WHERE ... c1  = fromJson(?)  */
      public final MultiClusteringEntity_Update.W_C2 Eq_FromJson(String c1) {
        where.and(QueryBuilder.eq("c1", QueryBuilder.fromJson(QueryBuilder.bindMarker("c1"))));
        boundValues.add(c1);
        encodedValues.add(c1);
        return new MultiClusteringEntity_Update.W_C2(where, cassandraOptions);
      }

      /**
       * Generate a SELECT ... FROM ... WHERE ... c1 IN ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.W_C2 IN(int... c1) {
        Validator.validateTrue(ArrayUtils.isNotEmpty(c1), "Varargs for field '%s' should not be null/empty", "c1");
        where.and(QueryBuilder.in("c1",QueryBuilder.bindMarker("c1")));
        final List varargs = Arrays.asList((int[])c1);
        final List encodedVarargs = new ArrayList<>(c1.length);;
        for(int c1_element : c1) {
          encodedVarargs.add(meta.c1.encodeFromJava(c1_element, Optional.of(cassandraOptions)));
        }
        boundValues.add(varargs);
        encodedValues.add(encodedVarargs);
        return new MultiClusteringEntity_Update.W_C2(where, cassandraOptions);
      }
    }
  }

  public final class W_C2 extends AbstractUpdateWhere {
    public W_C2(Update.Where where, CassandraOptions cassandraOptions) {
      super(where, cassandraOptions);
    }

    public final MultiClusteringEntity_Update.W_C2.Relation c2() {
      return new MultiClusteringEntity_Update.W_C2.Relation();
    }

    public final class Relation {
      /**
       * Generate a SELECT ... FROM ... WHERE ... c2 = ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E Eq(int c2) {
        where.and(QueryBuilder.eq("c2", QueryBuilder.bindMarker("c2")));
        boundValues.add(c2);
        encodedValues.add(meta.c2.encodeFromJava(c2, Optional.of(cassandraOptions)));
        return new MultiClusteringEntity_Update.E(where, cassandraOptions);
      }

      /**
       * Generate a SELECT ... FROM ... WHERE ... c2  = fromJson(?)  */
      public final MultiClusteringEntity_Update.E Eq_FromJson(String c2) {
        where.and(QueryBuilder.eq("c2", QueryBuilder.fromJson(QueryBuilder.bindMarker("c2"))));
        boundValues.add(c2);
        encodedValues.add(c2);
        return new MultiClusteringEntity_Update.E(where, cassandraOptions);
      }

      /**
       * Generate a SELECT ... FROM ... WHERE ... c2 IN ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E IN(int... c2) {
        Validator.validateTrue(ArrayUtils.isNotEmpty(c2), "Varargs for field '%s' should not be null/empty", "c2");
        where.and(QueryBuilder.in("c2",QueryBuilder.bindMarker("c2")));
        final List varargs = Arrays.asList((int[])c2);
        final List encodedVarargs = new ArrayList<>(c2.length);;
        for(int c2_element : c2) {
          encodedVarargs.add(meta.c2.encodeFromJava(c2_element, Optional.of(cassandraOptions)));
        }
        boundValues.add(varargs);
        encodedValues.add(encodedVarargs);
        return new MultiClusteringEntity_Update.E(where, cassandraOptions);
      }
    }
  }

  public final class E extends AbstractUpdateEnd {
    public E(Update.Where where, CassandraOptions cassandraOptions) {
      super(where, cassandraOptions);
    }

    @Override
    protected final Class getEntityClass() {
      return entityClass;
    }

    @Override
    protected final AbstractEntityProperty getMetaInternal() {
      return meta;
    }

    @Override
    protected final RuntimeEngine getRte() {
      return rte;
    }

    @Override
    protected final CassandraOptions getOptions() {
      return cassandraOptions;
    }

    @Override
    protected final List getBoundValuesInternal() {
      return boundValues;
    }

    @Override
    protected final List getEncodedValuesInternal() {
      return encodedValues;
    }

    @Override
    protected final MultiClusteringEntity_Update.E getThis() {
      return this;
    }

    public final E.If_Value if_Value() {
      return new E.If_Value();
    }

    public final class If_Value {
      /**
       * Generate an ... IF value = ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E Eq(final String value) {
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        where.onlyIf(QueryBuilder.eq("value", QueryBuilder.bindMarker("value")));
        return MultiClusteringEntity_Update.E.this;
      }

      /**
       * Generate an ... IF value > ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E Gt(final String value) {
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        where.onlyIf(QueryBuilder.gt("value", QueryBuilder.bindMarker("value")));
        return MultiClusteringEntity_Update.E.this;
      }

      /**
       * Generate an ... IF value >= ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E Gte(final String value) {
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        where.onlyIf(QueryBuilder.gte("value", QueryBuilder.bindMarker("value")));
        return MultiClusteringEntity_Update.E.this;
      }

      /**
       * Generate an ... IF value < ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E Lt(final String value) {
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        where.onlyIf(QueryBuilder.lt("value", QueryBuilder.bindMarker("value")));
        return MultiClusteringEntity_Update.E.this;
      }

      /**
       * Generate an ... IF value <= ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E Lte(final String value) {
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        where.onlyIf(QueryBuilder.lte("value", QueryBuilder.bindMarker("value")));
        return MultiClusteringEntity_Update.E.this;
      }

      /**
       * Generate an  ... IF value != ? */
      @SuppressWarnings("static-access")
      public final MultiClusteringEntity_Update.E NotEq(final String value) {
        boundValues.add(value);
        encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions)));
        where.onlyIf(NotEq.of("value", QueryBuilder.bindMarker("value")));
        return MultiClusteringEntity_Update.E.this;
      }

      /**
       * Generate an ... IF value = fromJson(?) */
      public final MultiClusteringEntity_Update.E Eq_FromJSON(final String value) {
        boundValues.add(value);
        encodedValues.add(value);
        where.onlyIf(QueryBuilder.eq("value", QueryBuilder.fromJson(QueryBuilder.bindMarker("value"))));
        return MultiClusteringEntity_Update.E.this;
      }
    }
  }
}