标签:事务 性能测试 orm sqliteorm sqlite
import android.annotation.SuppressLint;
//依赖注入配置
@SuppressLint("UseValueOf")
public class Entity {
/**
* 默认主键,自增。最好有id主键,便于debug和逻辑判断。
*
* 暂不支持自定义主键
*/
int id;
public boolean base_boolean;
public double base_double;
public float base_float;
public int base_int;
public long base_long;
public Boolean mBoolean;
public Double mDouble;
public Float mFloat;
public Integer mInteger;
public Long mLong;
public String mString;
}private DB db= DB.getInstance(mContext);
//依赖注入
@SuppressLint("UseValueOf")
Entity entity = new Entity();
entity.base_boolean = true;
entity.base_double = 10.2;
entity.base_float = 9.1f;
entity.base_int = 99;
entity.base_long = System.currentTimeMillis();
entity.mBoolean = new Boolean(true);
entity.mDouble = new Double(10.2);
entity.mFloat = new Float(9.1);
entity.mInteger = new Integer(99);
entity.mLong = new Long(System.currentTimeMillis() / 1000);
entity.mString = new String("test");
db.save(entity);
List<Entity> list = db.findAll(Entity.class);
if (list != null && list.size() > 0) {
Entity entity = list.get(0);
db.delete(entity);
}//删除所有 // db.deleteAll(Entity.class);
//按条件删除 // db.deleteByWhere(Entity.class, "");
List<Entity> list = db.findAll(Entity.class);
if (list.size() > 0) {
<span style="white-space:pre"> </span>Entity entity = list.get(0);
entity.base_int = 23482374;<span style="white-space:pre"> </span>//按条件更新 // db.update(Entity, "id=1"); db.update(entity); }
List<Entity> list = db.findAll(Entity.class); //条件查询 //db.findAllByWhere(Entity.class, "id=1");
db.dropTable(Entity.class);
// 开始事务。提高效率(不用事务,插入1000条数据可能要十几秒,用事务可能不到1秒,具体要看类是否复制) db.beginTrancation();
<span style="white-space:pre"> </span>for (int i = 0; i < 1000; i++) {
db.save(entity);
}<span style="white-space:pre"> </span>db.endTrancation();
标签:事务 性能测试 orm sqliteorm sqlite
原文地址:http://blog.csdn.net/yy1300326388/article/details/43449271