Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.

Slides:



Advertisements
Similar presentations
Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Databases MMG508. DB Properties  Definition of a database: “A database is a collection of interrelated data items that are managed as a single unit”
 data/data-storage.html#pref data/data-storage.html#pref 
.NET Database Technologies: Open-Source Frameworks.
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.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
From Class Diagrams to Databases. So far we have considered “objects” Objects have attributes Objects have operations Attributes are the things you record.
Ch1: File Systems and Databases Hachim Haddouti
Attribute databases. GIS Definition Diagram Output Query Results.
Structure of a web application1 Dr Jim Briggs. MVC Structure of a web application2.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Chapter 2 Architectural Models. Keywords Middleware Interface vs. implementation Client-server models OOP.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
The Relational Model These slides are based on the slides of your text book.
Attribute Data in GIS Data in GIS are stored as features AND tabular info Tabular information can be associated with features OR Tabular data may NOT be.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
© D. Wong  Indexes  JDBC  JDBC in J2EE (Java 2 Enterprise Edition)
CST203-2 Database Management Systems Lecture 2. One Tier Architecture Eg: In this scenario, a workgroup database is stored in a shared location on a single.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 09. Review Introduction to architectural styles Distributed architectures – Client Server Architecture – Multi-tier.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
Chapter 1 : Introduction §Purpose of Database Systems §View of Data §Data Models §Data Definition Language §Data Manipulation Language §Transaction Management.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Nilesh Singh Local Data Storage option Android provides several options for you to save persistent application data. - Shared preferences - Creation.
1 CS 350 Data Structures Chaminade University of Honolulu.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
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.
Cohesion and Coupling CS 4311
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
© 2005 Prentice Hall10-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Lecture # 3 & 4 Chapter # 2 Database System Concepts and Architecture Muhammad Emran Database Systems 1.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
CS 1308 Computer Literacy and the Internet
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Chapter-2- Database System Concepts and Architecture Text Book : “Fundamentals of Database Systems” Additional References: Prof. Beat Signer Lecture notes.
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
Database Management Systems (DBMS)
The Data Access Object Pattern (Structural – Not a GoF Pattern) ©SoftMoore ConsultingSlide 1.
Copyright (c) 2014 Pearson Education, Inc. Introduction to DBMS.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
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.
Layers Architecture Pattern Source: Pattern-Oriented Software Architecture, Vol. 1, Buschmann, et al.
Database System Concepts Introduction Purpose of Database Systems View of Data Data Models Data Definition Language Data Manipulation Language Transaction.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
CHAPTER 9 File Storage Shared Preferences SQLite.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
Introduction to Database Programming with Python Gary Stewart
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Chengyu Sun California State University, Los Angeles
Structure of a web application
Chapter 2 Database Environment Pearson Education © 2009.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
CS3220 Web and Internet Programming SQL and MySQL
Database Management Systems
Developing and testing enterprise Java applications
CS3220 Web and Internet Programming SQL and MySQL
Chengyu Sun California State University, Los Angeles
Chapter 2 Database Environment Pearson Education © 2009.
SPL – PS13 Persistence Layer.
Presentation transcript:

Data Access Patterns

Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing low-level data access logic throughout a program is not a good idea (design). Program Data select * from Items rs.getString("Name")

Data Access Layer A better design is one that includes a data access layer which encapsulates the details of the underlying persistence API. It abstracts the low-level details of persistent storage. It provides an interface that is usually a better match for the style of programming used in the domain logic. For example, the data access layer might provide an OO interface onto relational data.

Program Data select * from Items rs.getString("Name") Program Data Data Access Layer select * from Items rs.getString("Name") customer = dao.find(id) update(customer)

Data Access Layer To avoid problems associated with mixing SQL and application logic, SQL statements and data base design details are often encapsulated in a data access layer The data access layer presents an interface that is convenient for application programs.

Program to an Interface; Not Implementation

SQL Most software systems that need persistent storage more powerful than a flat file end up using a relational database management system SQL is the standard language for managing data in a relational database. Mixing SQL with application logic is considered poor design. –Writing simple SQL statements takes a fair amount of skill, and writing efficient SQL statements takes even more. If you mix SQL and application logic, it makes it harder for those unskilled in SQL to work with the code. –Changes to the database may necessitate changes to the SQL that accesses the database. If the SQL is spread throughout the program, a small change to the database might cause a strong ripple effect throughout the program.

General benefits of having a data access layer Separation of concerns. Data storage logic is kept separate from domain logic. Information hiding. Domain logic avoids dependencies on database schema. Ability to change DB vendors without disrupting client code.

Data Access Architecture Patterns Key architecture patterns used in the implementation of a data access layer: –Table Data Gateway (aka Data Access Object) –Row Data Gateway –Active Record

Table Data Gateway Put all the logic for managing the records of a table into one class. There is one instance of the class for each table/view. find() methods return data for one row of the table/view. insert(), update() and delete() modify one row. Stateless (unlike Row Data Gateway) A Data Transfer Object (DTO) may be used to encapsulate and return record values. Customer in the class diagram to the right is an example of a DTO.

Table Data Gateway Variations Customer might include an id field. This would simplify certain routines: update(Customer) There may be find methods that return more than one record. One option for implementing such methods is to return a collection of DTO’s: List find(criteria)

Design Decisions/Discussion find() methods can return: –Record set (data structure from SQL query such as ResultSet). Convenient if find returns multiple records. –Data Transfer Object (object with getters and setters used to pass data around) –Generic collection class (e.g. map which may contain instances of a DTO) If table/view is read only, there is no need for insert, update and delete.

Row Data Gateway Define a stateful class that encapsulates the data for one record of your data source. There is one instance per row. The logic to find a record (one instance of the row data gateway class) can be represented as static methods on the row data gateway class or encapsulated in a separate finder class.

Usage scenarios Use finder object to fetch one row (an instance of row data gateway). Make updates to instance (it’s stateful). Ask instance to update(). Create an instance of row data gateway. Ask instance to insert().

When to use each pattern? Table Data Gateway is probably the simplest of all three. It also works well when you want to (or it’s not an inconvenience to) use record sets from SQL query. Row Data Gateway is convenient when you need data from two or more records in memory at once and it’s inconvenient to store the data in another data object (inconvenient = don’t want to create another object). Row Data Gateway also factors out the find/access logic. This is useful if it needs to be reused or can vary.

Active Record Active Record is a Row Data Gateway class with domain logic.

References Patterns of Enterprise Application Architecture Data Access Patterns: Database Interactions in Object-Oriented Applications Pattern-Oriented Software Architecture: A Pattern Language for Distributed Computing, 4th Volume Agile Principles, Patterns, and Practices in C# Core J2EE™ Patterns: Best Practices and Design Strategies

Android

Persistent Storage in Android Options: –Shared Preferences –Internal Storage – local to application –External Storage – shared space –SQLLite Database –Network Resources

Shared Preferences PreferenceActivity – standard way of saving settings getSharedPreferences() – –Example: SharedPreferences preferences = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE); getPreference - uses the getSharedPreferences() method with the name of the activity class for the preference file name getDefaultSharedPreferences – similar to getPreference() but uses a default file name. Limited to boolean, float, long and String.

Internal Storage openFileInput() openFileOutput() deleteFile() fileList()