What is Dao layer?

Source: Internet
Author: User

I wrote two articles consecutively about the hierarchies. I have been talking about the relationship between the layer and the layer. What should I put in the DaO layer for the transmission and processing of data objects between layers? Of course, I have briefly introduced the DaO layer model. Now let's explain in detail what is in the DaO layer.

 

First, start thinking about this issue based on JDBC.

When querying a user information (ID, name), we often perform the following operations:

1. Get a connection

2. Generate a statement

3. concatenate SQL statements

4. query the object and obtain the result set (assuming that the object we need has been found)

5. Read the result set information and encapsulate it into user objects.

6. Disable result set, statement, connection

 

Next, consider how to deal with hibernate?

1. create user information objects and configure object relationship ing

2. Get a Session Object

3. Produce a query object

4. Compile hql statements

5. Execute the query. List () method to obtain object information (here, the Hibernate framework completes the conversion between objects and relationships based on the ing relationship)

6. Close the session object

 

In detail, they actually process the same thing, but the difference is that they are slightly different in the encapsulation process.

 

Let's take a look at how ibatis is handled,

1. Write a po object and configure the sqlmap File

2. Generate sqlmapclient object

3. Return results of the corresponding SQL statement (in the SQL statement, In the configuration file we wrote, the object encapsulation is completed by the ibatis Framework)

4. Disable sqlmapclient

 

The Dao layer should process the transformation of object relationships. It needs a connection object, but it does not care about how the object comes from, and does not care about after the conversion is completed, how to handle it. Like the ibatis framework, it acts as a Dao in the project, because we have converted the object relationship through the configuration file and object. For JDBC and hibernate technologies, I personally think that we can pass a connection as a parameter to Dao to avoid getting a connection object for every method of Dao, in this way, we don't need to process the opening and closing of database connections in Dao, from where to implement Transaction Management outside Dao.

 

It is better to move the transaction to the business logic layer ~

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.