Detailed example of database operation object model in Spring jdbc

Detailed example of database operation object model in Spring jdbc

Detailed example of database operation object model in Spring jdbc

Spring Jdbc database operation objectification

Use object-oriented methods to represent relational database operations and implement a thread-safe and reusable object model. Its top-level parent class interface is 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 database operation select as an object. The base class of the query operation is SqlQuery. All queries can be represented by this class. Spring JDBC also provides some easier-to-use MappingSqlQueryWithParameters and MappingSqlQuery for mapping result sets to Java objects. The query object class also provides two extensions, UpdatableSqlQuery and SqlFunction.

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

3) Stored procedure and function calls are encapsulated as objects. The base class is the SqlCall class, which provides a StoredProcedure implementation.

Database Connection

JDBC:

Spring jdbc controls the database connection through DataSource, that is, it is obtained through its implementation subclass.

1) DriverManagerDataSource: Simple encapsulation of DriverManager.getConnection()

2) SingleConnectionDataSource: encapsulates a connection internally, will not be closed and cannot be used by multiple threads, used for testing

3) LazyConnectionDataSourceProxy: Encapsulates DataSource and is used to delay the acquisition of database connections. The connection is only obtained when a Statement is actually created. Therefore, in actual projects, the proxy is finally used to wrap the original DataSource so that the connection is only obtained when it is really needed.

Vendor:

The DataSource implementations provided mainly include C3P0/Proxool/DBCP/, etc. These implementations all have database connection pool capabilities.

DataSourceUtils: The Spring JDBC abstract framework obtains database connections through its getConnection(DataSource dataSource) method, releaseConnection(Connection con, DataSource dataSource) is used to release database connections, and DataSourceUtils is used to support Spring managed transactions. Only connections obtained using DataSourceUtils have Spring managed transactions.

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

1) JdbcDaoSupport: supports consistent JdbcTemplate access

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

3) SimpleJdbcDaoSupport: JdbcDaoSupport subclass, providing SimpleJdbcTemplate access

Because 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 come to the community to discuss. Thank you for reading and I hope it can help you. Thank you for your support of this site!

You may also be interested in:
  • How to install and run the python plugin in IntelliJ IDEA
  • Intellij IDEA installation and use of lombok plug-in
  • Use of IntelliJ IDEA hot deployment plugin JRebel
  • Recommend a Key Promoter X plugin for IntelliJ IDEA to prompt shortcut keys
  • A must-have Intellij IDEA plugin for Java programmers
  • IntelliJ IDEA JRebel installation and use graphic tutorial (hot deployment plug-in)
  • Getting Started with Intellij IDEA Plugin Development
  • Intellij Idea plugin development: creating a project-level right-click menu
  • Use the Spring Initializr plugin in IntelliJ IDEA 2017.2.5 x64 to quickly create a Spring Boot/Cloud project (illustration)
  • Detailed description of the installation and use of IntelliJ IDEA plug-in (illustration)
  • How to install Vue development plug-in in IntelliJ IDEA
  • Detailed explanation of how to use the .ignore plugin in IntelliJ IDEA to ignore unnecessary submitted files
  • Intellij IDEA configuration Subversion plug-in implementation steps detailed explanation
  • Spring Boot practical database operation sample code
  • Springboot database operation graphic tutorial
  • Spring Boot Mysql database operation example
  • Detailed method of using IntelliJ IDEA plug-in EasyCode to generate code in one click in Spring Boot

<<:  How to use a game controller in CocosCreator

>>:  How to create a swap partition file in Linux

Recommend

An article to help you thoroughly understand position calculation in js

Table of contents introduction scroll Element.scr...

Detailed explanation of Vue's monitoring method case

Monitoring method in Vue watch Notice Name: You s...

Completely uninstall mysql. Personal test!

Cleanly uninstall MySQL. Personally tested, this ...

Detailed explanation of the solution to font blur when using transform in CSS3

This question is very strange, so I will go strai...

CSS to achieve text on the background image

Effect: <div class="imgs"> <!-...

Vue implements multi-column layout drag

This article shares the specific code of Vue to i...

MySQL learning tutorial clustered index

Clustering is actually relative to the InnoDB dat...

How to configure the Runner container in Docker

1. Create a runner container mk@mk-pc:~/Desktop$ ...

Create a screen recording function with JS

OBS studio is cool, but JavaScript is cooler. Now...

Javascript implements simple navigation bar

This article shares the specific code of Javascri...

HTML tutorial, easy to learn HTML language (2)

*******************Introduction to HTML language (...

MySQL GROUP_CONCAT limitation solution

effect: The GROUP_CONCAT function can concatenate...

How to clear mysql registry

Specific method: 1. Press [ win+r ] to open the r...

MySQL 5.7 installation-free configuration graphic tutorial

Mysql is a popular and easy-to-use database softw...

Vue3+TypeScript implements a complete example of a recursive menu component

Table of contents Preface need accomplish First R...