Ok, today read the Spring database component implementation of the source code, briefly take notes.
The first is the jdbctemplate, in fact, the implementation of this technology is very simple, is a template class, the execution of the backbone of the SQL process is written, such as connection acquisition, closure, abnormal capture, statement generation and so on, and the different parts of the exposure, Let the user customize, such as what statement do, the results to avabean mapping and so on.
Then there is the RDBMS, the bottom of which is also used JdbcTemplate. The functionality provided here is, I think, a way to provide an OO-oriented and reusable operation. The implementation is also very simple, save the SQL statement in the object, each time in execution, call the underlying jdbctemplate, the user passed in the parameters set to Preparestetement.
About connection and Preparestatement, looking at the bottom of the code, the implementation of JDBC, connection is to create a preparestatement cache, key is a question mark of the SQL statement, Because Preparestatement is more expensive to create than statement, caching is done here to reduce consumption. If the connection is turned off, its preparestatement will be lost, so look at the connection to close the time, actually did not really close, but to return it to the datasource.
Preparestatement than statement advantage, not much to say, today went to the Internet to check a bit.
The implementation of the ORM layer is to be explained later.
Implementation of spring-database operation component