• 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

About create new record number for URLyBird

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instruction document mentions that :
"2 byte flag. 00 implies valid record, 0x8000 implies deleted record"<BR>
A>Does that mean I can use this 2 byte to store record number I created in program? and persist the change into *.db file?

B>In the operaion process of the application, could I persist data changes caused from users' create, update, delete operation into *.db file?

Because I find out that code in Denny's DVD project of book "SCJD Exam with J2SE 5" really persists the data.

Thanks for the replying.
[ May 12, 2007: Message edited by: Vince Chen ]
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vince,

If you use the search button, then you find already the [i]Yes[\i] for your first question. For sure, you can use zzwo bytes.

For the second question I think that you must make the changes persistint to pass the exam.

I have never thought not to do is. That is why I want to know why you think that you should not write to the database file. Looking forward to your answer.
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Instruction document mentions that :
"2 byte flag. 00 implies valid record, 0x8000 implies deleted record"<BR>

A>Does that mean I can use this 2 byte to store record number I created in program? and persist the change into *.db file?



In my case, I only read the "2 byte flag" to see if it is:
1. 0x8000 - i.e. deleted, OR
2. 00 - i.e. not deleted.

-whenever I create a new record (possibly by using a deleted record - i.e. marked 0x8000,) I change the value to 00 - undeleted. That is the only situation that I write into the "2 byte flag".


B>In the operaion process of the application, could I persist data changes caused from users' create, update, delete operation into *.db file?



Everyone persists their data to file. Don't know if you have any reasons for not doing that though. We'd all surely want to hear a good argument of why you wouldn't.
[ May 12, 2007: Message edited by: Bod Toki ]
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Instruction document mentions that :
"2 byte flag. 00 implies valid record, 0x8000 implies deleted record"<BR>
A>Does that mean I can use this 2 byte to store record number I created in program? and persist the change into *.db file?

B>In the operaion process of the application, could I persist data changes caused from users' create, update, delete operation into *.db file?

Because I find out that code in Denny's DVD project of book "SCJD Exam with J2SE 5" really persists the data.



If I understand it well your question is:

A) can I use the place to store the delete byte to store a record number?

Personally I would not do that. First of all, I think you don't need the record number. Secondly, I think we can be quite sure that Sun didn't think of this when describing the use of that field. However, the assignment does not use the word "MUST" here, so if your sollution is good, I don't think it will cost you points.

B) I think you are asking here: can I update the delete flag byte here with a record number in case of updating an existing rec? Is that correct?

Then, I think the answer would be: update them all, or don't update them. Again, I don't think you need that, and personally I would not do that, but there is no "must" here...
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With regards to the first question I would only use the two byte flag to mark files as deleted or available. As the records are of fixed size this implies that Sun intend for you to use the position in the file of a record as the basis of the numbering of records.

I am afraid that I do not really understand what you mean by the second question, we should always persist all action to the db file whenever an operation is carried out.
 
Vince Chen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank all you reply. Does that mean if i do use record number, record number will only be generated in memory while loading and initilizing *.db?
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vince Chen:
Thank all you reply. Does that mean if i do use record number, record number will only be generated in memory while loading and initilizing *.db?



There is no need to generate the record numbers during initialisation. To find the position of a record you would use the following formula for fixed size records.

int position = (file_header_size_bytes -1 )+ ( record_number * record_size_bytes)

suppose for the sake of example the file header size is 100 bytes and the record size in the file is 40 bytes then

position record #0 = 99 + ( 0 * 40) =99
position record #1 = 99 + ( 1 * 40) =139
position record #2 = 99 + ( 1 * 40) =179

Hope this helps:

Regards,
Mark.
 
Vince Chen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all you reply. But I have another question:
In my DBAccess.java , it desrribe that:

// Creates a new record in the database (possibly reusing a
// deleted entry). Inserts the given data, and returns the record
// number of the new record.



If I first choose to reuse a deleted entry while creating a new record each time, should I use record number of old deleted entry, or directly generate new record number whatever reuse deleted entry or use new entry?
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Creates new record means reuse deleted record no (xyz) and return xyz same record number. If you don't find any deleted entry return new record number i.e. current max record number + 1
 
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic