Android Open Source - SORM Indexer






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.core;
//ww w . j  a v  a 2s .c o  m
import java.lang.reflect.Field;

import com.annotation.entity.Sqlable;
import com.annotation.utils.NameBuilder;
import com.annotation.utils.ReflectionUtils;
import com.annotation.utils.SqlUtils;
import com.annotation.utils._;

public class Indexer implements Sqlable {
  private String _indexName;
  private String _talbe;
  private boolean _unique = false;
  private StringBuffer _indexedColumns;// index name equals column name
  private String _expression = null;

  public Indexer() {
    _indexedColumns = new StringBuffer();
  }

  public Indexer unique(boolean isUnique) {
    _unique = isUnique;
    return this;
  }

  public Indexer from(Class<?> cls) {
    _talbe = ReflectionUtils.getTableName(cls);
    _indexName = NameBuilder.buildIndex(_talbe);
    Field[] fields = SqlUtils.getIndexField(cls);
    for (Field f : fields)  
        _indexedColumns.append(f.getName()).append(",");
    if (_indexedColumns.length() > 0)
      _indexedColumns.deleteCharAt(_indexedColumns.length() - 1);
    return this;
  }

  public Indexer where(String expression) {
    _expression = expression;
    return this;
  }

  @Override
  public String build() {
    if(_indexedColumns == null || _indexedColumns.length() == 0){
      return null;
    }
    StringBuffer builder = new StringBuffer();
    if (_unique) {
      builder.append("Create Unique Index ");
    } else {
      builder.append("Create Index ");
    }
    builder.append(_indexName).append(" on ").append(_talbe);
    builder.append(" (").append(_indexedColumns).append(") ");
    if (!_.isEmpty(_expression))
      builder.append(" Where ").append(_expression);
    return builder.toString();
  }

}




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