Package org.nutz.dao.util.cri

Source Code of org.nutz.dao.util.cri.SimpleExpression

package org.nutz.dao.util.cri;

import org.nutz.dao.entity.Entity;
import org.nutz.dao.entity.MappingField;
import org.nutz.dao.jdbc.Jdbcs;
import org.nutz.dao.jdbc.ValueAdaptor;

public class SimpleExpression extends AbstractSqlExpression {

  private String op;
  private Object value;

  public SimpleExpression(String name, String op, Object val) {
    super(name);
    this.op = op;
    this.value = val;
  }

  public void joinSql(Entity<?> en, StringBuilder sb) {
    if (not)
      sb.append(" NOT ");
    sb.append(_fmtcol(en)).append(op).append('?');
  }

  public int joinAdaptor(Entity<?> en, ValueAdaptor[] adaptors, int off) {
    MappingField mf = _field(en);
    if (null != mf) {
      adaptors[off++] = mf.getAdaptor();
    } else {
      adaptors[off++] = Jdbcs.getAdaptorBy(value);
    }
    return off;
  }

  public int joinParams(Entity<?> en, Object obj, Object[] params, int off) {
    params[off++] = value;
    return off;
  }

  public int paramCount(Entity<?> en) {
    return 1;
  }

}
TOP

Related Classes of org.nutz.dao.util.cri.SimpleExpression

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.