Android Ultra-Lightweight ORM Framework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.