File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Can model know about database classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Can model know about database classes?" Watch "Can model know about database classes?" New topic
Author

Can model know about database classes?

John Chien
Ranch Hand

Joined: Feb 06, 2003
Posts: 105
Hi,
I am designing the Model of my GUI.
The Model (I called it FlightModel) uses a Facade
class to get data from database server.
I am wondering if the facade class should encapsulate Database classes (DBInfo,FieldInfo ...etc) from the FlightModel so that FlightModel has no knowledge of database at all.
For example: define the method in facade as
Object[][] searchFlight(String criteria);
insted of
DBInfo[] searchFlight(String criteria);
I found if I do so, client can not specify the record number that he/she wants to lock in the bookFlight() method because the FlightModel does not have knowledge of database record number.
Thus the bookFlight() might have to search the whole database to find the interested record to lock.
Question:1) Should I expose the Database classes to FlightModel?
or 2) Cache the Database data in Facade class ?
Which one is a better choice ?


SCJP, SCJD, SCWCD, SCBCD<br />IBM Certified Specialist (158)<br />Oracle9i PL/SQL Developer Certified Associate
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
Originally posted by John Chien:
I am wondering if the facade class should encapsulate Database classes (DBInfo,FieldInfo ...etc) ... I found if I do so, client can not specify the record number that he/she wants to lock in the bookFlight() method because the FlightModel does not have knowledge of database record number.
Question:1) Should I expose the Database classes to FlightModel?
or 2) Cache the Database data in Facade class ?
Which one is a better choice ?

Short answer to #1: No.
Long answer to #1:
I can't remember the specifics of how I did it, but in general I created an implementation of TabelModel that I populated with plain Java data types. My GUI calls searchFlights on my controller, which calls a method on my facade, which returns a data structure without any mention of the db classes. My controller then places this information into the table model, and for record numbers I have a column in the TableModel that is not visible on the GUI. So basically, I am loading up my TableModel with my search results from the db. This may be the entire db depending on my search criteria.

My reason for not letting the TableModel know about the db classes was that I wanted to cleanly separate my layers. (Arrows indicate who can see who)
[code]GUI (JFrame, JTabel, TableModel, etc) <--- Controller ---> Business (Facade) ---> Persistence[code]
Don't let your GUI (TableModel) be tied to your persistence layer implementation.
John Chien
Ranch Hand

Joined: Feb 06, 2003
Posts: 105
Thank you. This really help. You give me the hints of how I can have record number without knowing all the database classes. Yes, we should encapsulate those class using the facade class.
Model should not know those classes.
John Chien
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can model know about database classes?