Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.

Slides:



Advertisements
Similar presentations
UML State Machine Diagrams and Modeling
Advertisements

CSSE 374: Persistent Frameworks with GoF Design Patterns & Deployment Diagrams Steve Chenoweth Office: Moench Room F220 Phone: (812)
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
1 Layers Data from IBM-Rational and Craig Larman’s text integrated into these slides. These are great references… Slides from these sources have been modified.
Chapter 6 Methodology Logical Database Design for the Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Chapter 25 GRASP: More Objects with Responsibilities 1CS6359 Fall 2011 John Cole.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Data Management Design
Methodology Logical Database Design for the Relational Model
©Silberschatz, Korth and Sudarshan1.1Database System Concepts Chapter 1: Introduction Purpose of Database Systems View of Data Data Models Data Definition.
Template Method By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
Chapter 11 Data Management Layer Design
Mar 20, R McFadyen1 Persistent Objects Persistent objects are objects that continue to exist after the application program terminates Persistence.
Reuse Activities Selecting Design Patterns and Components
Dr. Kalpakis CMSC 461, Database Management Systems Introduction.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Chapter 25 More Design Patterns.
The chapter will address the following questions:
Client/Server Software Architectures Yonglei Tao.
CSSE 374: Even More Object Design with Gang of Four Design Patterns These slides derived from Shawn Bohner, Curt Clifton, and others involved in delivering.
11 1 Object oriented DB (not in book) Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Learning objectives: What.
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.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Database Systems: Design, Implementation, and Management Ninth Edition
Concepts and Terminology Introduction to Database.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
Chapter 1 : Introduction §Purpose of Database Systems §View of Data §Data Models §Data Definition Language §Data Manipulation Language §Transaction Management.
CSCI 3140 Module 3 – Logical Database Design for the Relational Model Theodore Chiasson Dalhousie University.
Introduction to Databases Trisha Cummings. What is a database? A database is a tool for collecting and organizing information. Databases can store information.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Designing a Persistence Framework With Patterns
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
1 Mapping to Relational Databases Presented by Ramona Su.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Fanny Widadie, S.P, M.Agr 1 Database Management Systems.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
DATABASE MANAGEMENT SYSTEM ARCHITECTURE
Chapter 36 More Object Design with GoF Patterns 1CS6359 Fall 2011 John Cole.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Lection №4 Development of the Relational Databases.
Session 1 Module 1: Introduction to Data Integrity
Elaboration Iteration 3 – Part 3 - Persistence Framework -
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS. The Problem: Persistent Objects persistent object An object that can survive the process or thread that.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
CSCE 240 – Intro to Software Engineering Lecture 3.
SQL Basics Review Reviewing what we’ve learned so far…….
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
XP Chapter 1 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Level 2 Objectives: Understanding and Creating Table.
Design Engineering 1. Analysis  Design 2 Characteristics of good design 3 The design must implement all of the explicit requirements contained in the.
Behavioral Design Patterns
UML Deployment and Component Diagrams, Designing Persistence Framework with Patterns Software Design and Analysis CSCI 2040.
Teaching slides Chapter 8.
Data Model.
Informatics 122 Software Design II
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole

Persistent Objects Object databases Relational databases Other: Flat files, XML, hierarchical databases, etc. 2CS6359 Fall 2011 John Cole

Persistence Service A Persistence Framework is a general- purpose, reusable, and extendable set of types that provides functionality to support persistent objects. Also called an O-R Mapping service if it works with an RDB. 3CS6359 Fall 2012 John Cole

Frameworks A Framework is an extensible set of objects for related functions. For example Swing, or LINQ. Provides an implementation of core and unvarying functions and allows a programmer to plug in the varying functions or to extend them. 4CS6359 Fall 2011 John Cole

Frameworks Is a cohesive set of interfaces and classes to provide services for the core, unvarying part of a logical subsystem Contain concrete and abstract classes that define interfaces to conform to, object interactions to participate in, and other invariants Usually require the user to define subclasses of framework class to use, customize, and extend framework services 5CS6359 Fall 2011 John Cole

Frameworks Have abstract classes that may contain both abstract and concrete methods Rely on the Hollywood Principle: Don’t call us, we’ll call you. User-defined classes will receive messages from predefined framework classes Frameworks are reusable 6CS6359 Fall 2011 John Cole

Persistence Service and Framework Requirements: Store and retrieve objects in a persistent storage mechanism Commit and rollback transactions Extensible to support different storage mechanisms 7CS6359 Fall 2011 John Cole

Key Ideas Mapping between a class and its persistent store and between object attributes and the fields in a record Object identity – to easily relate records to objects and ensure there are no inappropriate duplicates, records and objects have a unique identifier Database mapper – pure fabrication object responsible for materialization and dematerialization 8CS6359 Fall 2011 John Cole

Key Ideas Caches – persistence services cache materialized for performance Transaction state of object – State of objects in relation to the current transaction. Which objects are dirty? Transaction operations – Commit and Rollback 9CS6359 Fall 2011 John Cole

Key Ideas Lazy materialization – not all objects are materialized at once; materialization on demand Virtual proxies – Lazy materialization can be implemented using a smart reference known as a virtual proxy 10CS6359 Fall 2011 John Cole

