DAO

This is a summary for beginners to study personally.

DAO(Data Access Object)

・ Simply put, the idea of creating a class called DAO that specializes in accessing databases and leaving everything related to databases to us. ・ One of the Java EE design patterns

DAO's unique features

  1. ** By abstracting data access into classes, you can hide specific data sources from the business layer and do not depend on them **

→ Being able to hide a specific data source means that even if the data source changes, the business layer does not need to be aware of the change as long as the interface is decided. For example, I'm using postgresql now, and when I change to Oracle in the future, the business layer doesn't have to be aware of the change, and the only fix is DAO. This is true even if the persistence layer (the layer that stores data so that it is not lost after the program ends) is something other than an RDBMS such as a CSV file or XML-DB (such as using a web service), the business layer It also means that you don't have to be aware of it. → In principle, only DAO is accessing the database, so even if the table structure of the database is changed, only DAO will be affected.

  1. ** Programmers unfamiliar with SQL can access the persistence layer without being aware of SQL. ** **

→ If you want to disconnect after connecting to the database, you have to use ** close method ** for the object of Connection interface acquired at the time of connection, but if you forget to close ** garbage collector ** Automatically closes the connection as soon as the object is destroyed, and the quality (reliability) is improved from the perspective of the entire system. ** However, this is a mistake, and you should immediately disconnect from the database you no longer use.

References

http://qune.jp/archive/001266/index.html https://ts0818.hatenablog.com/entry/2017/07/10/223553 https://techacademy.jp/magazine/19443

Recommended Posts