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

io.ebeaninternal.server.expression.ArrayContainsExpression Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebeaninternal.server.expression;

import io.ebeaninternal.api.BindValuesKey;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionBind;
import io.ebeaninternal.api.SpiExpressionRequest;

import java.io.IOException;

/**
 * Contains expression for ARRAY type.
 */
final class ArrayContainsExpression extends AbstractExpression {

  private final boolean contains;
  private final Object[] values;

  ArrayContainsExpression(String propName, boolean contains, Object... values) {
    super(propName);
    this.contains = contains;
    this.values = values;
    if (values == null || values.length == 0) {
      throw new IllegalArgumentException("values must not be null or empty");
    }
  }

  @Override
  public void queryPlanHash(StringBuilder builder) {
    builder.append("ArrayContains[").append(propName)
      .append(" b:").append(contains)
      .append(" ?:").append(values.length).append(']');
  }

  @Override
  public void queryBindKey(BindValuesKey key) {
    key.add(values.length);
    for (Object value : values) {
      key.add(value);
    }
  }

  @Override
  public boolean isSameByBind(SpiExpression other) {
    ArrayContainsExpression that = (ArrayContainsExpression) other;
    for (int i = 0; i < this.values.length; i++) {
      if (!this.values[i].equals(that.values[i])) {
        return false;
      }
    }
    return true;
  }

  @Override
  public void addSql(SpiExpressionRequest request) {
    request.platformHandler().arrayContains(request, propName, contains, values);
  }

  @Override
  public void addBindValues(SpiExpressionBind request) {
    for (Object value : values) {
      request.addBindValue(value);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy