This preview has intentionally blurred sections. Sign up to view the full version.View Full 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 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 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 it’s 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 It’s a static method because it’s 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 It’s a non-static method because it’s 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 It’s a non-static method because it’s 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 It’s a non-static method because it’s 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
- Spring '10
- Computer file, public static void, NotFoundException