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

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

package info.archinnov.achilles.generated.dsl;

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.EntityWithSimplePartitionKey_AchillesMeta;
import info.archinnov.achilles.internals.entities.EntityWithSimplePartitionKey;
import info.archinnov.achilles.internals.metamodel.AbstractEntityProperty;
import info.archinnov.achilles.internals.options.Options;
import info.archinnov.achilles.internals.query.dsl.update.AbstractUpdate;
import info.archinnov.achilles.internals.query.dsl.update.AbstractUpdateColumns;
import info.archinnov.achilles.internals.query.dsl.update.AbstractUpdateEnd;
import info.archinnov.achilles.internals.query.dsl.update.AbstractUpdateFrom;
import info.archinnov.achilles.internals.query.dsl.update.AbstractUpdateWhere;
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.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;

public final class EntityWithSimplePartitionKey_Update extends AbstractUpdate {
  protected final EntityWithSimplePartitionKey_AchillesMeta meta;

  protected final Class entityClass = EntityWithSimplePartitionKey.class;

  public EntityWithSimplePartitionKey_Update(RuntimeEngine rte, EntityWithSimplePartitionKey_AchillesMeta meta) {
    super(rte);
    this.meta = meta;
  }

  /**
   * Generate an UPDATE FROM ... */
  public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateFrom 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 EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateFrom(where);
  }

  /**
   * Generate an UPDATE FROM ... using the given SchemaNameProvider */
  public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateFrom 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 EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateFrom(where);
  }

  public class EntityWithSimplePartitionKey_UpdateColumns extends AbstractUpdateColumns {
    EntityWithSimplePartitionKey_UpdateColumns(Update.Where where) {
      super(where);
    }

    /**
     * Generate an UPDATE FROM ... SET value = ? */
    @SuppressWarnings("static-access")
    public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateColumns value_Set(final String value) {
      where.with(QueryBuilder.set("value", QueryBuilder.bindMarker("value")));
      boundValues.add(value);
      encodedValues.add(meta.value.encodeFromJava(value));
      return this;
    }

    public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateWhere_Id where() {
      return new EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateWhere_Id(where);
    }
  }

  public class EntityWithSimplePartitionKey_UpdateFrom extends AbstractUpdateFrom {
    EntityWithSimplePartitionKey_UpdateFrom(Update.Where where) {
      super(where);
    }

    /**
     * Generate an UPDATE FROM ... SET value = ? */
    @SuppressWarnings("static-access")
    public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateColumns value_Set(final String value) {
      where.with(QueryBuilder.set("value", QueryBuilder.bindMarker("value")));
      boundValues.add(value);
      encodedValues.add(meta.value.encodeFromJava(value));
      return new EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateColumns(where);
    }
  }

  public final class EntityWithSimplePartitionKey_UpdateWhere_Id extends AbstractUpdateWhere {
    public EntityWithSimplePartitionKey_UpdateWhere_Id(Update.Where where) {
      super(where);
    }

    /**
     * Generate a SELECT ... FROM ... WHERE ... id = ? */
    @SuppressWarnings("static-access")
    public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateEnd id_Eq(Long id) {
      where.and(QueryBuilder.eq("id", QueryBuilder.bindMarker("id_Eq")));
      boundValues.add(id);
      encodedValues.add(meta.id.encodeFromJava(id));
      return new EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateEnd(where);
    }

    /**
     * Generate a SELECT ... FROM ... WHERE ... id IN ? */
    @SuppressWarnings("static-access")
    public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateEnd id_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)).collect(Collectors.toList());
      boundValues.add(varargs);
      encodedValues.add(encodedVarargs);
      return new EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateEnd(where);
    }
  }

  public final class EntityWithSimplePartitionKey_UpdateEnd extends AbstractUpdateEnd {
    public EntityWithSimplePartitionKey_UpdateEnd(Update.Where where) {
      super(where);
    }

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

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

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

    @Override
    protected final Options getOptions() {
      return options;
    }

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

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

    @Override
    protected final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateEnd getThis() {
      return this;
    }

    /**
     * Generate an ... IF value = ? */
    @SuppressWarnings("static-access")
    public final EntityWithSimplePartitionKey_Update.EntityWithSimplePartitionKey_UpdateEnd ifValue_Eq(final String value) {
      boundValues.add(value);
      encodedValues.add(meta.value.encodeFromJava(value));
      where.onlyIf(QueryBuilder.eq("value", QueryBuilder.bindMarker("value")));
      return this;
    }

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

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

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

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

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