Principles and usage of configuring ing using Java annotations in easydbo

Source: Internet
Author: User

We know that in the last beta version of easydbo, annotations are added to configure object and relational table ing. Some time ago, I saw how to configure the primary key attribute and primary key generator in the annotation. Because the default configuration is used in the development documentation, the following example is used in this document: ImportJava. Io. serializable;
ImportJava. util. date; ImportCom. easyjf. DBO. annotation .*;
@ Table (tablename = "message ")
Public ClassMessage ImplementsSerializable {
@ Tablefield (name = "CID ")
Private StringCID;
@ Tablefield (name = "title ")
PrivateString title1;
@ Tablefield (name = "content ")
PrivateString content1;
@ Tablefield (name = "inputuser ")
PrivateString inputuser;
@ Tablefield (name = "inputtime ")
PrivateDate inputtime;
@ Tablefield (name = "publish ")
PrivateBoolean publish1;
@ Tablefield (name = "status ")
PrivateInteger status1;
PublicString getcid (){
ReturnCID;
}
Public VoidSetcid (string CID ){
This. Cid = CID;
}
//...
// Other getter and setter Methods
} This section does not demonstrate how to configure the primary key attribute and generator. Let's take a look at the source code of the two tags @ table and @ tabelfield: Package COM. easyjf. DBO. annotation; import Java. lang. annotation. retention;
Import java. Lang. annotation. retentionpolicy;
/**
* Labels used to define the table structure
* @ Author Daxia
*
*/
@ Retention (retentionpolicy. runtime)
Public @ interface table {
/**
* Table Name
* @ Return
*/
String tablename ();
/**
* Table Primary Key
* @ Return
*/
String keyfield () Default "CID ";
/**
* Primary key value Generator
* @ Return
*/
String keygenerator () Default "com. easyjf. DBO. randomidgenerator ";
 
} As can be seen from the source code, @ table has three attributes, tablename is used to define the table name, keyfield is used to define the primary key attribute, and keygenerator is used to define the primary key generator. Keyfield and keygenerator have a default value. Because the default value is used in the previous message class definition, keyfield and keygenerator are not used. To customize your default value, you can write it as follows: @ table (tablename = "message", keyfield = "ID", keygenerator = "com. easyjf. DBO. nul1_generator ")
Public ClassMessage ImplementsSerializable {...} Let's take a look at the source file @ tablefield: Package com. easyjf. DBO. annotation; import java. Lang. annotation. retention;
Import java. Lang. annotation. retentionpolicy;
/**
* Tags used to define table fields
* @ Author Daxia
*
*/
@ Retention (retentionpolicy. runtime)
Public @ interface tablefield
{
Public string name ();
Boolean lazy () default false;
Boolean unique () default false;
} Because lazy and unique have been given the default values, we can see that only the examples corresponding to the attributes are defined in the example. @ Tablefield only defines common attributes, and also has attributes such as onetoone, manytoone, and manytoquota. For details, see easydbo development documentation. Http://www.easyjf.com/easydbo/devguide.htm In addition, the annotation configuration should also be added to some of the more suitable content in the official version, easydbo will also make some adjustments, please pay attention!

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.