Using ormlite in Android for persistence (2)-detailed configuration of persistence classes

Source: Internet
Author: User

PreviousArticleOrmlite is simple to use, but I think ormlite is superior to the configuration design for fields, tables, and so on.

The following describes the class Configuration:

If the Android app we developed needs to retain user information, create a new class: useraccount

This class has six variables:

 
Private IntID;
PrivateString username;
PrivateString password;
PrivateDate regtime;
PrivateString tellphone;
PrivateString email;

Use eclipse to generate get and set methods:

 Public   Int GETID (){
Return ID;
}

Public Void Setid ( Int ID ){
This . ID = ID;
}

Public String GetUserName (){
Return Username;
}

Public Void Setusername (string username ){
This . Username = username;
}

Public String GetPassword (){
Return Password;
}

Public Void Setpassword (string password ){
This . Password = password;
}

Public Date getregtime (){
Return Regtime;
}

Public Void Setregtime (date regtime ){
This . Regtime = regtime;
}

Public String gettellphone (){
Return Tellphone;
}

Public Void Settellphone (string tellphone ){
This . Tellphone = tellphone;
}

Public String getemail (){
Return Email;
}

Public Void Setemail (string email ){
This . Email = Email;
}

The persistence parameters of the class are configured as follows:

1. Table Name:

 
@ Databasetable (tablename = "datatablename ")

If this parameter is not specified, the table name is the class name.

2. Fields

 
@ Databasefield

This can be configured with a lot of attributes.

2.1 primary key

 
@ Databasefield (ID = true)

2.2 column name

@ Databasefield (columnname = "columnname ")

If this parameter is not specified, it is the same as the variable name.

2.3 Data Type

 
@ Databasefield (datatype = datatype. integer)

In general, you do not need to specify this parameter. You can obtain this parameter based on the Java class.

2.4 Default Value

 
@ Databasefield (defaultvalue = "0 ")

2.5 Length

 
@ Databasefield (width = 13)

It is generally used for string type

2.6 empty

 
@ Databasefield (canbenull = false)

The default value is true.

2.7 self-growth?

 
@ Databasefield (generatedid = true)

This is relatively simple. Let's talk about the foreign key in the next article.

Related Article

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.