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

How to implement Vue binding class and binding inline style

Table of contents Binding Class Binding inline st...

MySql COALESCE function usage code example

COALESCE is a function that refers to each parame...

Example of how to change the line spacing of HTML table

When using HTML tables, we sometimes need to chan...

Navicat connection MySQL error description analysis

Table of contents environment Virtual Machine Ver...

Details on using JS array methods some, every and find

Table of contents 1. some 2. every 3. find 1. som...

MySQL 5.7.21 winx64 installation and configuration method graphic tutorial

This article summarizes the notes for installing ...

MySQL 8.0.13 decompression version installation graphic tutorial under Windows

This article shares with you the MySQL 8.0.13 ins...

Advanced techniques for using CSS (used in actual combat)

1. The ul tag has a padding value by default in Mo...

Installation tutorial of MySQL 5.7 green version under windows2008 64-bit system

Preface This article introduces the installation ...

Examples of using the ES6 spread operator

Table of contents What are spread and rest operat...