I'm cashing the file into an ArrayList and to delete a record the first field is set from 1 to 0. However at some point there will be a call to readRecord where the Jtable will need to be populated and if it come across a record position that has been set to 0 it will throw a RecordNotFoundException. So to get around this problem I'll create a service class that will query Data for a list of active records and Jtable will traverse with this list getting an active record each time from readRecord.
If it fails to create a new record then maybe it could return -1 to denote a failed attempt.
Should all method in Data be synchronized especially if Data is to be a Singleton?
I have synchronized all methods and credit to Roberto's test my locking and unlocking seems to prevent deadlock.
I made the Data class a Singelton and the Data class is going to work with the file access, but now I cannot pass a db file and path name through it constructor. Would the solution here be to not make Data a singelton but keep all methods of Data synchroized?
Another point: I'm using a Hashmap to cash the data and I'm treating the recNo as a string. Is there anything wrong with this? should I make the key value a Long type?
In update and delete methods, I'm thinking of not throwing RecordNotFound exception because I have make the lock method to ensure that the data does exist or else it does not lock and it throws the RecordNotFound exception thus the method calling lock does not proceed with Update/Delete.
Final point: I'm thinking of making a file access class for data but Data itself is to controll the locking mechanism. Its not a complete Facade so what pattern would it be?
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
I made the Data class a Singelton and the Data class is going to work with the file access, but now I cannot pass a db file and path name through it constructor. Would the solution here be to not make Data a singelton but keep all methods of Data synchroized?
SCJP1.4: 96% SCWCD5: 91%
Matteo Palmieri wrote:The solution proposed by Roberto is good...
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|