Bably Das

Greenhorn
+ Follow
since Sep 17, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bably Das

With great pleasure I would like to declare that I am a SCJD now
It took me almost a year to finish off the assignment as I had many months of absolute no work on the project due to personal reasons.
Being a junior Java programmer the project was challenging but all the help I got from this forum made it possible.
I would like to thank everyone on this forum specially Andrew Monkhouse for his great book, Roel and Roberto for all the help they provided me during my journey of being a SCJD. Roberto's database file reader tool, the locking test class and then Roel's ant file to wrap up the project were an absolute life saver as I rushed to submit my project on my 1 year deadline date .
People still contemplating on doing the project specially junior Java programmers should just go ahead with it as it makes one learn a lot and I got my dream job offer too thanks to the project!
Best of luck to people still working on the project.

Once again thanks a lot to all the great people who are selflessly helping others on this great forum.

Regards,
Bably Das
13 years ago

No need to worry



Thanks Roel for the confirmation
Thanks Roel for the reply. Yeah being new to software development world I was a bit confused about authentication and validations. I am doing the following validations:

1. Port number - allowing user to enter only digits upto maximum of 5 and then checking if the number entered is between 0-65535.
2. Database location - If a file exists in the location specified by user and can be read and written to. I decided not do any validations on the magic cookie.
3. IP address - if it is in the correct format ie, A valid ip-address must be in the form of xxx.xxx.xxx.xxx, where xxx is a number from 0-255.
I have decided to stick to ip-address as I found it difficult to validate the host name, hope thats acceptable.
4. customer id - A user can enter only positive numbers in the customer Id field and that must be 8 digits for it to be accepted as a valid customer id.

Hope thats sufficient to pass.
Thanks,
Bably Das
Hello,

Just wanted to know if it is really necessary to validate the database path, port number and ip address in the assignment? I have a line in my assignment which says -

No authentication is required for database access.



My deadline is approaching so wanted to be sure if I can pass without doing it?

Thanks,
Bably Das
Thanks all for your replies.
I fixed the issue but realised that I had not posted back.
So a null Room object denotes a deleted a record in my cache. I write the deleted record with spaces for all its fields and the deleted flag set as I am reusing the deleted recNo to create a new record and needed a way to persist the deleted record back to the file.
While reading the database file I am converting the database record to a Room object as I prefer working with a Room object, I check for the valid/deleted flags and if a deleted record is found, it is just added to the cache as a null Room object. This way I no longer have spaces for a null Room object which was actually my mistake in implementation. Now I always have valid records in my business and GUI layer and hence no more gaps in the JTable.
I hope this approach is valid.

Regards,
Bably Das

How can a null object have spaces in all fields?



This is exactly what I am doing -
While deleting a record in my Data class, I set the Room object to be null. While writing back the deleted record to the .db file in my DBFileAccess class, I write the length of the bytes for each field


After writing the bytes I again set the Room object back to null in the DBFileAccess class as I found out after I write the bytes the Room object is no longer null but has spaces for all the fields, hence I cannot reuse the recNo for creating a new record. Setting the Room object back to null makes it possible to reuse recordNos and while viewing a deleted record in the JTable I found that it contained spaces, hence the check on spaces.

I am really confused now as I thought I was doing the right thing

Thanks,
Bably Das


Thanks I have solved the problem by doing an additional check for spaces in all fields of a Room object apart from doing a check on it being a null object.
Simple JUnits were enough to solve the problem. I am sticking with a Room object as I find it easier to work with. Have justified about it in choices.txt, so I think that should be fine.

Cheers,
Bably Das
Hello,

I just wanted to confirm if its alright to have gaps in the JTable for deleted records?

For eg, there might be a situation where I have in my map record with recordNos 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 (Size is 10, starting with a zero "0" index)
and records 3, 5, and 7 have been deleted, therefore in the JTable only 7 records 0, 1, 2, 4, 6, 8, 9, will be displayed.

