Jfinal Beijing-Racing website source code Building Research core Components Plugin

Source: Internet
Author: User
Tags connection pooling

Compared to the Beijing-racing site source code built in other core components, jfinal to plugin processing is quite concise. This is reflected in the definition of the core interface IPlugin of the plugin component.

    1. Defined

/**

    • IPlugin
      */
      Public interface IPlugin {
      Boolean start ();
      Boolean stop ();
      }

      1
      2
      3
      4
      5
      6
      7

      For plugin,jfinal to give enough status--top packagecom.jfinal.plugin.
      One thing to note is that in the plugin mechanism, jfinal is only responsible for the start and stop of the plugin, the concrete implementation logic, and the plugin application is completely left to the outside world to decide.
      In addition, observing the Com.jfinal.plugin package structure can also detect the jfinal of plugin and the way of design. And from the package structure can also be seen, the general project is basically a few needs. (where Auth has not yet been completed, the idea should be to build a custom session).
      Package structure

    1. Inheritance Chain

After reading the definition, next we look at the plugin inheritance chain system according to the previous habit.
Inheritance Chain
3.1 Activerecordplugin

As one of the core components of the Jfinal ActiveRecord is the start of this plugin, the importance of self-evident.

public boolean start () {
if (isstarted) {
return true;
}
Configure the data source
if (Config.datasource = = NULL && Datasourceprovider! = null) {
Config.datasource = Datasourceprovider.getdatasource ();
}
if (Config.datasource = = null) {
throw new RuntimeException ("ActiveRecord start error:activerecordplugin need DataSource or datasourceprovider");
}
Parsing the SQL Management module joined by Jfinal 3.0
Config.sqlKit.parseSqlTemplate ();
Build the mapping of model between class and table
New Tablebuilder (). Build (tablelist, config);
Dbkit.addconfig (config);
IsStarted = true;
Returns true to inform Jfinal that the plugin started successfully
return true;
}

1234567891011121314151617181920

3.2 C3p0plugin/druidplugin/hikaricpplugin

These three plugin are database connection pooling tools. The core logic is the construction of the DataSource instance.
3.3 Ehcacheplugin/redisplugin

Cache implementations.
3.3 Cron4jplugin

Timed task implementation. The official documents on this category have detailed instructions for use, and users are not using Baidu.

    1. Life cycle

Finally, let's see how plugin fits into the life cycle of jfinal.
4.1 Start

Jfinalfilter.init

> Jfinal.init
> config.configjfinal (jfinalconfig)
> Config.configpluginwithorder (1, jfinalconfig);
> Config.startplugins (); The jfinal will start plugin before a different jfinalconfig.configxxxx, depending on the user configuration (Constants.setconfigpluginorder ()). 】

12345

4.2 Stop

Jfinalfilter.destroy

> Jfinal.stopplugins ()

12
    1. Summarize

Jfinal at the framework level for plugin processing, only responsible for callback plugin start and stop, specific implementation logic, as well as the plugin application is completely left to the outside world to complete.

Very few mandatory contracts, giving plugin a very strong flexibility to meet custom requirements on a variety of projects.

Jfinal Beijing-Racing website source code Building Research core Components plugin

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.