The Data Layer Database Design.

Slides:



Advertisements
Similar presentations
Three-Step Database Design
Advertisements

Chapter 10: Designing Databases
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
Management Information Systems, Sixth Edition
Introduction to Database Processing with ADO.NET.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Data Management Design
Chapter 11 Data Management Layer Design
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Database Features Lecture 2. Desirable features in an information system Integrity Referential integrity Data independence Controlled redundancy Security.
Information systems and databases Database information systems Read the textbook: Chapter 2: Information systems and databases FOR MORE INFO...
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
Databases C HAPTER Chapter 10: Databases2 Databases and Structured Fields  A database is a collection of information –Typically stored as computer.
ASP.NET Programming with C# and SQL Server First Edition
1 Advanced Computer Programming Databases. Overview What is a database? Database Basics Database Components Data Models Normalization Database Design.
1 CS 430 Database Theory Winter 2005 Lecture 1: Introduction.
Introduction to SQL Steve Perry
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Intro to C#.net and EF Ilan Shimshoni. The Three Faces of ADO.NET The connected layer – Directly connecting to the DB The disconnected layer – Using datasets.
1 Introduction to Database Systems. 2 Database and Database System / A database is a shared collection of logically related data designed to meet the.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Entity Framework Overview. Entity Framework A set of technologies in ADO.NET that support the development of data-oriented software applications A component.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
CHAPTER EIGHT Accessing Data Processing Databases.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Object Persistence (Data Base) Design Chapter 13.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
Slide 1 Object Persistence Design Chapter 13 Alan Dennis, Barbara Wixom, and David Tegarden John Wiley & Sons, Inc. Slides by Fred Niederman Edited by.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Chapter 12: Designing Databases
INFORMATION MANAGEMENT Unit 2 SO 4 Explain the advantages of using a database approach compared to using traditional file processing; Advantages including.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Object Oriented Software Development 10. Persistent Storage.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
Use of ICT in Data Management AS Applied ICT. Back to Contents Back to Contents.
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
CSE323 การวิเคราะห์และออกแบบระบบ (Systems Analysis and Design) Lecture 12: Data Management Design.
HNDIT Rapid Application Development
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Object storage and object interoperability
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Chapter 3: Relational Databases
1 Information Retrieval and Use De-normalisation and Distributed database systems Geoff Leese September 2008, revised October 2009.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
.NET Data Access and Manipulation
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
Introduction to Entity Framework
Teaching slides Chapter 8.
Systems Analysis and Design
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Database management systems
Presentation transcript:

The Data Layer Database Design

Persistent vs Transient Data Persistent data is data which survives after a piece of software is no longer running. It is typically stored in a file or a database, depending on the quantity and nature of the data.

What types of object tend to be persistent? What types of object tend to be transitory? Give examples

Architecture for persistence Presentation Layer interfaces between the software application and the database layer. wrapper layer that makes data appear as objects to the business logic layer Business Logic Layer Data Access Layer Database

Example : 4-layer architecture Presentation Layer User interface classes Control classes Entity classes Lower level data handling classes Application Logic Layer Business Logic Layer Domain Layer Data Management Layer

Designing Persistent Storage Are there parts of the system where file storage is appropriate? Is the system a truly object oriented system or a front-end to a database (like many web applications)? What type of DBMS is used e.g. relational, OO What is the logical layering of the system?

Files File and Record Structures Fixed – variable length records Header/body structures of files e.g. daily transactions Tagged data e.g. XML files File types Serial – update by adding at the end e.g. transaction files Sequential – ordered – need to partially rewrite file to insert records. Random access- can insert anywhere

File Access Modes Serial Indexed Sequential Direct access Hashed addressing Types of File Master File Transaction Files : record business transactions/events e.g. sales transactions, banking transactions Temporary or work files Parameter files used for e.g. configuration, settings etc.

When is it appropriate to use files? Files are appropriate for simple programs and data that does not need to be shared by many users.

Database Models Relational databases – RDBMS – most commonly used for record-based business applications. Based on records or relations (rows), between fields(columns), in tables relational algebra is used to extract data SQL is the standard query language e.g. SQL server, MySQL Object oriented Databases – used more for e.g. CAD systems. E.g. ObjectStore Object- Relational hybrids e.g. relational databases with OO extensions e.g. PostgresSQL

Relational Databases Data held in flat 2D tables with no embedding Need to translate between this and a structured store of objects Normalisation can be used to decompose complex objects into tables. Classes can be translated using some general “rules of thumb” Where is this done?

Normalisation Aim : to reduce redundancy Functional dependency between elements should be 1-1 1NF – atomic values 2NF – every nonkey element is fully dependent on the primary key 3NF – attributes depend on the primary key and nothing else.

Entity- Relationship Modelling Identify entities and attributes Remove multivalued attributes Resolve many-many relationships Should produce normalised data

