First, test performance demoFirst give you a performance test demo to see how the performance.demo.apk
Second, related operation Crudentity:
Import android.annotation.suppresslint;//Dependency Injection configuration @suppresslint ("usevalueof") public class Entity {/** * default primary key, self-increment. It is best to have the ID primary key, which facilitates debug and logic judgment. * * No support for custom primary key */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;}
INITDb:
Private DB db= db.getinstance (mcontext);
Dependency Injection
@SuppressLint ("usevalueof")
1. Increase:
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 ( Entity.mfloat = new Float (9.1), Entity.minteger = new Integer (10.2); Entity.mlong = new Long (system.currenttimemillis entity.mstring = new String ("test");d B.save (entity);
2. Delete
list<entity> list = Db.findall (Entity.class), if (list! = null && list.size () > 0) {Entity entity = LIST.G ET (0);d B.delete (entity);}
Delete all//Db.deleteall (Entity.class);
Conditionally Delete//Db.deletebywhere (Entity.class, "");
3. Update
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>//conditionally Updated//db.update (Entity, "id=1");d b.update (entity);}
4. Enquiry
list<entity> list = Db.findall (Entity.class);//Condition Query//db.findallbywhere (entity.class, "id=1");
5. Delete a table
Db.droptable (Entity.class);
6. Add 1000 data, add transaction
Begins a transaction. Improve efficiency (no transactions, insert 1000 data may take more than 10 seconds, with transactions may be less than 1 seconds, depending on whether the class is copied) db.begintrancation ();
<span style= "White-space:pre" ></span>for (int i = 0; i <; i++) {Db.save (entity);}
<span style= "White-space:pre" ></span>db.endtrancation ();
Demo: Source code and JAR package: Http://pan.baidu.com/s/1gd7ZRTh
Android Ultra-Lightweight ORM Framework