The Data Access Object Pattern (Structural – Not a GoF Pattern) ©SoftMoore ConsultingSlide 1.

Slides:



Advertisements
Similar presentations
Chapter 10: Designing Databases
Advertisements

And so to Code. Forward, Reverse, and Round-Trip Engineering Forward Engineering Reverse Engineering Round-Trip Engineering.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Spring, Hibernate and Web Services 13 th September 2014.
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Using Third-Party Frameworks in Building Blocks™ David Ashman Principal Architect, Product Development.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
JDBC Session 5 Tonight: Data Access Patterns 1.J2EE Architecture & Design Patterns 2.The Data Access Tier 3.Data Access Patterns –DataAccessObject (DAO)
A Scalable Application Architecture for composing News Portals on the Internet Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta Famagusta.
UPortal Developers MIT August 2004 Persistence Strategy for uPortal 3 Mike DeSimone the r-smart group
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
Software Engineering 2003 Jyrki Nummenmaa 1 CASE Tools CASE = Computer-Aided Software Engineering A set of tools to (optimally) assist in each.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
Persistence Store Project Proposal.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
8/15/2003System Specialists Corporation How to implement BC4J with the Struts Framework Eugene Sicat Technical Architect/Project Manager System Specialists.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Core Indigo Patterns Ted Neward
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
CF101: Welcome to ColdFusion Simon Horwith CTO, Etrilogy Ltd.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
آرمان حسين‌زاده آذر  Access to data varies depending on the source of the data.  Access to persistent storage, such as to a database, varies greatly.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Metadata Store Management Platform GE:architectural notes Fabrizio Verroca, Roberto Pagnin Telecom Italia WP1.3, FIWARE
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Ch- 8. Class Diagrams Class diagrams are the most common diagram found in modeling object- oriented systems. Class diagrams are important not only for.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Mediator Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Bridge Pattern (Structural) “All problems in computer science can be solved by another level of indirection.” – Butler Lampson ©SoftMoore ConsultingSlide.
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Template Method Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Basics of JDBC Session 14.
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
The Strategy Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Singleton Pattern (Creational)
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
1 A Very Brief Introduction to Relational Databases.
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Reactor An ORM framework for ColdFusion Presentation By: Doug Hughes
Introduction to Database Programming with Python Gary Stewart
Data Access Patterns Problems with data access from OO programs: 1.The object-relational impedance mismatch 2.Decoupling domain logic from database technology.
COMP 430 Intro. to Database Systems SQL from application code.
Introduction to Entity framework
SQL – Application Persistence Design Patterns
Database Management Systems
Developing and testing enterprise Java applications
SQL – Application Persistence Design Patterns
SPL – PS13 Persistence Layer.
Presentation transcript:

The Data Access Object Pattern (Structural – Not a GoF Pattern) ©SoftMoore ConsultingSlide 1

Motivation Most real-world applications need to use persistent data. Mechanisms for persisting data vary greatly –Text Files (e.g., CSVs) – XML Files –Relational Databases– Object-Oriented Databases –NoSQL Databases – LDAP Repositories –Web Services– Proprietary Systems Even when using a relational database, the actual syntax and format of SQL statements can vary from one RDBMS vendor to another. How do we maintain flexibility so that the underlying persistence mechanism can be changed with minimal impact on the rest of the application? ©SoftMoore ConsultingSlide 2

Data Access Object – Basic Idea Abstract and encapsulate the details of persistence into a data access layer by separating business/application objects from the data access objects. Data access objects are the only objects that have knowledge of and communicate with the underlying persistence mechanism. They encapsulate all persistence-related functions. Changes to the persistence mechanism require changes to the DAO layer only, and not to the application objects. For this pattern to be effective, it is important that no (or at least minimal) details of the persistence mechanism “leak” out of the DAO layer. ©SoftMoore ConsultingSlide 3

Data Access Object Pattern Intent: Separate application logic from the logic used to access the underlying persistence mechanism, thereby allowing the persistence mechanism to change without impacting the rest of the application Applicability: Use the Data Access Object Pattern when any of the following apply: –An application uses a lot of persistent data. –The persistence mechanisms are likely to change during the lifetime of an application. –An application needs to support different vendor products for persistence. –Portability of an application is a key design consideration. Slide 4©SoftMoore Consulting

