Talking about DAO mode

xiaoxiao2021-03-06  70

Just getting my Web Media Technology's homework ... I have some time to write some personal opinions about Dao:

What is DAO

DAO is Data Access Object Data Access Interface ...

Data Access .. Therefore, it is a dedication to deal with the database ...

Is clip in the middle of business logic and database resources ...

DAO's function:

1. DAO is used to encapsulate Data Source .., for example, Connection Conn = DAOFATRY.CREATECONNECTION () .. You can change the DRIVER. URL. UserName, PassPword Some of the type of database to change the type of database. For example MSSQL is replaced with Oracle .. Simply change the driver.URL in the getConnection () in Daofacory .. 2.2. DAO is also encapsulated by the operation of the database (such as the most basic CRUD operation). For example, if you want to insert a new user .. So, in Dao, we only need to provide an insertuser (user user) this method .. The specific operation is implemented in DAO ... So When you want to call DAO. We just know that INSERTUSER (user) is used to insert a new user ... and don't know how to implement it ..

General DAO is used with the Abstract Factory mode ...

Factory to establish a database and positioning specific DAO (for example Userdao..customerdao ..) .. Generally set the getConnection to static .. You can also put the HibernateSessionFactory this public class in this AbstractFactory class ...

public class DAOFactory {private static final SessionFactory sessionFacotory; // define a TrheadLocal static Session currentSession () ..... public UserDao getUserDAO () {return new UserDaoImpl (sesssion);.} pulbic OtherDao getOtherDAO () {return new OtherDaoImpl ( session);} ...

public interface UserDao {public insertUser (FormBean) public updateUser (FormBean);} then implement an interface DAO: (Struts of FormBean ... VO come ..) public class UserDaoImpl implements UserDao {private Session session; public UserDaoImpl (Session Session) {this.Session = session;} ... public insertuser (FORMBEAN) {.///////wwwwwwdateuse}} ............................................................................... "

Huhmmmm ..........

转载请注明原文地址:https://www.9cbs.com/read-87969.html

New Post(0)