Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.

Slides:



Advertisements
Similar presentations
Basics of Database Programming with VB6
Advertisements

The Package Statement Group related interfaces and classes together Purpose: encapsulation and reduces name conflicts –private package classes not visible.
File-based Persistence: Serializability COMP53 Dec 7, 2007.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
Creating a Blank Database 1. Open up Microsoft Access 2. Click on Blank document button 3. On the right panel, Specify the location for saving your database.
1004INT Information Systems Week 10 Databases as Business Tools.
Database Design Chapter 2. Goal of all Information Systems  To add value –Reduce costs –Increase sales or revenue –Provide a competitive advantage.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L08 (Chapter 18) Binary I/O.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
13.1 Understanding Files The File class Objects can read and write to the file system Use the File class to hold information about files and directories.
Microsoft Access 2010 Chapter 7 Using SQL.
Chapter 15 - Creating More Complex Database Applications 1 Chapter 15 Creating More Complex Database Applications.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
Files and Streams (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Introduction to Databases. Overview  What is a Database?  What is a Database Management System?  How is information organized in a database?  What.
Irwin/McGraw-Hill Copyright © 2000 The McGraw-Hill Companies. All Rights reserved Whitten Bentley DittmanSYSTEMS ANALYSIS AND DESIGN METHODS5th Edition.
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
Database Programming in Java Corresponds with Chapter 32, 33.
Introduction to Accounting Information Systems
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
Input / Output Chapter 13.  We use files all the time  Programs are files  Documents are files  We want them to be “permanent”  To last beyond execution.
©2007 · Georges Merx and Ronald J. NormanSlide 1 Chapter 10 Information Management in Java.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Relational Databases (MS Access)
File Processing Concepts – Field – combination of 1 or more characters that is the smallest unit of data to be accessed – Record – group of related fields.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
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.
Files and Streams Chapter What You Will Learn Create files Read files Write files Update files.
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
Component 4: Introduction to Information and Computer Science Unit 6a Databases and SQL.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
GLOBEX INFOTEK Copyright © 2013 Dr. Emelda Ntinglet-DavisSYSTEMS ANALYSIS AND DESIGN METHODSINTRODUCTORY SESSION EFFECTIVE DATABASE DESIGN for BEGINNERS.
 Pearson Education, Inc. All rights reserved Files and Streams.
Oracle10g Developer: PL/SQL Programming1 Objectives SQL queries within PL/SQL Host or bind variables The %TYPE attribute Include queries and control structures.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
Oracle11g: PL/SQL Programming Chapter 3 Handling Data in PL/SQL Blocks.
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Session 1 Module 1: Introduction to Data Integrity
1 Exceptions Exception handling – Exception Indication of problem during execution – E.g., divide by zero – Chained exceptions Uses of exception handling.
Basics of JDBC Session 14.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Introduction to File Processing with PHP. Review of Course Outcomes 1. Implement file reading and writing programs using PHP. 2. Identify file access.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. A database is a collection of information organized to provide efficient retrieval. The collected information.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
SQL Basics Review Reviewing what we’ve learned so far…….
Module 11: File Structure
IS444: Modern tools for applications development
Chapter 12 Information Systems.
JDBC.
IS444: Modern tools for applications development
MSIS 670: Object-Oriented Software Engineering
Creating More Complex Database Applications
Handling Data in PL/SQL Blocks
Presentation transcript:

Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes

Chapter 14 - Designing Data Access Classes2 Making Objects Persistent  Use object persistence to store instances or attribute values for later retrieval  Two approaches to achieving persistence:  Attribute storage – store the object’s attributes individually  Object storage – store the entire object  Advantage of object storage is that you don’t need to recreate the object when you retrieve it

Chapter 14 - Designing Data Access Classes3 Making Objects Persistent

Chapter 14 - Designing Data Access Classes4 Designing a Data Access Class  The purpose of the Data Access (DA) class is to provide methods to store and retrieve data and make instances of a Problem Domain (PD) class persistence  Three tier OO design  GUI class  PD class for business entities  DA class for data storage and retrieval  DA class isolates data storage and retrieval  DA class supports three-tier architecture

Chapter 14 - Designing Data Access Classes5 Data Access Methods  Since you will not have instances of the DA class – all methods will be static  Four basic methods are provided  Retrieve – find method  Store – addNew method  Change – update method  Remove – delete method

Chapter 14 - Designing Data Access Classes6 Data Access Methods

Chapter 14 - Designing Data Access Classes7 Communicating with DA Class  The Customer class invokes methods in CustomerDA class  Isolates the DA class from everything but PD class  DA class methods are not tied to data storage method 14

Chapter 14 - Designing Data Access Classes8 Finding a Customer  The purpose of the PD find method is to invoke the DA find method  It’s a static method because it’s not tied to a specific customer instance  Throws a NotFoundException if the customer is not found 14

Chapter 14 - Designing Data Access Classes9 Adding a Customer  The purpose of the PD addNew method is to invoke the DA addNew method  It’s a non-static method because it’s invoked for the new customer being added  Throws a DuplicateException if the customer already exists

Chapter 14 - Designing Data Access Classes10 Changing a Customer  The purpose of the PD update method is to invoke the DA update method  It’s a non-static method because it’s invoked for the customer being updated  Throws a NotFoundException if the customer is not found

Chapter 14 - Designing Data Access Classes11 Deleting a Customer  The purpose of the PD delete method is to invoke the DA delete method  It’s a non-static method because it’s invoked for the customer being deleted  Throws a NotFoundException if the customer is not found

Chapter 14 - Designing Data Access Classes12 Understanding Java I/O  Java views data input and output as a flow of bytes  Two different data streams:  Byte stream  Character stream 14

Chapter 14 - Designing Data Access Classes13 Understanding Java I/O 14

Chapter 14 - Designing Data Access Classes14 Understanding Java I/O  Record is a collection of related variables  File is a collection of related records  Sequential files contains records that are stored and processed in sequential order  Random access files are organized so you can access a record by specifying its record number  Database is one or more files that help make queries  Relational database organized in tables and rows 14

Chapter 14 - Designing Data Access Classes15 Implementing Persistence with a Sequential File  Reads the customer records, creates a customer instance for each record, and places instances in a Vector  Uses the java.io package import java.io.*; 14

Chapter 14 - Designing Data Access Classes16 Initialize Method  Reads the attribute values for all of the customers from the sequential file  Uses BufferReader class to read the file sequentially 14

Chapter 14 - Designing Data Access Classes17 Terminate Method  Responsible for creating a file that contains attribute values for all the customer instances in the Vector  Attributes written to the file using the println method 14

Chapter 14 - Designing Data Access Classes18 Find Method  The find method simply iterates the customers Vector, seeking a customer instance with a phone number that matches the value received by the method  If the customer is not found a NotFoundException is thrown

Chapter 14 - Designing Data Access Classes19 AddNew Method  Simply adds the new reference to the Vector  If a duplicate is found throws a DuplicateException error

Chapter 14 - Designing Data Access Classes20 Update Method  Contains no code – since the file is written when done 14

Chapter 14 - Designing Data Access Classes21 Delete Method  Remove a customer from the system  Removes the reference from the Vector  If the customer is not found a NotFoundException is thrown 14

Chapter 14 - Designing Data Access Classes22 getAll Method  The Vector already contains all of the customers  Simply returns this Vector

Chapter 14 - Designing Data Access Classes23 Testing CustomerDA Class 1.Create two customer instances 2.Invoke initialize 3.Invoke addNew to add two customers 4.Retrieve reference to first customer 5.Invoke getAll 6.Invoke delete 7.Change first customer’s address and verify 8.Invoke the terminate method 14

Chapter 14 - Designing Data Access Classes24 Implementing Persistence with Random Access  Change the file specification to Customer.ran  Use the RandomAccessFile class  Use the writeBytes method

Chapter 14 - Designing Data Access Classes25 Implementing Persistence with Object Serialization  Store the entire Customer instances  Change the file specification to Customer.obj  Use the ObjectInputStream and the readObject method  Use the ObjectOutputStream and the writeObject method

Chapter 14 - Designing Data Access Classes26 Designing a Relational Database  Provide tools to organize data into tables  Each column represents a field  Each row represents a record  Each customer is identified by their phone number – primary key  Protocols required to access Microsoft Access  Java Database Connectivity (JDBC)  Open Database Connectivity (ODBC)  See pp. 510 for setup of DSN 14

Chapter 14 - Designing Data Access Classes27 Designing a Relational Database 14

Chapter 14 - Designing Data Access Classes28 Understanding SQL  Structured Query Language (SQL) used to access relational databases  SQL SELECT is used to retrieve a specific customer record  SQL INSERT is used to add a new customer record  SQL UPDATE is used to change a customer record  SQLQ DELETE is used to delete a customer record  Java.sql package contains the database access method 14

Chapter 14 - Designing Data Access Classes29 Understanding SQL 14