Android Open Source - AndroidModelView Query






From Project

Back to project page AndroidModelView.

License

The source code is released under:

MIT License

If you think the Android project AndroidModelView 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.khar.isframework;
//from   w w  w. ja  va2  s .  c  o m
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * build criteria for querying
 * @author kharisma
 *
 */
public class Query {
  String whereClause;
  String onClause;
  String selectClause;
  boolean distinct = false;
  String groupClause;
  String limitClause;
  String havingClause;
  String orderClause;
  Map<String,String> joinedTable;
  public Query(){
    joinedTable = new HashMap<String, String>();
  }
  public void addWhere(String query){
    if(whereClause==null)
    whereClause = query;
    else
      whereClause+=" and "+query;
  }
  public void addWhere(Map<String,String> attr){
    String tambahan = "(";
    Set<Entry<String,String>> j = attr.entrySet();
    Iterator<Entry<String,String>> iter1=j.iterator();
    while(iter1.hasNext()){
      Entry<String,String> e2 = iter1.next();
      tambahan+=e2.getKey()+"="+e2.getValue()+" ";
      if(iter1.hasNext())
        tambahan+=" and ";
    }
    tambahan +=")";
    if(whereClause==null){
      whereClause = tambahan;
    }
    else{
      whereClause += " and "+whereClause;
    }
  }

  /**
   * 
   * @param with string to string map with key is table name and value is join condition
   */
  public void addJoinedTable(Map<String,String> with){
    joinedTable.putAll(with);
  }
  
  public void addJoinedTable(String tableName,String joinCondition){
    joinedTable.put(tableName, joinCondition);
  }
  /**
   * 
   * @param select comma separated select condition
   */
  public void addSelect(String select){
    if(selectClause==null)
      selectClause = select;
    else
      selectClause+=select;
  }
  public void addSelect(List<String> cols){
    if(selectClause==null)
      selectClause = "";
    
    Iterator<String> it = cols.iterator();
    while(it.hasNext()){
      if(!selectClause.equals("")){
        selectClause+=",";
      }
      String j = it.next();
      selectClause += j;
    }
  }
  public void addSelect(String[] sh){
    if(selectClause==null)
      selectClause = "";
    int it = 0;
    while(it<sh.length){
      if(!selectClause.equals("")){
        selectClause+=",";
      }
      String j = sh[it];
      selectClause += j;
      it++;
    }
  }
  public void setGroupBy(String s){
    groupClause = s;
  }
  public void setHaving(String s){
    havingClause = s;
  }
  public String getHaving(){
    return havingClause;
  }
  public void setOrderBy(String s){
    orderClause = s;
  }
  public String getOrderBy() {
    return orderClause;
  }
  public void setLimit(String s){
    limitClause = s;
  }
  public String getLimit(){
    return limitClause;
  }
  public String getGroupBy(){
    return groupClause;
  }
  public String[] getSelect(){
    if(selectClause!=null && !selectClause.isEmpty()){
      String[] k = selectClause.split(",");
      return k;
    }
    else return null;
  
  }
  public void setDistinct(boolean dis){
    distinct = dis;
  }
  public String getWhere(){
    return whereClause;
  }
  public boolean getDistinct(){
    return distinct;
  }

}




Java Source Code List

com.khar.isframework.DataAccess.java
com.khar.isframework.FlexibleModel.java
com.khar.isframework.ModelAdapter.java
com.khar.isframework.ModelListFragment.java
com.khar.isframework.Model.java
com.khar.isframework.MySqliteHelper.java
com.khar.isframework.Query.java
com.khar.isframework.SqliteDataAccess.java
com.khar.isframework.formbuilder.BasicTheme.java
com.khar.isframework.formbuilder.FormBuilder.java
com.khar.isframework.formbuilder.Theme.java
com.khar.isframework.models.ibu.IbuListFragment.java
com.khar.isframework.models.ibu.Ibu.java
com.khar.isframework.models.rs.RSDetailFragment.java
com.khar.isframework.models.rs.RSListFragment.java
com.khar.isframework.models.rs.RumahSakit.java
com.khar.isframework.validator.BasicValidator.java
com.khar.isframework.validator.DateValidator.java
com.khar.isframework.validator.Validator.java
com.kharcustom.testframework.DummyDetailActivity.java
com.kharcustom.testframework.DummyDetailFragment.java
com.kharcustom.testframework.DummyEditForm.java
com.kharcustom.testframework.EmptyDetilFragment.java
com.kharcustom.testframework.FormTester.java
com.kharcustom.testframework.GenericForm.java
com.kharcustom.testframework.IbuDetailActivity.java
com.kharcustom.testframework.IbuDetailFragment.java
com.kharcustom.testframework.IbuListActivity.java
com.kharcustom.testframework.ModuleMenuHandler.java
com.kharcustom.testframework.dummy.DummyContent.java