Android Open Source - AndroidModelView Sqlite Data Access






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   ww w .  jav a2 s .co  m*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class SqliteDataAccess implements DataAccess {
  private MySqliteHelper _helper;
  private SQLiteDatabase _database;
  public SqliteDataAccess(Context context) {
    _helper = new MySqliteHelper(context);
    _database = _helper.getWritableDatabase();
  }

  @Override
  public long save(String tableName, ContentValues values) {
    if(values.containsKey("id")&&values.getAsInteger("id")!=null){
      _database.update(tableName, values, "id="+values.getAsString("id"), null);
      return (long)values.getAsInteger("id");
    }      
    return _database.insert(tableName, null, values);
  }

  @Override
  public Cursor findAll(String tableName, Query condition) {
    return _database.query(condition.distinct, tableName, condition.getSelect(), condition.getWhere(), null, condition.getGroupBy(), condition.getHaving(), condition.getOrderBy(), condition.getLimit());    
  }

  @Override
  public int count(String tableName, Query condition) {
    String[] countCol = {" count(id) as count"};
    Cursor c = _database.query(condition.distinct, tableName, countCol, condition.getWhere(), null, condition.getGroupBy(), condition.getHaving(), condition.getOrderBy(), condition.getLimit());
    return c.getInt(0);
  }

  @Override
  public int countBySql(String tableName, String sql) {
    Query condition = new Query();
    condition.addWhere(sql);
    return count(tableName, condition);
  }

  @Override
  public int delete(String tableName, Query condition) {
    return _database.delete(tableName, condition.getWhere(),null);    
  }

  @Override
  public boolean exist(String tableName, Query condition) {
    Cursor c = _database.query(condition.distinct, tableName, condition.getSelect(), condition.getWhere(), null, condition.getGroupBy(), condition.getHaving(), condition.getOrderBy(), condition.getLimit());
    return c.getCount()>0;
  }

}




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