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

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

The newest version!
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.EntityWithIndexOnClustering_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.EntityWithIndexOnClustering;
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.Integer;
import java.lang.Long;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
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 EntityWithIndexOnClustering_Update extends AbstractUpdate {
  protected final EntityWithIndexOnClustering_AchillesMeta meta;

  protected final Class entityClass = EntityWithIndexOnClustering.class;

  public EntityWithIndexOnClustering_Update(RuntimeEngine rte, EntityWithIndexOnClustering_AchillesMeta meta) {
    super(rte);
    this.meta = meta;
  }

  /**
   * Generate an UPDATE FROM ... */
  public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.F(where, new CassandraOptions());
  }

  /**
   * Generate an UPDATE FROM ... using the given SchemaNameProvider */
  public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.W_Partition where() {
      return new EntityWithIndexOnClustering_Update.W_Partition(where, cassandraOptions);
    }

    public final class Value {
      /**
       * Generate an UPDATE FROM ... SET value = ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.Cols(where, cassandraOptions);
      }
    }
  }

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

    public final EntityWithIndexOnClustering_Update.W_Partition.Relation partition() {
      return new EntityWithIndexOnClustering_Update.W_Partition.Relation();
    }

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

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

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

    public final EntityWithIndexOnClustering_Update.W_Clustering.Relation clustering() {
      return new EntityWithIndexOnClustering_Update.W_Clustering.Relation();
    }

    public final class Relation {
      /**
       * Generate a SELECT ... FROM ... WHERE ... clustering = ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_Update.E Eq(Integer clustering) {
        where.and(QueryBuilder.eq("clustering", QueryBuilder.bindMarker("clustering")));
        boundValues.add(clustering);
        encodedValues.add(meta.clustering.encodeFromJava(clustering, Optional.of(cassandraOptions)));
        return new EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.E.this;
      }

      /**
       * Generate an ... IF value > ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.E.this;
      }

      /**
       * Generate an ... IF value >= ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.E.this;
      }

      /**
       * Generate an ... IF value < ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.E.this;
      }

      /**
       * Generate an ... IF value <= ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.E.this;
      }

      /**
       * Generate an  ... IF value != ? */
      @SuppressWarnings("static-access")
      public final EntityWithIndexOnClustering_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 EntityWithIndexOnClustering_Update.E.this;
      }
    }
  }
}