Frame Address: https://github.com/yangfuhai/afinal
Corresponding Source:
net.tsz.afinal.annotation.sqlite.*
Net.tsz.afinal.db.sqlite.*
Net.tsz.afinal.db.table.*
net.tsz.afinal.utils. Classutils, Net.tsz.afinal.utils.FieldUtils
Finaldb
Build Library
FINALDB db = finaldb.create (context, "mytest.db", true);
There are entity beans
@Table (name = "user")//@Table represents the table name of the ORM (object-Relational mapping) public class User { private int id; private String name; private String Email; Private Date registerdate; Private Double money; Getter and setter cannot omit Oh///////////////public int getId () { return ID; } public void setId (int id) { this.id = ID; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; } Public String Getemail () { return email; } public void Setemail (String email) { This.email = email; } Public Date getregisterdate () { return registerdate; } public void Setregisterdate (Date registerdate) { this.registerdate = registerdate; } Public Double Getmoney () { return money; } public void Setmoney (Double money) { This.money = money; }}
Build table
Db.save (user);
Primary KEY annotations:
Must have a primary key. The default column name is ID and is self-increment. Use annotation @id (column= "Id")
There is no id attribute in the actual bean, use @id (column= "name") to make name a primary key, non-integer type, and not self-increment
attribute annotations
@Property (column= "uname"), map the property name to the Uname field in the table
Canceling an ORM annotation
@Transient indicates that a property is not mapped to a table
One-to-many relationships
@OneToMany (manycolumn= "ParentID")
Many-to-one relationship
@ManyToOne (column= "ParentID")
Finaldb onetomany Lazy Loading using the method:
Model definition:
Public class Parent{ Private int ID; @OneToMany(Manycolumn = "ParentID") Private Onetomanylazyloader<Parent , Child> Children; /*....*/} Public class Child{ Private int ID; Private String text; @ManyToOne(column = "ParentID") Private Parent Parent; /*....*/}
Use:
List<Parent> All = DB.FindAll(Parent.class); for( Parent Item : All){ if(Item.GetChildren ().getList().size() >0) Toast.Maketext( This,Item.GetText() + Item.GetChildren().getList().Get(0).GetText(),Toast.Length_long).Show(); }
Finaldb objects, there are many methods, crud and other operations. It's not listed.