• 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

nx:All of URLy Bird 1.1.3 about delete and update method

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George: about the delete method
the instruction say:


// Deletes a record, making the record number and associated disk
// storage available for reuse.
// Throws SecurityException if the record is locked with a cookie
// other than lockCookie.
public void delete(int recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;


from this situation,i will implements it and ask you some questions:
my implementation:

I have some questions as follow:
1: You can see:i use read() of Data class in delete(),Am i right? or i use direct reading from database file?
2: In this delete method there are two synchronized blocks. one in read of Data class,another in the delete method.Am i right?
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun

Originally posted by liqun chang:
Hi George: about the delete method


I do not understand why you are reading the record in the delete method. All we need to do in this method is to set the deleted flag to 1 implying that the record is deleted.

I have some questions as follow:
1: You can see:i use read() of Data class in delete(),Am i right? or i use direct reading from database file?
2: In this delete method there are two synchronized blocks. one in read of Data class,another in the delete method.Am i right?


Can you please explain of why you are reading the record that is supposed to be deleted? That way it will be easy to answer. Now all I can tell you is in this method, we seek to the record starting physical posistion in the db file using maybe seek of RAF and then write 1 there. That is all we have to do. Atleast that's what I think we have to do and am doing the same.
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish glad to meet you and thanks for your responding.

you say:

Can you please explain of why you are reading the record that is supposed to be deleted? That way it will be easy to answer. Now all I can tell you is in this method, we seek to the record starting physical posistion in the db file using maybe seek of RAF and then write 1 there. That is all we have to do. Atleast that's what I think we have to do and am doing the same.


the instruction also say:

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file



My meaning is to read record and see whether the record validate and throws
RecordNotFoundException,in this situation,simply reuse read method in Data
class can approach.or i can directly access the database file and judge flag
.Am i right?
Hi George,you can see:the purpose of delete is write deleted flag to database file,but this method require throws RecordNotFoundException,so i must read record and judge whehter the recNo already has deleted flag or
doesn't exist in database file.Am i right?
or you have another method?
[ March 11, 2004: Message edited by: liqun chang ]
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun

Originally posted by liqun chang:
Hi Satish glad to meet you and thanks for your responding.
My meaning is to read record and see whether the record validate and throws
RecordNotFoundException,in this situation,simply reuse read method in Data
class can approach.or i can directly access the database file and judge flag.Am i right?


Here's what Sun says:


Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.


What I interpret from the Sun's given statement "if a specified record does not exist" is this:
If you are using recNo to locate the record in the file, then if say your db file length is 400, then a recNo value of 460 should throw RecordNotFoundException.
And from "is marked as deleted in the database file" this is:
As you know, if a record is already deleted we cannot delete it and so the method should throw RecordNotFoundException.
Also this is not a must requirement, it just suggests that it should throw. However, here is what I am doing.
cookie = db.lock(recNo);
db.delete(recNo, cookie);
db.unlock(recNo, recNo);
I check whether the record is there are not in the lock method only if not throw RecordNotFoundException. As am doing record locking, now if the record is locked, it means record is present then only am doing delete right. So I think it should be OK.
If you have any questions, please ask them. Good Luck.
 
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,

Originally posted by liqun chang:

My meaning is to read record and see whether the record validate and throws
RecordNotFoundException,in this situation,simply reuse read method in Data
class can approach.or i can directly access the database file and judge flag
.Am i right?

Well, you could do it that way, but you'd be doing more work than necessary. I agree with Satish, all you need to do is read the validity flag (which conveniently is at the beginning of each record). So I would recommend that you read only the validity flag rather than the entire record. If you want to reuse code there's an opportunity to factor out the code that reads the validity flag. This readValidityFlag method could be used in all sorts of database methods (read, delete, update), basically any of the database operations that can throw the RecordNotFoundException.

Hi George,you can see:the purpose of delete is write deleted flag to database file,but this method require throws RecordNotFoundException,so i must read record and judge whehter the recNo already has deleted flag or
doesn't exist in database file.Am i right? or you have another method?

I would use similar reasoning to that in my previous response. As Satish said you only need to write the validity flag to mark a record as deleted. So you might want to create a writeValidityFlag method that writes the valid or deleted value into the validity flag of the record. This method could possibly be used in the create method in the case where you're reusing a deleted record to store the newly created record.

 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish don't get angry because George is my best friend,and he always help me.That isn't real that i don't believe you,only because i meet you at
the first time.Say again,sorry for what i said.
and thanks for your response.
Hi George and Satish,according to your suggestion,i will change my delete
method as follow,see whether i understand your statement.
delete method:

Am i right for previous code?please tell me.
 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George,i find that the delete method is similar to update method.
my update method implementation:


1: Am i right for update method?
2: I find that delete and update both write to database file,one write the
flag,another write whole record.Am i right?
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Liqun,

Originally posted by liqun chang:

1: Am i right for update method?

Yes. I think your test for the deleted flag can be simplified. I think there are some good opportunities for refactoring some of the code into small private methods (for example, seek(int recNo), readValidityFlag(int recNo), writeValidityFlag(int recNo, boolean flag), and possibly others you might discover as well). I think these comments apply to the delete method too.

2: I find that delete and update both write to database file,one write the
flag,another write whole record.Am i right?

Yes, absolutely. Also the create method, right?

 
liqun chang
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi George:i want to ask you the right of my design diagram.Could you give me you email address?thanks.because this forum don't allow to paste image.
The size of my design diagram about 16k.hope you check it and give me some
suggestion.This is my whole application architecture.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic