Example of Db+record mode for jfinal

Source: Internet
Author: User
Tags connection pooling

Jfinal Plug-in configuration

//Configure plug-ins     Public voidConfigplugin (Plugins me) {//Configure database connection pooling plug-inC3p0plugin c3p0plugin1 =NewC3p0plugin ("URL","User name","Password");        Me.add (c3p0plugin1); //enable the Activerecordplugin pluginActiverecordplugin activeRecordPlugin1 =NewActiverecordplugin (c3p0plugin1); //Add a database dialectActiverecordplugin1.setdialect (Newansisqldialect ());        Me.add (activeRecordPlugin1); //mapping Formmodel tables to Formmodel modelsActiverecordplugin1.addmapping ("","", Formmodel.class); //Configuring the Ehcache pluginMe.add (NewEhcacheplugin ("Src/ehcache.xml")); }

Ehcache.xml

<?xml version= "1.0" encoding= "Utf-8"? ><ehcache xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:nonamespaceschemalocation= "Http://ehcache.org/ehcache.xsd" > <diskstore path= "java.io.tmpdir"/> <cache name= "Orgcodes" maxelement Sinmemory= "10000" eternal= "true"Overflowtodisk= "true" copyonread= "true" copyonwrite= "true"/> <cache name= "Activitys" maxelementsinmemory= "10000" eternal= " TrueOverflowtodisk= "true" copyonread= "true" copyonwrite= "true"/>
<!--
Cache configuration
Name: Cache names.
Maxelementsinmemory: Maximum number of caches.
Eternal: The object is permanently valid, but if set, timeout will not work.
Timetoidleseconds: Sets the allowable idle time (in seconds) for an object before it expires. An optional property is used only if the Eternal=false object is not permanently valid, and the default value is 0, which means that the idle time is infinite.
Timetoliveseconds: Sets the time (in seconds) that an object is allowed to survive before it expires. The maximum time is between the creation time and the expiration time. Used only when the Eternal=false object is not permanently valid, the default is 0, which means that the object survives indefinitely.
Overflowtodisk: When the number of objects in memory reaches Maxelementsinmemory, Ehcache writes the object to disk.
DISKSPOOLBUFFERSIZEMB: This parameter sets the buffer size of the Diskstore (disk cache). The default is 30MB. Each cache should have its own buffer.
Maxelementsondisk: Maximum number of hard disk caches.
Diskpersistent: Whether to cache VM Restart period data Whether The disk store persists between restarts of the virtual machine. The default value is False.
Diskexpirythreadintervalseconds: Disk failed thread run time interval, default is 120 seconds.
Memorystoreevictionpolicy: When the maxelementsinmemory limit is reached, Ehcache will clean up the memory according to the specified policy. The default policy is LRU (least recently used). You can set it to FIFO (first in, out) or LFU (less used).
Clearonflush: If the maximum amount of memory is cleared.
--></ehcache>
Formmodel.java
 Public class extends Formbean<formmodel> {    publicstaticfinalnew  Formmodel ( );}
Formbean.java
 Public Abstract classFormbean<mextendsFormbean<m>>extendsModel<m>Implementsibean{Private intgetId () {intid = getlong ("id"). Intvalue ();
Intvalue initializes the value of the acquired long type to type intreturnID; } Privatestring GetCode () {String Code= Getstr ("code"); returnCode; } PublicMap<string,object>GetData () {Map<String,Object> data =NewHashmap<>(); Data.put ("id", GetId ()); Data.put ("Code", GetCode ()); Data.put ("Field name", the Get method declared above); Waitreturndata; }}

Jfinal Original DB + Record mode example
Jfinal is equipped with the ActiveRecord plug-in, in addition to the implementation of similar rails Activerecrod functions, but also implemented a
DB + record mode, in which the developer can easily manipulate the database without even having to write the model.
The following is the sample code:

//Create a Record object with the Name property of the James,age property of 25 and add it to the databaseRecord user =NewRecord ().Set("name","James").Set(" Age", -);D B.save ("User", user);//Delete records from the user table with ID value 25Db.deletebyid ("User", -);//A record with a query ID value of 25 changes its Name property to James and updates to the databaseuser = Db.findbyid ("User", -).Set("name","James");D b.update ("User", user);//The Query ID value is 25 for user, and only the value of name and age two fields are takenuser = Db.findbyid ("User", -,"name, age");//gets the Name property of the userString userName = User.getstr ("name");//gets the age property of the userInteger userage = User.getint (" Age");//query for all user ages older than 18 and output their Name propertylist<record> users = Db.find ("SELECT * from user where age >");//paging query user age greater than 18, the current page number is 1, 10 user per pagepage<record> userpage = db.paginate (1,Ten,"SELECT *","From user where age >?", -);

This is my Baidu + self-integration

Example of Db+record mode for jfinal

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.