Android afinal Framework Learning (i) FINALDB database operations

Source: Internet
Author: User

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.


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.