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

URLyBird - Initial thoughts / doubts

Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 140

Hi,

I just started my assignment (URLyBird 1.1.1) a few days ago. I think I will use the following approach:

Design:
=======
* Use a 3 layer architecture (GUI, business, DAO)
* Use a thin client
* Use no transfer / value objects at all in the suncertify.db package

Data class:
===========
* Mark all methods as synchronized and make it a Singleton
* Implement an extended interface
* Use a worker class for managing data (the record map) + use record cache
* Use a separate class that facilitates the locked records
* Identify clients by their thread id

Networking:
===========
* Use sockets...yeah really ;-)

GUI:
====
* I will keep it simple...no fancy stuff, as it doesn't give any extra credits


So for now, I have some small questions / doubts:

1. The instructions say that I should implement the used Exceptions in the provided interface (in the suncertify.db package). A zero and one argument constructor should be provided.

Well that's ok, but I want my exceptions to extend from a general DatabaseException, so that I can wrap all kinds of exceptions in this DatabaseException and throw it to the business layer. I think it's just legal that these exceptions (like RecordNotFoundException) extend from a base exception class (DatabaseException). Right?

2. Do I need some kind of synchronization / locking for the reading / writing to the provided database file? I will use a record cache, so at startup I will read the whole database and put the records in a Map. If the application terminates a shutdown hook will write the record cache back to disk. Only one thread will do this, so what precautions should I take?

3. What about the validation of the database file at startup? There are no must requirements specified about this, but I've read that almost everybody checks if the magic cookie value matches the value that is expected. That's cool, but it's a rather simple check and does not confirm that the records themselves are ok...
I guess the best thing to do is quit the application when the database is corrupt (also providing an message to the CSR)? The application doesn't work without a correct database.

4. What about the deleted property of a record? Use it in the Room transfer object? It's also in the record itself and makes it easier to write back the data to the file at application termination. On the other hand...it's a kind of flag indicating if a record is marked as deleted, so I don't see it as a 'normal' property...

Cheers,
Dennis


SCJP, SCWCD, SCJD
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Howdy, Dennis!

I think it's just legal that these exceptions (like RecordNotFoundException) extend from a base exception class (DatabaseException). Right?


Right. I did that too.

Do I need some kind of synchronization / locking for the reading / writing to the provided database file? I will use a record cache, so at startup I will read the whole database and put the records in a Map. If the application terminates a shutdown hook will write the record cache back to disk. Only one thread will do this, so what precautions should I take?


Hum... no. The usage of the locking mechanism is only required for updating/deleting records.

What about the validation of the database file at startup?


Well champ, it doesn't say that you have to validate anything... it is just said that the magic cookie identifies a file as being a valid file. I myself validated the file, and if it isn't a file with the same value as the one provided in the file I received (I think it is 256), then I display a message to the user.

What about the deleted property of a record? Use it in the Room transfer object? It's also in the record itself and makes it easier to write back the data to the file at application termination. On the other hand...it's a kind of flag indicating if a record is marked as deleted, so I don't see it as a 'normal' property...


Agreed. I didn't include it in my Room object. When I read it, if the record in the given position, then I put it in the map as records.put(recordNumber, null);. In this case, I also add the record number to a List where I have the record numbers that are available for using when I create records.

Now, you said that you won't use a TO in the .db package. When do you plan to transform from String [] to Room object?


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 140

Roberto Perillo wrote:Now, you said that you won't use a TO in the .db package. When do you plan to transform from String [] to Room object?


A client can call book and search in my business layer. There I use a Room TO. I'll make a mapper class in this layer to convert from TO <---> String[]
I think I also should put that TO in the business layer (and not in de db layer).
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Dennis Grimbergen wrote:A client can call book and search in my business layer. There I use a Room TO.


Ok, that's what I expected.

You know, one idea. For my assignment, I created a class called RoomRetriever, with two static methods, where one transforms from String [] to Room and the other one does the opposite. If it was today, I'd create a class called RoomAdapter, which would do this, except that the methods wouldn't be static. I think this would be more object-oriented.
Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 140

I have another question about the InterruptedException that can be thrown during wait() in the lock method.
I read some older posts about this and it seems good practice to restore the interrupt status in the catch block by saying:


But what should I do with the lockCookie I have to return from the lock method in this case? Return what value? Another possibility is wrap the InterruptedException in a RecordNotFoundException, but that seems weird and not the way to go...
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5126
    
  12

Restoring the interrupt status, is what I have done. I didn't had to return a lockCookie. I restored the interrupt in a finally-block, so it's always executed, even with a return

Note 1: in my assignment I didn't had lockCookies, so no need to return a lockCookie from lock-method.
Note 2: I deleted your duplicate post


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLyBird - Initial thoughts / doubts
 
Similar Threads
UrlyBird Questions
URLybird
Passed URLyBird 1.3.2 (400/400)
URLyBird data access
URLyBird passed