Example : Water Safety class Enrolment student trainer studentquals training Can a student be enrolled in more than one class at a time? If so we need this, otherwise? Qualification

Mapping Classes to Tables Classes with a simple data structure become tables, object identifiers become primary keys. Classes containing objects – we make these into a separate table and the objects are referenced by a unique object ID. Collections become tables: 1-many Many-many – we need separate tables 1-1 Use foreign key.

Example Object identifiers become primary keys <entity> class classID Startdate Enddate Day Time TrainerID <entity> student StudentID Name Address Phone Mobile Email Studentquals[] <entity> studentquals StudentID QualID Date of award TrainerID Classes containing objects –make these into a separate table and the objects are referenced by a unique object ID. Object identifiers become primary keys

Mapping an Inheritance Hierarchy implement subclasses as tables with different structures or implement superclasses and subclasses as tables. Depends on what makes sense in the application.

Example subclasses -> tables with different structures <entity> student StudentID Studentquals[] subclasses -> tables with different structures superclasses and subclasses ->tables. trainer table student table <entity> trainer Trainings[] Garda Vetting

Designing Data Management Classes Layered architecture Introduce new classes whose role is to deal with the storage and retrieval of other classes. This has the aim of separating the data storage classes from the business classes. -Database Broker Approach

Example : Product list Note the use of abstraction- here we just want to know that some object will fill our list for us. This will be implemented in the data access layer below public class Productlist { private List<product> products; public Productlist() { products = new List<Product>(); } public void Add(Product p) products.Add(p); .............. public void Fill() Products = ProductDB.GetProducts() } ..................

ProductDB Class Write a wrapper class to handle data access ProductDB Static class Product GetProduct(); bool AddProduct (Product p); bool UpdateProduct(Product oldprod, Product newprod); ...........

Use of Existing Frameworks e.g. ADO.Net Includes a number of namespaces ( including System.Data, System.Data.Common etc.) provided by .Net framework for working with relational databases. Data provider objects (e.g. DataReader and dataAdapter) manage the database for your application -gets data from the database into your application. DataSet objects (DataTable etc.) manage the data model within your application, providing a memory-resident set of objects that you can load with data. For example, the SQLConnection object is used to connect into a database; SQLCommand can be used to send an SQL command to your database.

Example : define data access class to deal with the database. public static class BankaccDB { //……… public static BankAccount GetBankaccount(string accID) // Set up SQL Connection SqlConnection connection = MyBankDB.GetConnection(); // Set up Query String string selectStatement= " SELECT BankID, Balance" + "FROM Bankaccounts" + "WHERE BankID = @AccID"; // .......................................

// Open the connection and read in the record. try { connection // Open the connection and read in the record..... try { connection.Open(); SqlDataReader accReader = selectCommand.ExecuteReader(commandBehaviour.SingleRow); if (accReader.Read() ) { BankAccount b = new BankAccount(); b.Accountno = accReader["BankID"].ToString; b.Balance = (double) accReader["Balance"]; return b; } else return null; // ...... Etc.

In terms of demonstrating this on a package diagram, this would show as a dependency between your system and the ADO.net package Business logic layer of your application is linked directly to the implementation-specific ADO, and this still leaves the entity model as an independent layer.

LINQ challenge in programming technology is to reduce the complexity of accessing and integrating information that is not natively defined using OO technology. The two most common sources of non-OO information are relational databases and XML LINQ is a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

// establish a query context over ADO // establish a query context over ADO.NET sql connection DataContext context = new DataContext( "Initial Catalog=petdb;Integrated Security=sspi"); // grab variables that represent the remote tables that correspond to the Person and Order CLR types Table<Person> custs = context.GetTable<Person>(); Table<Order> orders = context.GetTable<Order>();

LINQ to SQL: SQL Integration LINQ to SQL defines two core attributes, [Table] and [Column], which indicate which CLR types and properties correspond to external SQL data. [Table] attribute can be applied to a class and associates the CLR type with a named SQL table or view. [Column] attribute can be applied to any field or property and associates the member with a named SQL column

// build the query var query = from c in custs from o in orders where o.Customer == c.Name select new { c.Name, o.OrderID, o.Amount, c.Age }; // execute the query foreach (var item in query) Console.WriteLine("{0} {1} {2} {3}", item.Name, item.OrderID, item.Amount, item.Age);

LINQ to SQL: SQL Integration [Table(Name="People")] public class Person { [Column(DbType="nvarchar(32) not null", Id=true)] public string Name; [Column] public int Age; public bool CanCode; }

[Table(Name="Orders")] public class Order { [Column(DbType="nvarchar(32) not null", Id=true)] public string OrderID; [Column(DbType="nvarchar(32) not null")] public string Customer; [Column] public int? Amount; }