permaculture playing cards
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URLyBird - 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 "URLyBird -" Watch "URLyBird -" New topic

URLyBird -

John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
Hi all, I have a question regarding the class. Is it permissible to add new methods to the class? My implements which has the following methods..

So how do I read all records initially to populate the JTable in the GUI? I will not know the recNo that the read method requires. Is it OK to add a readAll method that will read every record from the database?

John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
Hi, I was thinking about a possible solution and came up with the following.
In my class I have the method . Now as I mentioned before, at startup I believe the user would want to see all records but as the software/user wont know anything about how many records there are or the individual record numbers, I will pass a -1 to the method and use this as an indication to read everything and pass the array of results back to the adapter class that calls into the class.
Any thoughts....
josine wilms
Ranch Hand

Joined: Jan 23, 2006
Posts: 45

Yes it's permissable to add methods to the Data class. It is not permissible to add methods to the DB interface.


SCJP 1.4<br />SCWCD 1.4<br />SCJD <br />SCEA (new version) Work in progress...
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
so what do you all think of my proposed solution to read all records from the database by passing a '-1' to the method to indicate that all records should be returned? As this method returns a String[], returning all records would not be an more difficult than returning one if the method was passed a non-negative number.
any thoughts???
what has anyone else done for the URLyBird exam???

many thanks
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
I followed a completely different approach. I simply implemented the the DBAccess interface in the Data class, I added a couple of helper private methods in order to refactor some code, but nothing new.

In order to get all records, I reused the findByCriteria() method by means of passing empty Strings. Now, this method just returns an array with the record numbers. You could go over that array and reuse the read() method to get the record.

That is why I am not using the Data class directly. I created a wrapper class that offers more business-aware methods that reuse the core functionality offered by the Data class. Among these methods in this wrapper class I offer functionality to get all records using the underlying findByCriteria() method.

Evidently using the findByCriteria() method to achieve this task has a drawback: the comparison algorithm is irredeemably invoked while fetching every record in order to check if the record matches the defined search criteria, since we are fetching all the records, every comparison will finish in match. So all records will match, and then we will have to perform a second read to get every matched record.

So, this approach implies two file reads and the execution of the comparison algorithm.

Probably an expensive alternative, but I did not want to offer any functionality that was not completely based on the interface provided by Sun.

In the approach you are suggesting, the problem is that you are actually violating the DBAccess interface contract. Your implementation is doing more than what the interface contract suggest.

If you find necessary to implement this method here, I'd rather suggest to overload the read() method, with no parameters, and return an array of arrays or a collection of arrays, or another kind of complex structure that you can come up with.
[ December 29, 2006: Message edited by: Edwin Dalorzo ]
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
thanks for the response, sounds like a more sensible approach. I was concerned about using the -1 as an indicator to read all records.

I agree. Here's the link:
subject: URLyBird -
It's not a secret anymore!