File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S:understanding of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S:understanding of "search the data for all records" and create record" Watch "B&S:understanding of "search the data for all records" and create record" New topic
Author

B&S:understanding of "search the data for all records" and create record

lambertlee Li
Ranch Hand

Joined: Dec 15, 2005
Posts: 52
Hi, there,

How are you guys interpret the "search the data for all records"? I thought my understanding if wrong as I implemented this "search all" as returning all the records(including those marked as deleted ) to GUI from database. And I have an extra column on GUI called "Status" telling client that is record has been "deleted/active". How do you guys think?

One more issue is the create() method, when try to insert a new record into database, which solution you guys choose? Assume (primary key)=name+location,

(a)check for all the active records(those record with deleted flag=0), if no same(name+location) exists, insert this record,else throw DuplicateKeyException.

(b)check for all the records (regardless of deleted flag), if no same (name+location) exists, insert this record, else throw DuplicateKeyException.

Thanks!
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
records marked as deleted no longer exist so should not be returned.
The clients don't need (or even want) to know whether the database engine merely marks them as deleted or actually wipes them.
To them a record that's marked as deleted in the database is as nonexistent as one that never existed in the first place, it's simply not there and might as well never have been there at all.


42
lambertlee Li
Ranch Hand

Joined: Dec 15, 2005
Posts: 52
Jeroen,

thank you so much! So like what you said in your post, you will surely go for solution (a) when creating a new entry in the database, right?
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Originally posted by kaymen ji:
Hi, there,

How are you guys interpret the "search the data for all records"? I thought my understanding if wrong as I implemented this "search all" as returning all the records(including those marked as deleted ) to GUI from database. And I have an extra column on GUI called "Status" telling client that is record has been "deleted/active". How do you guys think?

One more issue is the create() method, when try to insert a new record into database, which solution you guys choose? Assume (primary key)=name+location,

(a)check for all the active records(those record with deleted flag=0), if no same(name+location) exists, insert this record,else throw DuplicateKeyException.

(b)check for all the records (regardless of deleted flag), if no same (name+location) exists, insert this record, else throw DuplicateKeyException.

Thanks!


I don't throw a DuplicateKeyException in my implementation at all. I think that the name and location is not specific enough to be a primary key. Is it not quite likely that a hotel that urlybird provides a late booking service to has more that one room on a given night (or the same room on different dates).

Regards,
Mark


SCJP<br />SCJD
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Originally posted by kaymen ji:
Jeroen,

thank you so much! So like what you said in your post, you will surely go for solution (a) when creating a new entry in the database, right?


No.
You do NOT supply a record ID when inserting a record. The actual record ID is instead the place at which the record was inserted.

First I check if there's an empty slot in the file.
If there is I use that and remove it from the list I keep of empty slots (for performance reasons when reading).
If there isn't I create a new record at the end of the file.
 
jQuery in Action, 2nd edition
 
subject: B&S:understanding of "search the data for all records" and create record
 
Similar Threads
NX: DuplicateKeyException for records without keys!? *blink*
RecordNotFoundException and unlock
B&S: How to create a new record, when identical record exist but marked as deleted?
nx: All of URLy Bird 1.1.3 read/write lock(2)
No definition of what is a DuplicateKeyException