So in my case there is gap for the other records as in my cache I am making the Room object null and while writing back the deleted record to the database file I am filling the fields with spaces equal to field length apart from setting the flag to that of deleted. Is this alright?

Thanks
Bably Das
Thanks Roel and Seetharaman for your replies. I have now got a clear understanding of how to deal with both type of exceptions. I will get back if I have more doubts.

Regards,
Bably Das.
Hello,
I am refactoring my code and am in a mess in dealing with Exceptions in the correct way.

1. My read method throws a RecordNotFoundException which I created as a checked exception Do I need to catch the RecordNotFoundException in the read method itself if the record is not valid or simply stay with the throws clause and deal with the exception in the next layer - the business logic layer and again wrap the exception till it reaches the GUI layer when I actually deal with it? Shouldn't my Data class also work perfectly on its own displaying the exception messages as and when they occur?

2. While accessing the database file I throw IOExceptions and simply have wrapped them in my custom runtime exception - DatabaseException. So how do I deal with the DatabaseException in the next layer, as being a runtime exception it doesnot have to be caught?

Thanks,
Bably Das

As always thanks a lot Roel for your quick reply.

The only question I can think of: why using a cache if you write each time to the database file?



Being a junior Java programmer myself I find working on a cache easier than the actual file itself.

Thanks,
Bably Das
Hello,
Is it possible to use a cache for the assignment and not to implement a shutdown hook. My approach is-
I have a DBFileAccess class with two method to load the database records into a cache and a persist database method to load the cache into the database file. For this, in my load Database method -


For persist Cache to Database file


My Data class is Singleton, with all methods synchronized and at application startup, in Data class private constructor, I call the loadDbRecords from the DBFileAccess class.
After each update, delete or create operation I persist database records back to the file instead of persisting records at the time of server shutdown. My server shutdown is simply System.exit(0) as my RandomAccessFile is closed after each read and write. Is this a valid approach to pass the exam? I know there will be slow performance issues but as it is not a criteria in this exam, can I overlook it? Any advise in this direction highly appreciated.
Thanks Roel for your quick reply.
I am completely happy with the 1st and the 2nd points you mentioned and have implemented them. But unsure about the third. I have gone thru the link you provided.

3/ I don't think this behavior is related to the locking method. It means your business logic to check if the room is already booked is working. The lock method of the Data class has another purpose which is described excellently in the ScjdFaq.



My book method does lock -> update -> unlock. Just wanted to confirm that if my lock method is working as per Roberto's lock test class, is it a certainty that my locking and unlocking mechanism are working as desired?

Thanks,
Bably Das
Hello all,

My problem is that I start the server and two client windows simultaneously. So in one client window I select a room and click the book button to book that room. The customer Id entry dialog is then displayed and I enter a 8 digit number to book that room.

In the second opened client window I do the same, that is, book the same room but with a different customer Id. Right now when I click the "Book" button in the second client window, the customer id entry dialog is displayed and when I enter a different 8 digit customer id, my JTable is refreshed with the old value of the customer Id as I entered in the first opened client window for that room. So my questions are:

1. Once the room is booked in the first client window how do I refresh the JTable data in the other opened client windows?

2. Where do I need to throw the RoomAlreadyBookedException and an error message to notify the second client that the room he/she is trying to book is already booked by the first client?

3. If the value of the customerId stays as entered by the first client for n number of clients, is my locking method working as expected?

Many thanks,
Bably Das
Thanks Vlad for your replies. My lock method clearly states that

// Locks a record so that it can only be updated or deleted by this client.
// If the specified record is already locked, the current thread gives up
// the CPU and consumes no CPU cycles until the record is unlocked.



So the requirement to check what happens if the same client locks the same record twice or tries to lock another record is not explicitly mentioned. Like you I am also working on the gui/rmi part now and will have to come back to locking again. I guess I will throw an IllegalStateException for these conditions and explain them properly in JavaDoc/choices.txt but still need to think more on these situations.

Thanks again for all your time and help!

Cheers,
Bably Das