Mybatis source code parsing (1) (June 11, 2015), mybatis 2015

Source: Internet
Author: User

Mybatis source code parsing (1) (June 11, 2015), mybatis 2015

I. Introduction

First, let's take a look at the source code structure of Mybatis. There are 19 packages in Mybatis3.2.7, and there may be fewer packages in other versions.

Public SqlSessionFactory build (Reader reader, String environment, Properties properties ){
SqlSessionFactory var5;
Try {
XMLConfigBuilder e = new XMLConfigBuilder (reader, environment, properties );
Var5 = this. build (Configuration) e. parse ());
} Catch (Exception var14 ){
Throw ExceptionFactory. wrapException ("Error building SqlSession.", var14 );
} Finally {
ErrorContext. instance (). reset ();

Try {
Reader. close ();
} Catch (IOException var13 ){
;
}

}

Return var5;
}

public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
SqlSessionFactory var5;
try {
XMLConfigBuilder e = new XMLConfigBuilder(inputStream, environment, properties);
var5 = this.build((Configuration)e.parse());
} catch (Exception var14) {
throw ExceptionFactory.wrapException("Error building SqlSession.", var14);
} finally {
ErrorContext.instance().reset();

try {
inputStream.close();
} catch (IOException var13) {
;
}

}

return var5;
}
public SqlSessionFactory build(Configuration config) {
return new DefaultSqlSessionFactory(config);
}

2. SqlSessionFactory

SqlSessionFactory is an interface. In fact, its implementation class defasqlsqlsessionfactory is actually working. As the name suggests, SqlSessionFactory is a factory class of SqlSession, and its function is to provide SqlSession externally, another function is to obtain the Configuration object.

public interface SqlSessionFactory {
SqlSession openSession();

SqlSession openSession(boolean var1);

SqlSession openSession(Connection var1);

SqlSession openSession(TransactionIsolationLevel var1);

SqlSession openSession(ExecutorType var1);

SqlSession openSession(ExecutorType var1, boolean var2);

SqlSession openSession(ExecutorType var1, TransactionIsolationLevel var2);

SqlSession openSession(ExecutorType var1, Connection var2);

Configuration getConfiguration();
}

Provides the method for obtaining SqlSession in Step 8. The parameters involved mainly include: Custom connection, transaction isolation level, ExecutorType (Statement type [Normal, preprocessing, batch processing ])

Note that the openSession method does not automatically submit a transaction by default.

3. SqlSession

SqlSession is also an interface. What actually works is its implementation class defasqlsqlsession, which is its class structure.

We can see that the role of SqlSession is mainly to provide some basic operations of the database.

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.