PPT09_Data_Access - Data Access Making Objects Persistent...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Data Access Making Objects Persistent Use object persistence to store instances or attribute values for later retrieval Two approaches to achieving persistence: Attribute storage store the objects attributes individually Object storage store the entire object Advantage of object storage is that you dont need to recreate the object when you retrieve it 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 persistent 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 Designing a Data Access Class Design a DA class for every persistent PD class A DA class is accessed only by the PD class it is associated with A CustomerDA class is accessed only by the Customer class PD classes that need data must request it from the appropriate PD class. That PD class will invoke methods in its DA class. DA classes are generally not instantiated 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 add method Change update method Remove delete method Data Access Methods public static Customer find(String phoneNo) throws NotFoundException public static void addNew(Customer aCustomer) throws DuplicateException public static void update(Customer aCustomer) throws NotFoundException public static void delete(Customer aCustomer) throws NotFoundException public static voide initialize() public static void terminate() public static Vector getAll() Communicating with DA Class The Customer class has the same methods that will simply invoke the methods in CustomerDA class Isolates the DA class from everything but one PD class PD class methods are not tied to data storage method Finding a Customer The purpose of the PD find method is to invoke the DA find method Its a static method because its not tied to a specific customer instance Throws a NotFoundException if the customer is not found Adding a Customer The purpose of the PD addNew method is to invoke the DA addNew method Its a non-static method because its invoked for the new customer being added Throws a DuplicateException if the customer already exists Changing a Customer The purpose of the PD update method is to invoke the DA update method Its a non-static method because its invoked for the customer being updated Throws a NotFoundException if the customer is not found Page 1 of 13 Deleting a Customer The purpose of the PD delete method is to invoke the DA delete method Its a non-static method because its invoked for the customer being deleted Throws a NotFoundException if the customer is not found Understanding Java I/O Java views data input and output as a flow of bytes (stream) Two different data streams: Byte stream...
View Full Document

Page1 / 13

PPT09_Data_Access - Data Access Making Objects Persistent...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online