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

info.archinnov.achilles.generated.function.SystemFunctions Maven / Gradle / Ivy

package info.archinnov.achilles.generated.function;

import com.datastax.driver.core.querybuilder.QueryBuilder;
import info.archinnov.achilles.internals.metamodel.functions.FunctionCall;
import info.archinnov.achilles.validation.Validator;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * This class is the common registry for all system functions */
public final class SystemFunctions {
  /**
   * Call "token" function with given parameters */
  @SuppressWarnings("rawtypes")
  public static final  Long_Type token(final T input) {
    final List params = new ArrayList<>();
    Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'token' function, it does not accept function call as argument, only simple column");
    Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'token' function, it does not accept literal value as argument, only simple column");
    params.add(QueryBuilder.column((String)input.getValue()));
    return new Long_Type(Optional.empty()) {
      @Override
      public boolean isFunctionCall() {
        return true;
      }

      @Override
      public String functionName() {
        return "token";
      }

      @Override
      public List parameters() {
        return params;
      }
    };
  }

  /**
   * Call "writetime" function with given parameters */
  @SuppressWarnings("rawtypes")
  public static final  Long_Type writetime(final T input) {
    final List params = new ArrayList<>();
    Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'writetime' function, it does not accept function call as argument, only simple column");
    Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'writetime' function, it does not accept literal value as argument, only simple column");
    params.add(QueryBuilder.column((String)input.getValue()));
    return new Long_Type(Optional.empty()) {
      @Override
      public boolean isFunctionCall() {
        return true;
      }

      @Override
      public String functionName() {
        return "writetime";
      }

      @Override
      public List parameters() {
        return params;
      }
    };
  }

  /**
   * Call "countNotNull" function with given parameters */
  @SuppressWarnings("rawtypes")
  public static final  Long_Type countNotNull(final T input) {
    final List params = new ArrayList<>();
    Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'countNotNull' function, it does not accept function call as argument, only simple column");
    Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'countNotNull' function, it does not accept literal value as argument, only simple column");
    params.add(QueryBuilder.column((String)input.getValue()));
    return new Long_Type(Optional.empty()) {
      @Override
      public boolean isFunctionCall() {
        return true;
      }

      @Override
      public String functionName() {
        return "count";
      }

      @Override
      public List parameters() {
        return params;
      }
    };
  }

  /**
   * Call "countNotNull" function with given parameters */
  @SuppressWarnings("rawtypes")
  public static final  Integer_Type ttl(final T input) {
    final List params = new ArrayList<>();
    Validator.validateFalse(input.isFunctionCall(), "Invalid argument for 'ttl' function, it does not accept function call as argument, only simple column");
    Validator.validateFalse(input.hasLiteralValue(), "Invalid argument for 'ttl' function, it does not accept literal value as argument, only simple column");
    params.add(QueryBuilder.column((String)input.getValue()));
    return new Integer_Type(Optional.empty()) {
      @Override
      public boolean isFunctionCall() {
        return true;
      }

      @Override
      public String functionName() {
        return "ttl";
      }

      @Override
      public List parameters() {
        return params;
      }
    };
  }
}