• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CriteriaFind() location

 
luis veron
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Guys, I'm struggling on the idea on how to define the CriteriaFind method (implementation) that we need to introduced. I was thinking of using the randomaccess File inside this method but I noticed that the file(object) is declared as private in my Data class. Should I add the Criteria find in my Data class? I think this is not the best way to implement it.

Also let's say we book 2 seats, we need to follow the lock, read, modify, unlock sequence. Which means we need to invoke this method to change the randomaccessfile.
public synchronized void modify(DataInfo newData) throws DatabaseException {
.
.
}
Am I right on saying we need to use the modify() method to change the db?
Can you give me some light here. Really appreciate your help.
Thanks
[This message has been edited by luis veron (edited March 19, 2001).]
[This message has been edited by luis veron (edited March 19, 2001).]
 
Aron J. Skantz
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luis.

I don't know about the specification of your assignment, but mine is pretty clear on that the criteriaFind should be placed in Data. In my opinion this is also the best place to have the method since if you implement it to use any criterias (and not only ORG and DEST) then it will be as generic as the rest of the Data class, making it reusable. It is also tightly connected to the database functionality and i see no reason to move it.
We have already been given the code for the find(..) method and it can provide a hint on how to implement criteriaFind using the methods in Data and not the RandomAccessFile object directly.

modify(..) modifys the database and thus provides a nice way to update it to reflect booking...

\Aron
 
luis veron
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Aron,
Your reply has given me some light. I read through the documentation and made me clear some things. Sometimes it takes a bit of cue to understand and learn. Regarding the modify method, I am still a bit confused since in my specs, it mention a line saying lock, read modify, write, unlock... Why do we need the modify then write..In my understanding to be able to update the book number, use the modify() method..Within the modify() method, It uses the method in the randomaccess object to update(write) the record.
Does it makes sense?
Thanks.
 
Aron J. Skantz
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes it makes sense to me Luis.
I interpreted the line read->modify->write to be equivalent to read a record, modify it in code and write it back.
The method provided to overwrite an existing record is modify(..), which then corresponds to the "write" part of the instructions.
\Aron
 
Chris Lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I got a better idea for implementing criteriaFind. Why don't we just use getRecord to return a DataInfo object, and then compare string value of the DataInfo with the criteria. I think this is a high-level way to implement criteriafind. What kind of search algorithm are u guys using? For now, I think the easiest way is to loop thru all records and compare values of each record, do you guys have better and more efficient ways of searching?
Thanks
 
luis veron
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,
I think what you mention is correct. Another way is, if were going to change the Data class and add the criteriaFind in that class, we can manipulate (read only) straight away like what getRecord() method is doing. Then return an array of DataInfo.
Regarding the search, I will just make a read through on all the record.. the Data class doesn't provide better means to read through the record. What we can do to improve this search maybe based on what I have read in one of the post is, just to consider to process(compare) the field name passed from the criteriaFind.
Any other Algo?
Thanks,
Luis
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic