The use and principle analysis of mapper mapping configuration in MyBatis Framework (iii) configuration

Source: Internet
Author: User

The use and principle analysis of mapper mapping configuration in the above <mybatis Framework (ii) configuration Chapter Sqlsessionfactorybuilder,xmlconfigbuilder> We know that Xmlconfigbuilder calls the parse () method to parse the MyBatis configuration file and generate the Config object.

The configuration class is mainly used to store the MyBatis and mapper file parsing data, the configuration object will run through the entire MyBatis execution process, to provide the necessary information for the execution of MyBatis.

Let's take a look at the member variables and construction methods of the configuration class:

 Packageorg.apache.ibatis.session; Public classConfiguration {protectedenvironment environment; protected Booleansaferowboundsenabled =false; Whether to enable inline nested statements in rowsprotected Booleansaferesulthandlerenabled =true; protected BooleanMapunderscoretocamelcase =false;//whether to enable database table fields A_column automatically map to the camel named properties in the Java class
  //When the object uses lazy loading, the property's load depends on those deferred attributes that can  be referenced, otherwise the protectedbooleantrueis loaded on demand;   protected Boolean true ;//Whether to allow single SQL to return multiple datasets (depending on driver compatibility)
Allows JDBC to generate a primary key. Drive support is required. If set to true, this setting enforces the generated primary key, and some drives are incompatible but can still be executed
protected Boolean false ;
//Use column labels instead of column names. Different drivers will behave differently in this regard, depending on the driver documentation or by testing these two different patterns to see the results of the drives usedprotected BooleanUsecolumnlabel =true;
Configuring the global cache switchprotected Booleancacheenabled =true;
The setter is also called when NULL is used to return the map,3.2 version above availableprotected BooleanCallsettersonnulls =false;
Global configuration Print all of the SQL prefixesprotectedString Logprefix;
Specifies the specific implementation of the log used by MyBatis, which is automatically found when unspecifiedprotectedClass <?extendsLog>Logimpl;
Set the local cache scope, session: There will be data sharing, statement: statement scope, so there is no data sharingprotectedLocalcachescope Localcachescope =localcachescope.session;
When set but the JDBC type is empty, some drivers specify valuesprotectedJdbctype Jdbctypefornull =Jdbctype.other;
To set the method for lazy loadingprotectedSet<string> Lazyloadtriggermethods =NewHashset<string> (Arrays.aslist (NewString[] {"Equals", "clone", "Hashcode", "toString" })); protectedInteger defaultstatementtimeout;//Set Wait data response timeout number
protectedExecutortype Defaultexecutortype =executortype.simple;//execution type with simple, resue, and batch
Specifies how MyBatis automatically maps the columns of the Data base table NONE: insinuate Partial: Partial full: AllprotectedAutomappingbehavior Automappingbehavior =automappingbehavior.partial;

Global Property Configuration Object
protected Properties variables = new properties ();

//Object creation factory, default implementation class Defaultobjectfactory, used to create objects, such as incoming List.class, to return instances of ArrayList with reflectionprotectedObjectfactory objectfactory =Newdefaultobjectfactory ();
Object Wrapper factory, default implementation class is Defaultobjectwrapperfactory, wrapping object instanceprotectedObjectwrapperfactory objectwrapperfactory =Newdefaultobjectwrapperfactory ();
Register MapperprotectedMapperregistry Mapperregistry =NewMapperregistry ( This); protected Booleanlazyloadingenabled =false;//whether to use lazy to load the associated object
Specifies the proxy tool used by Mybatis to create objects with lazy loading capabilityprotectedproxyfactory proxyfactory; Database type IDprotectedString databaseId;

/**
* Configuration factory class.
* Used to create Configuration for loading deserialized unread properties.
*
* @see <a href= ' https://code.google.com/p/mybatis/issues/detail?id=300 ' >issue 300</a> (google code)
*/
protected class<?> configurationfactory;

//Interceptor chainprotected FinalInterceptorchain Interceptorchain =NewInterceptorchain ();
Typehandler Registrationprotected FinalTypehandlerregistry Typehandlerregistry =NewTypehandlerregistry ();
Aliases and specific class registrationsprotected FinalTypealiasregistry Typealiasregistry =NewTypealiasregistry ();
This is the driver of the specified parsing, such as you can use the Velocity template engine to replace the XML file, which is xmllanguagedriver by default, that is, using an XML file to write SQL statementsprotected FinalLanguagedriverregistry Languageregistry =NewLanguagedriverregistry ();
Corresponds to the statement configured in the Mapper.xmlprotected Finalmap<string, mappedstatement> mappedstatements =NewStrictmap<mappedstatement> ("Mapped statements Collection");
Corresponds to the cache configured in the Mapper.xmlprotected FinalMap<string, cache> caches =NewStrictmap<cache> ("Caches Collection");
corresponding to the Resultmap in Mapper.xml .protected Finalmap<string, resultmap> resultmaps =NewStrictmap<resultmap> ("Result Maps Collection");
corresponding to the Parametermap in Mapper.xml .protected Finalmap<string, parametermap> parametermaps =NewStrictmap<parametermap> ("Parameter Maps Collection");
Primary Key Generatorprotected Finalmap<string, keygenerator> keygenerators =NewStrictmap<keygenerator> ("Key Generators Collection"); protected FinalSet<string> loadedresources =NewHashset<string>(); protected Finalmap<string, xnode> sqlfragments =NewStrictmap<xnode> ("XML fragments parsed from previous mappers"); protected FinalCollection<xmlstatementbuilder> incompletestatements =NewLinkedlist<xmlstatementbuilder>(); protected FinalCollection<cacherefresolver> incompletecacherefs =NewLinkedlist<cacherefresolver>(); protected FinalCollection<resultmapresolver> Incompleteresultmaps =NewLinkedlist<resultmapresolver>(); protected FinalCollection<methodresolver> Incompletemethods =NewLinkedlist<methodresolver>();

   /*
     * A map holds cache-ref relationship. The key is the namespace,
     * references a cache bound to another namespace and the value is the
     * namespace which the actual cache is bound to.
     */
    protected final map<string, string> cacherefmap = new hashmap<string, String> ( );

Public thethis. Environment = public  Configuration () {
    Registering aliases for some classes by using Typealiasregistry
Typealiasregistry.registeralias ("JDBC", jdbctransactionfactory.class); Typealiasregistry.registeralias ("MANAGED", managedtransactionfactory.class); Typealiasregistry.registeralias ("JNDI", jndidatasourcefactory.class); Typealiasregistry.registeralias ("Pooled", pooleddatasourcefactory.class); Typealiasregistry.registeralias ("Unpooled", unpooleddatasourcefactory.class); Typealiasregistry.registeralias ("Perpetual", Perpetualcache.class); Typealiasregistry.registeralias ("FIFO", Fifocache.class); Typealiasregistry.registeralias ("LRU", LruCache.class); Typealiasregistry.registeralias ("SOFT", Softcache.class); Typealiasregistry.registeralias ("WEAK", Weakcache.class); Typealiasregistry.registeralias ("Db_vendor", Vendordatabaseidprovider.class); Typealiasregistry.registeralias ("XML", Xmllanguagedriver.class); Typealiasregistry.registeralias ("RAW", Rawlanguagedriver.class); Typealiasregistry.registeralias ("Slf4j", Slf4jimpl.class); Typealiasregistry.registeralias ("Commons_logging", Jakartacommonsloggingimpl.class); Typealiasregistry.registeralias ("Log4j", Log4jimpl.class); Typealiasregistry.registeralias ("Log4j2", Log4j2impl.class); Typealiasregistry.registeralias ("Jdk_logging", Jdk14loggingimpl.class); Typealiasregistry.registeralias ("Stdout_logging", Stdoutimpl.class); Typealiasregistry.registeralias ("No_logging", Nologgingimpl.class); Typealiasregistry.registeralias ("CGLIB", cglibproxyfactory.class); Typealiasregistry.registeralias ("JAVASSIST", javassistproxyfactory.class); Languageregistry.setdefaultdriverclass (xmllanguagedriver.class); Languageregistry.register (rawlanguagedriver.class); }   }

Later we will combine xmlconfigbuilder,configuration to explain the mapper.xml of the elements of the analysis.

The use and principle analysis of mapper mapping configuration in MyBatis Framework (iii) configuration

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.