Dao Completo

15
Fabian Andres Hoyos Sergio Vargas Poveda Cristian Schotborgh Lopez Facultad de ingeniería de sistemas Fecha: 05 / 07/ 2014

Transcript of Dao Completo

Page 1: Dao Completo

Fabian Andres HoyosSergio Vargas Poveda

Cristian Schotborgh Lopez

Facultad de ingeniería de sistemasFecha: 05 / 07/ 2014

Page 2: Dao Completo

PATRONDAO

Page 3: Dao Completo

Patrón DAO

Design pattern

They are the backbone of proven and documented to common problems in software development solutions subject to similar contexts.

Page 4: Dao Completo

DAO

Data Access Object is a software component that provides a common interface between the application and one or more data storage devices, such as a database or file base.

Page 5: Dao Completo

DAO

The DAO pattern solves this problem by using a Data Access Object to abstract and encapsulate the data access. A DAO manages the connection to the data source to obtain and store data.

A DAO always performs atomic operations against the database, transactions are never necessary. Clear examples of this would be a key searches, creating, updating and deleting a record, obtain all records and any other operation that we will make very often.

Usually a DAO is created for each object that we use in our application.

Page 6: Dao Completo

Benefits

- Storing and retrieving persistent data from different sources: relational databases, Files, XML, webservices, etc…

- Improve clarity in the project structure. - Allows access to encapsulate the data source. - The DAO manages the connection with the data source to obtain

and store information - A DAO defines the relationship between presentation logic and

domain model on the one hand and on the other data types. - The DAO has a common interface, regardless of the mode and

source data access

Page 7: Dao Completo

Benefits

• A DAO manages the connection to the data source to obtain and store data

• A DAO always performs atomic operations against the database, transactions are never necessary. Clear examples of this would be a key searches, creating, updating and deleting a record, obtain all records and any other operation that we will make very often

• Usually a DAO is created for each object that we use in our application

Page 8: Dao Completo

Disadvantages

- Gives access to different data repositories

- Requires large volumes of code

- Requires some understanding of the database schema

Page 9: Dao Completo

Example

Page 10: Dao Completo
Page 11: Dao Completo

Application example

public interface AccountDAO{ public boolean save(Account account); public boolean update(Account account); public boolean findByAccountNumber(int accountNumber); public boolean delete(Account account);

}

Page 12: Dao Completo

• Suppose we have the following table:

CREATE TABLE ciudades(nombre varchar(80),Departamento varchar(80));

• We will create 2 classes per connection with our application will have access: - Data Access - Data transport

Public class Cuidad{String nombre;String departamento;String gerNombre(){}String getDepartamento(){}}

Application example

Page 13: Dao Completo

Public class CiudadesDAO{Ciudad, ciudad;void insert(){}Void delete(){}Ciudad find(){consulta en base de datos}}

Page 14: Dao Completo

Relationship patterns

•Transfer object: the information is sent / received the DAO is packaged in these objects.•Factory: con el objetivo de conseguir la independencia del almacén de datos, comúnmente se usa este patrón para instanciar los daos

Page 15: Dao Completo

THANKS