• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[B&S] how to check the records

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know many of you use a ArrayList to store the locked record numbers.
As we need to throw RecordNotFoundException in many methods, I'm wondering
how to check the available records. I'm thinking about to use another
ArrayList to store all the record numbers, then I can check it in each method.

Another question, do I need to check if a record is in the locked-record Arraylist in "lock" and "unlock" method? Because there already has an "isLocked" method, I can call it before I call "lock" or "unlock".


public int [] find(String [] criteria)throws RecordNotFoundException;

public void lock(int recNo) throws RecordNotFoundException;

public void unlock(int recNo) throws RecordNotFoundException;

public boolean isLocked(int recNo)throws RecordNotFoundException;

 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether you need to check if a record is locked whenever reading it depends on your database engine design.
If you require a lock to read you need to check that, if you don't you only need to check that when writing or deleting a record.

The RecordNotFoundException is thrown only when a record doesn't exist.
That means the record number is impossible (beyond the end of the table) or belongs to a record that was deleted.
Both can be determined on the fly as it were.
I've created a method to set the file pointer to the correct position based on the record ID. That method returns false if an attempt is made to position the file pointer beyond the last existing record, true if it was successfully positioned.
The calling method simply throws a RecordNotFoundException if that method returns false.
Then on read I check the delete flag and throw a RecordNotFoundException if it is set.

I've created a little helper method "exists(int recordId)" to encapsulate that behaviour, which returns false if either the record is beyond EOF or has the delete flag set.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic