Android Open Source - SORM Where Impl






From Project

Back to project page SORM.

License

The source code is released under:

MIT License

If you think the Android project SORM listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.annotation.entity;
//from   w  ww.  jav  a2s  .  c o m
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SuppressWarnings("unchecked")
public abstract class WhereImpl<T> implements Wherable<T> {

  private StringBuffer _where;

  public WhereImpl() {
    _where = new StringBuffer();
  }

  @Override
  public T where(String column, String operation, String value) {
    _where.append(column).append(" ");
    _where.append(operation).append(" ");
    _where.append("\"").append(value.replaceAll("\\\"", "\\\\\""))
        .append("\"").append(" ");
    return (T) this;
  }

  // ???????????????id = 1 ???: id = 1 and age=18
  @Override
  public T where(String expression) {
    Pattern p = Pattern.compile("(\\S+)\\s*([!<>=]+)\\s*(\\S+)");
    Matcher m = p.matcher(expression);
    if (m.matches()) {
      return where(m.group(1), m.group(2), m.group(3));
    }
    return (T) this;
  }

  @Override
  public T and() {
    _where.append("and").append(" ");
    return (T) this;
  }

  @Override
  public T or() {
    _where.append("or").append(" ");
    return (T) this;
  }

  public StringBuffer getWhere() {
    return this._where;
  }

  public boolean hasWhere() {
    return this._where.length() > 0;
  }
}




Java Source Code List

.Creator.java
com.annotation.Column.java
com.annotation.Ignore.java
com.annotation.Index.java
com.annotation.NoNull.java
com.annotation.Table.java
com.annotation.Unique.java
com.annotation.core.Deletor.java
com.annotation.core.Droper.java
com.annotation.core.Indexer.java
com.annotation.core.Inserter.java
com.annotation.core.Model.java
com.annotation.core.Query.java
com.annotation.core.Selector.java
com.annotation.core.Updater.java
com.annotation.entity.ColumnInfo.java
com.annotation.entity.ORMcallback.java
com.annotation.entity.QueryCallback.java
com.annotation.entity.Sqlable.java
com.annotation.entity.Wherable.java
com.annotation.entity.WhereImpl.java
com.annotation.utils.DBHelper.java
com.annotation.utils.DBUtils.java
com.annotation.utils.NameBuilder.java
com.annotation.utils.ReflectionUtils.java
com.annotation.utils.SqlUtils.java
com.annotation.utils._.java