Pattern: Representing Objects as Tables Define a table in the RDB for each persistent object class Attributes containing primitive data types map to columns Relational model requires that values be atomic (first normal form) 11CS6359 Fall 2011 John Cole

Pattern: Object Identifier Since it is desirable to have a consistent way to relate objects to records and no duplicate rows, use an Object Identifier for each record. Every table will have an OID as its key field and every record in the table will have a unique value for this key OID provides a consistent key type 12CS6359 Fall 2011 John Cole

Accessing Persistence Service with a Facade Define a façade for the various services Retrieve an object given its OID; system needs to know what kind of object, so provide the class type, too 13CS6359 Fall 2011 John Cole

Mapping Objects The Persistence Façade delegates the work If a persistent object (such as ProductDescription) persists itself, this is a direct mapping design This works if a compiler tool generates it Problems: strong coupling of the object to storage; complex responsibilities in an unrelated area. 14CS6359 Fall 2011 John Cole

Database Broker Class that is responsible for materialization, dematerialization, and object caching Pattern is also called Database Mapper Define a different mapper class for each persistent object 15CS6359 Fall 2011 John Cole

Mapper Factory Better not to name each mapper with a different operation. For example: class MapperFactory { public IMapper getProductDescriptionMapper() {...} public IMapper getSaleMapper() {...}... } 16CS6359 Fall 2011 John Cole

Mapper Factory Better: class PersistenceFacade { private java.util.Map mappers = MapperFactory.getInstance().getAllMappers();... } 17CS6359 Fall 2011 John Cole

Metadata-based Mappers Instead of creating individual mapper classes for persistent types, these generate the mapping using metadata that describes the mapping Thus you can change the schema mapping in an external store and it will be reflected in the running system Pattern is Protected Variations WRT schema variations 18CS6359 Fall 2011 John Cole

Template Method Pattern Define a method (the Template Method) in a superclass that defines the skeleton of an algorithm. This invokes other methods, some of which may be overridden by a subclass Subclasses can override varying methods to provide unique behavior at points of variability 19CS6359 Fall 2011 John Cole

Template Pattern The basic algorithm structure is: If the object is in cache, return it If not, create it from its representation in storage, save it in cache, and return it The point of variation is how the object is created from storage 20CS6359 Fall 2011 John Cole

Template Pattern Create the get method as the template in an abstract superclass AbstractPersistenceMapper that defines the template, and use a hook method in subclasses for the varying part. The get method contains critical section code that must be made thread-safe 21CS6359 Fall 2011 John Cole

Synchronized Methods in UML +get(OID): Object {guarded} CS6359 Fall 2011 John Cole22

Transactional States and the State Pattern Persistent objects can be inserted, deleted, or modified; Operating on a persistent object does not cause an immediate database update; an explicit commit operation must be done The response to an operation depends upon the transactional state of the object CS6359 Fall 2011 John Cole23

Persistent Object Statechart CS6359 Fall 2011 John Cole24

PersistentObject Implements the following methods: – Commit() – Delete() – Rollback() – Save() Extending a domain class with a technical services class mixes architectural concerns CS6359 Fall 2011 John Cole25

State Pattern Commit and Rollback have different logic but similar structure Problem: If an object’s behavior is dependent upon its state, is there an alternative to conditional logic? Solution: Create state classes for each state, implementing a common interface. Delegate state- dependent operations from the context object to its current state object. Ensure the context object always points to a state object reflecting its current state. CS6359 Fall 2011 John Cole26

Transaction and the Command Pattern Transaction is a set of tasks that either must all be completed or none completed. Thus it is atomic The order of database tasks within a transaction can influence its success and performance CS6359 Fall 2011 John Cole27

Transaction examples Suppose the database has a referential integrity constraint such that when a record is updated in table A that contains a foreign key reference to table B, the record in B must exist Suppose a transaction contains an INSERT task to add the B record and an update for A. If the update occurs before the insert, error Ordering the tasks helps CS6359 Fall 2011 John Cole28

Command Pattern Problem: How to handle requests or tasks that need functions such as sorting, queuing, delaying, logging, or undoing? Solution: Make each task a class that implements a common interface CS6359 Fall 2011 John Cole29

Command Pattern Actions become objects and can be sorted, logged, etc. Each task or action is an object with an Execute method GUI actions such as cut and paste are examples of Command. The CutCommand’s execute method does a cut and its undo method reverses the cut. These objects can be stacked CS6359 Fall 2011 John Cole30

Lazy Materialization with a Virtual Proxy Sometimes useful not to materialize an object until absolutely necessary. This may be because the object is rarely referenced. Example: Manufacturer object referenced by ProductDescription Virtual Proxy gets the real object on first reference, thus standing in for the object. Created by the object that references the other object CS6359 Fall 2011 John Cole31

Representing Relationships One-to-one: place an OID foreign key in one or both tables or create an associative table with the OIDs of each object in the relationship. One-to-many: Create an associative table with keys of both objects Many-to-many: Create an associative table with keys of both objects CS6359 Fall 2011 John Cole32

Separation of Concerns Weakness of creating a PersistentObject class but it couples domain classes to technical services classes Separation is not an absolute rule, but be careful how you break it CS6359 Fall 2011 John Cole33