• 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

Where does recordNumber come from?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't find the field recordNumber in the binary data file created by the data convertion tool, where does this field come from?
in Data class, in the find(String toMatch) method,the comment says toMatch is the key field value to match upon for a successful find, for this assignment, the key field is the record number field. In the find method body, I think the Flight number field is compared to the toMatch parameter, not the record number is compared to toMatch,am I right?
another question, why isn't the writeRecord method sychronized?
Could you help me please? thanks!!
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi neo,
You are correct in saying that recordNumber is not in the binary data file. In fact, you don't need a record number to be written into the binary file. The reason behind this is : record number just acts like a reference variable to locate a particular record in the data file.
If you take a close look at the seek method in Data class, you will notice that seek method uses the record number to caluculate the position of the record in the data file.
You next question, why is write method not synchronized. This is because write methods access modifier is private and it is called by add method which is a synchronized method.
Satish
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to say I disagree with you if your assignment is exactly the same as mine. If you look at the comments of the find(String toMatch) method of the Data class, it clearly says "For this assignment, the key field is the record number field". So you have to write the record number to the binary file as the first field.
Robert
 
Satish Kasala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me ask you these.
1. What does getRecord(int recNum) return ?
I think it returns a DataInfo object that already has the record number. So you don't need to define explicity a record number in the database.
If you differ on the answer I would be glad to here from you.
2.How does the getRecord(int recNum) know which position to seek depending upon the recNum?
I think it calculates the position of the record to read.
The comments surely says that "Record Number is the key for this assignment". I think what they mean by this is the Flight number would be the key. I agree comments are somewhat confusing.
Another instance of not so correct comments is
"@param recno The record number to lock" in the lock method. You can see that lock mehtod takes in a record or recno. but they essentially mean the same thing.
And one more comment I want to make is about the first field that is written to the binary file is whether the record is Live or Not but not the record no.
Hope we can resolve these issue. Any help on these is appreciated
Satish
 
neo zhang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish and Robert,
thank you for your answers.
I can't quite agree with Robert's point : "So you have to write the record number to the binary file as the first field. " If you write the record number to the binary file as the first field, you must change some methods in the Data class to acomplish this, I think it's unnecessary and brings trouble.
I still don't know how to deal with the parameter in the find(String toMatch) method. How do you deal with it?
Satish, what do you mean by :" And one more comment I want to make is about the first field that is written to the binary file is whether the record is Live or Not but not the record no."?
neo
 
Satish Kasala
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
what I mean by the comment was : The first field in the binary data file is meant for determining whether the record is a LIVE record or DELETED record.
when you delete a record to change the value of the first field to 0.
Hope I answered your question
Satish
 
robert zhang
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you don't need to modify any method of the Data class even if you use the record number as the first field of each record in the binary file. That's how I did it. You just need to put the record number as the first field when you write your data conversion tool. I haven't got the results of my assignment from Sun. But I really don't think it is that big a deal if you think the comments for the find() method is wrong(I wouldn't count on it). As long as your project works, you will be fine. But it doesn't hurt to stick with whatever the original package says.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic