Like many people, i just bought my OCMJD voucher... trying to accomplish it before august 1st.
So yesterday i downloaded my essay and many questions are in my head... My project is the URLyBird, with "public long lock(int recNo) throws RecordNotFoundException;" interface.
After reading SCJD FAQ, related topics and ocmjd-paper-roberto-perillo.pdf (awesome by the way), i decided to start from DB interface and db-1x1.db file provided by Oracle.
Conclusions and doubts:
I used DBFileReader.java class by Roberto Perillo as kick off and see whats inside my .db file to design my VO(Room.java in my case) class;
Reading the instructions and studying the .db, i realized that there is no "record number" and no "primary key". But there is no record where Name and Location combination equals true, and since no insertion of data is expected i made both my "primary key". To do so, i @override equals method on my VO class to make sure of that(name.equals(this.name) == true && location.equals(this.location) == true), ignoring the other atributes;
I didn't see the need on @override the hashCode method here, since ill CACHE STORE the records on a List and my LOCK CONTROL will be Map<Thread.ID,Room>, so i didn't;
MagicCookie and the long longCookie attributes are not the same thing. MagicCookie will be used only to compare to a static final variable on my Data class to make sure the .db file is valid;
DB Interface:
I will use RandomAccessFile to seek and read/update records. Thats the only way the argument "int recNo" of DB interface make sense to me;
I concluded the arguments "int recNo" is the position of the record on my List object, and when i need to update the .db file i seek to headerBytes+recNo*bytesRecordLength then write;
I also concluded the "long lockCookie" argument is the Thread.ID from my Map<Thread.ID,Room> to identify the thread holding the lock of that Room object;
I need a utilitary class to transform String[] records to VO and vice-versa;
Now some comments about instructions:
"Data section. Repeat to end of file: 1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record "
// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void delete(int recNo, long lockCookie)
I didn't understand this part, what delete means here? Because all records have this field empty on db-1x1.db(so, all records are valid).
And again, is my conclusions about recNo and lockCookie right?
Do i have to implement this method? Instructions only ask for search and update.
User Interface
• It must allow the user to book a selected record, updating the database file accordingly.
• It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.
A null value in criteria[n] matches any field value. A non-null value in criteria[n] matches any field value that begins with criteria[n]. (For example, "Fred" matches "Fred" or "Freddy".)
public void update(int recNo, String[] data, long lockCookie)
Here i assume that i must provide a checkbox to allow And/or searchs and filter using .startsWith(String);
Do i have to update the .db file everytime i execute the update() method?
The search of data can be done only on the List i loaded at startup or i must re-read file and re-load List before?
-------------------
About architecture:
Im thinking about making my Data class a SINGLETON with static List for records and static Map<Thread.ID,Room> for locks, to make sure the same object is shared among all clients;
A VO named Room to map records entrys and transit between layers;
Make a Service interface that will be implemented by StandAloneServiceImpl, RemoteServiceImpl and ClientServiceImpl, and make it the only access point the Data.class;
Read .db file to load List at startup without locking and only if my static list is null;
Use Lock only on the record i want to update or delete, leaving .db file available to other threads;
I don't need to control concurrent access to .db file;
I don't need to synchronize methods because of the lock()/unlock() mechanism on Room object;
The Room.java VO implements serializable;
Problems to solve:
How to use and set the startup parameters(server or standalone or client) to instantiate classes;
How to share the Service interface with all running modes, because of different parameters(.bd location, hostname, port);
If is it viable to use the same classes from Service interface to Data.class to db-1x1.db file, since Data class is singleton;
Do i really need to implement serializable on my VO class? Since i write String[] object to the file;
-----------------------
Well, thats what i get so far...
I have to study about the RMI implementation.
Im having trouble to figure out the middle of my application, where i have to combine the 3 different interface implementations(standalone, client and server).
Please tell me if i'm asking/saying anything that is inapropriate, so i can remove it.
Thank you!
Pedro.