Examples of database operation object-oriented model in Spring jdbc, springjdbc

Source: Internet
Author: User

Examples of database operation object-oriented model in Spring jdbc, springjdbc

Detailed description of instances of the object-oriented model for database operations in Spring jdbc

Object-oriented Spring Jdbc database operations

An object model that is thread-safe and reusable is implemented using the object-oriented method to represent relational database operations. Its top-level parent interface RdbmsOperation.

SqlOperation inherits this interface to implement database operations such as select, update, and call.

1. query interface: SqlQuery

1) GenericSqlQuery, UpdatableSqlQuery, MappingSqlQueryWithParameter

2) SqlUpdate, BatchSqlUpdate

3) SqlCall

1) encapsulate the select statement for database operations as an object, and the base class of the query operation is SqlQuery. This class can be used for all queries, spring JDBC also provides some easier-to-use MappingSqlQueryWithParameters and MappingSqlQuery to map the result set to a Java object. The query object class also provides two extension UpdatableSqlQuery and SqlFunction;

2) add, delete, modify, and encapsulate insert, update, and delete operations in the database as objects. The base class for addition, deletion, and modification is SqlUpdate. Of course, BatchSqlUpdate is also provided for batch processing;

3) stored procedures and function calls are encapsulated as objects, and the base class is the SqlCall class, which provides StoredProcedure implementation.

Database Connection

JDBC:

Spring jdbc controls database connections through DataSource and obtains them through its sub-classes.

1) DriverManagerDataSource: A simple encapsulation of DriverManager. getConnection ()

2) SingleConnectionDataSource: encapsulates a link internally and cannot be used with multiple threads. It is used for testing.

3) lazyconnectionceceproxy: encapsulate DataSource, which is used to obtain database connections in a delayed manner. The connection is obtained only when Statement is created, therefore, in the actual project, the proxy is used to wrap the original DataSource so that it can be obtained only when a connection is required.

Vendor:

The DataSource implementations are C3P0, Proxool, DBCP, and so on, all of which have the database connection pool capability.

DataSourceUtils: the Spring JDBC abstraction framework uses its getConnection (DataSource dataSource) method to obtain database connections. releaseConnection (Connection con, DataSource dataSource) is used to release database connections, dataSourceUtils is used to support Spring transaction management. Only connections obtained using DataSourceUtils can have Spring transaction management.

Spring JDBC provides consistent database access through the DaoSupport abstract class.

1) JdbcDaoSupport: support consistent JdbcTemplate access

2) NamedParameterJdbcDaoSupport: a subclass of JdbcDaoSupport that provides access to NamedParameterJdbcTemplate

3) SimpleJdbcDaoSupport: a subclass of JdbcDaoSupport, which provides SimpleJdbcTemplate access.

Since the JdbcTemplate, NamedParameterJdbcTemplate, and SimpleJdbcTemplate classes use DataSourceUtils to obtain and release connections, and the connections are bound to threads, these JDBC template classes are thread-safe, that is, JdbcTemplate objects can be reused in multiple threads.

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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.