Data Access Object Pattern (continued) ©SoftMoore ConsultingSlide 5 Structure BusinessObjectDataAccessObject Data Source

Data Access Object Pattern (continued) Participants BusinessObject –represents an object used by an application that requires persistence (e.g., Employee, Customer, Order, etc.) –contains business/application logic, but does not know how to store itself in a persistence mechanism. DataAccessObject –abstracts and encapsulates access to the persistence mechanism for the business object. –all access to the underlying persistence mechanism goes through the DataAccessObject. –provides persistence CRUD (create, read, update, delete) operations for the BusinessObject. ©SoftMoore ConsultingSlide 6

Data Access Object Pattern (continued) Participants (continued) Data Source –represents the persistence mechanism (e.g., RDBMS, text file, LDAP repository, etc.) Other possible participants include –TransferObject serves as a data carrier returns data to the BusinessObject –A DAOFactory for creating/returning DAO objects can use AbstractFactory pattern for different persistence mechanisms (e.g., different databases) ©SoftMoore ConsultingSlide 7

Data Access Object Pattern (continued) Collaborations BusinessObject uses the DataAccessObject for all access to the underlying persistence mechanism. DataAccessObject communicates directly with DataSource to persist the BusinessObject. ©SoftMoore ConsultingSlide 8

Data Access Object Pattern (continued) Consequences: The Data Access Objects pattern Localizes access to the persistence mechanism. Since all access to the persistence mechanism is encapsulated in the DataAccessObject, ripple effects from possible changes to the persistence mechanism are minimized. In addition, changes to add additional functionality or improve performance are straightforward. Simplifies replacement of the persistence mechanism. Migration to a different database or persistence mechanism involves changes only to the DAO layer. ©SoftMoore ConsultingSlide 9

Data Access Object Pattern (continued) Consequences (continued) Reduces complexity of business objects. Logic to manage access to the data source is moved from business objects to data access objects. ©SoftMoore ConsultingSlide 10

Data Access Objects Pattern (continued) Implementation Using a DAOFactory. Using an Abstract Factory to create specific DAO objects can improve portability and flexibility, especially when it is known in advance that an application needs to support different vendor products for persistence. Naming Conventions. DataAccessObjects often use the same name as the business/application object with a “ DAO ” suffix; e.g., Customer and CustomerDAO. ©SoftMoore ConsultingSlide 11

DAO Example (Example of a Business Object) public class Student { private String id; private String lastName; private String firstName; private Date dateOfBirth; private String sex; private String ethnicity; private String major;... // constructors, get/set methods, etc.... // toString(), equals(), hashCode(), etc. } ©SoftMoore ConsultingSlide 12

DAO Example (Abstract Superclass for all Data Access Objects) public abstract class DAO {... // methods useful for all data access objects public Log getLog() {... } /** * Executes an insert, update, or delete query. the row count for the query */ public int executeUpdate(String query) {... } public void close(Statement stmt, Connection conn) {... } } ©SoftMoore ConsultingSlide 13

DAO Example (Example of a Data Access Object) public class StudentDAO extends DAO {... // constructor and other methods public int insert(List stucents) {... } public int update(List students) {... } public int remove(List ids) {... } public Student get(String id) {... } ©SoftMoore ConsultingSlide 14 (continued on next slide)

DAO Example (Example of a Data Access Object − continued) public List getBasedOnLastName (String lastNamePrefix) {... } public List getAllMajors(String major) {... } } ©SoftMoore ConsultingSlide 15

Automated Tools for DAO Objects FireStorm/DAO by CodeFutures DaoGen by TitanicLinux.Net DAO4J DB Visual ARCHITECT by Visual Paradigm ©SoftMoore ConsultingSlide 16

Related Patterns Abstract Factory can be used to create data access objects for different business objects. Concrete factories can be implemented for different databases/persistence mechanisms. ©SoftMoore ConsultingSlide 17

References Data access object pattern (Wikipedia) Core J2EE Patterns – Data Access Object Write once, persist anywhere: Implement a Data Access Object pattern framework (James Carman, JavaWorld) Database Interaction with DAO and DTO Design Patterns (by Sandeep Bhandari, JavaLobby) Data Access Object (Best Practice Software Engineering) ©SoftMoore ConsultingSlide 18