Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About reading in records and valid flag

 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i read in all records in a DataInfo[], i keep all information in there of all fields except valid flag. I can pass the DataInfo[] directly to the Jtable etc. to build it up. But however for all actions in the Dataclass i use the random access file, so even for getData() i read all records in again to get the most recent data. Can i do this have a DataInfo[] to pass the records around in the application but for all actions go directly to the random access file?
Thanx a lot for the help!!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ricardo,
Welcome to JavaRanch.
I think what you are suggesting is having the data cached on the server. There are a number of members of this forum who are doing exactly that - read the entire database into the cache, then whenever clients do any reads or searches the data is taken directly from the cache. When clients do any updates, the cache and the physical file are updated.
Regards, Andrew
 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i've been checking some posts and here is what i think :

There are two cases to consider for a record. Either
1) the record is marked as deleted
2) the record is valid (not marked as deleted)
If 1, then you're throwing the RecordNotFoundException, right?
If 2, then you're returning a record in String[]. The fact that you return a record and did not throw the RecordNotFoundException indicates that the record must have been valid. It's never valid to read a record that is marked for deletion (that is, a non-valid record), is it?

Ok so you allways check if the file is deleted in the raf.
But now my question:
If you delete a file in the raf you remove it from your cache, so you make sure your cache is only valid records. But then your recordnumbers do not correspond with the position of a record in your cache because you only have valid records in cache and the same recordnumber can be a deleted record in your datafile. Or do we have to read in all records again after update/delete?
Could you also say that for passing the information aroun i can use the DataInfo[] just for purpose of being more clear than a String[]?
I am really stuck on this one and other posts didn't help me, so can someone please help me out?
How to deal with this??
[ March 30, 2004: Message edited by: Ricardo Estafan ]
[ March 30, 2004: Message edited by: Ricardo Estafan ]
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ricardo
Originally posted by Ricardo Estafan:
Well i've been checking some posts and here is what i think :

From point 2 above, that's right. Its never valid to read a record that is already marked for deletion.

Ok so you allways check if the file is deleted in the raf.

Record is deleted and not the file. So you check if the record is deleted or not in the specified file.

But now my question:
If you delete a file in the raf you remove it from your cache, so you make sure your cache is only valid records.

Same as above. We use one datafile only. Its the file we have to read and update records from. We check for record validation and not file validation each time.

But then your recordnumbers do not correspond with the position of a record in your cache because you only have valid records in cache and the same recordnumber can be a deleted record in your datafile. Or do we have to read in all records again after update/delete?

You can deal this issue in different ways. As each record is represented by a unique record number, what you can do is you can cache the record numbers(instead of complete records). Each time a delete/create happens you can update the cache for record numbers for the available records. But to change the record, you have to do it physically in this case as you are only caching record numbers.

Could you also say that for passing the information aroun i can use the DataInfo[] just for purpose of being more clear than a String[]?

I think if the return signature of read method is String [], you have to use it. In all other cases, its really upto you how you do it.

I am really stuck on this one and other posts didn't help me, so can someone please help me out?
How to deal with this??
[ March 30, 2004: Message edited by: Ricardo Estafan ]
[ March 30, 2004: Message edited by: Ricardo Estafan ]
I tried to answer from what I understood from the questions. If its not clear, please let me know.
Good Luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic