It's not a secret anymore!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Max. Denny's DVD Project: GUIController class doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Max. Denny Watch "Max. Denny New topic
Author

Max. Denny's DVD Project: GUIController class doubt

Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hey all,
While am trying to understand GUIController class in Denny's DVD sample project that is given in Max Habibi's book, I did not understand the following.
/**
* Locates a DVD record by and UPC number.
*
* @param upc A String representing the UPC identifying the DVD record.
* @return A DVDTableModel containing all found DVD records.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public DVDTableModel findDVD(String upc) throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try{
dvdArray = (ArrayList) this.connection.find(upc);
out.addDVDRecord((DVD) dvdArray.get(0));
}
catch(PatternSyntaxException pse){
log.log(Level.WARNING, pse.getMessage(), pse);
throw new GUIControllerException(pse);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
In the above method, I think we are trying to get DVD record that has the given upc number. But inside the method, Max. is calling the find(upc) method instead of the getDVD(upc) method. I don't understand why Max. is using this method and it deviates from the other methods. The other methods are calling their respective methods in the DVDAdapter class or DVDDatabseImpl class.
Can anyone please help me understand the variation in calling this particular method? All inputs are greatly appreciated. Thanks.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Satish,
LEt me see if I can help. When you say
The other methods are calling their respective methods in the DVDAdapter class or DVDDatabseImpl class.

what does respective method mean to you?
M


Java Regular Expressions
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hello Max,
First of all, thank you for the reply. I will paste the whole code and will ask my question.
/**
* Locates a DVD record by and UPC number.
*
* @param upc A String representing the UPC identifying the DVD record.
* @return A DVDTableModel containing all found DVD records.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public DVDTableModel findDVD(String upc) throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try{
dvdArray = (ArrayList) this.connection.find(upc);
out.addDVDRecord((DVD) dvdArray.get(0));
}
catch(PatternSyntaxException pse){
log.log(Level.WARNING, pse.getMessage(), pse);
throw new GUIControllerException(pse);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
/**
* Locates a DVD based on a user defined search query.
*
* @param searchString The user defined search String
* @return A DVDTableModel containing all DVD records that met the search
* criteria.
* @throws GUIControllerException Indicates a database or network
* level exception.
*/
public DVDTableModel find(String searchString) throws
GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try {
System.out.println(this.connection);
dvdArray = (ArrayList)this.connection.find(searchString);
Iterator it = dvdArray.iterator();
while(it.hasNext()){
out.addDVDRecord((DVD)it.next());
}
}
catch(PatternSyntaxException pse){
log.log(Level.WARNING, pse.getMessage(), pse);
throw new GUIControllerException(pse);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
/**
* Retrieves all DVD records from the database.
*
* @return A DVDTableModel containing all DVD Records.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public DVDTableModel getDVDs() throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
ArrayList dvdArray = new ArrayList();
try {
System.out.println(this.connection);
dvdArray = (ArrayList)this.connection.getDVDs();
Iterator it = dvdArray.iterator();
while(it.hasNext()){
out.addDVDRecord((DVD)it.next());
}
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return out;
}
/**
* Decrements the number of DVD's in stock identified by their UPC number.
*
* @param upc The UPC of the DVD to rent.
* @return A boolean indicating if the rent operation was successful.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public boolean rent(String upc) throws GUIControllerException{
boolean retval = false;
try {
retval= this.connection.rent(upc);
}
catch(InterruptedIOException ie){
log.log(Level.SEVERE, ie.getMessage(), ie);
throw new GUIControllerException(ie);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return retval;
}
/**
* Increments the number of DVD's in stock identified by their UPC number.
*
* @param upc The UPC of the DVD to return.
* @return A boolean indicating if the return operation was successful.
* @throws GUIControllerException Indicates a database or
* network level exception.
*/
public boolean returnRental(String upc) throws GUIControllerException{
boolean retval = false;
try {
retval= this.connection.returnRental(upc);
}
catch(Exception e){
log.log(Level.SEVERE, e.getMessage(), e);
throw new GUIControllerException(e);
}
return retval;
}
-------------
In the above code, if we see for example, in the find(String) method, we are calling the this.connection.find(String), in the getDVDs() method, we are calling this.connection.getDVDs(), in the rent(String) mehod we are calling the this.connection.rent(String) respectively and so on...
But for the first findDVD(String upc) method, we are not calling the getDVD(String upc) method. I am not able to understand why we have this exception? Am I missing something here, Max? Please help me.
Thanks.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
You're assuming that there is some sort of requirement that the method names match one for one, which is not at all the case.
M
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Hi Max, I understand that there is no requirement like that. But my question is if we know the upc number, then it would be direct if we call the getDVD(String upc) method instead of calling find(String query) method in the findDVD(String upc) method.
We can also write the findDVD(String upc) method like this right?
public DVDTableModel findDVD(String upc) throws GUIControllerException{
DVDTableModel out = new DVDTableModel();
//ArrayList dvdArray = new ArrayList();
try{
//dvdArray = (ArrayList) this.connection.find(upc);
DVD dvd_temp = this.connection.getDVD(upc);
//out.addDVDRecord((DVD) dvdArray.get(0));
out.addDVDRecord(dvd_temp);
}
Would it make any difference if the code is like above? I am a bit confused here because the find() method involves more work to retrieve the DVD than the getDVD() method. And moreover if as we are finding the DVD using the upc number, I think we can directly call the getDVD(String upc) method instead of find(String query) method. Please clarify if I'm wrong.
Thanks Max. Appreciate your help and patience.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Well, there are two views of this.
In one view, you're increasing the number of methods on the object(and hence, complexity) in order to achieve an increase in performance, even though performance is a non-issue in this project .
Alternately, you're adding a specific method, which clarifies and focuses how the methods on the object are used.
Both are defendable. We just went one way: you may choose to go another.
Al best,
M
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Max, I really appreaciate your patience in clarifying.
Thanks alot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Max. Denny's DVD Project: GUIController class doubt
 
Similar Threads
Locking issues in Max's book sample project - Denny's DVD store
We should wrap delete/create/update in lock/unlock ?
locking in Denny's DVDs example
Max. Denny's DVD Project: DVDDatabase class doubt
NX: URLy Bird 1.3.1 Connection Factory Design