This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: methods problem in DBMain is puzzling me! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: methods problem in DBMain is puzzling me!" Watch "NX: methods problem in DBMain is puzzling me!" New topic
Author

NX: methods problem in DBMain is puzzling me!

Light Wan
Ranch Hand

Joined: May 15, 2002
Posts: 31
In my assignment(hotel version1.3.1, db-1x1.db), the interface DBMain provides these methods:
// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public int [] find(String [] criteria)
// Deletes a record, making the record number and associated disk
// storage available for reuse.
public void delete(int recNo) throws RecordNotFoundException;
// 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.
public int create(String [] data) throws DuplicateKeyException;
I have three questions:
  • Should the find method return records regardless of live records and deleted records . Or justly return live records mathching the criteria?
  • The comment of delete method said that "makeing the record number and associated disk storage available for reuse". What's this mean? Should I delete the record physically or justly set the record to a "deleted" record?
  • In the implementing of create method, should I first call find(data) to judge the data whether or not exists in the database? Like the following coding:



  • SCJP2
    Bob Reeves
    Ranch Hand

    Joined: May 01, 2003
    Posts: 64
    Hi Light:
    Based on my URLyBird assignemnt, I think the asnwers are probably:
    * Should the find method return records regardless of live records and deleted records . Or justly return live records mathching the criteria?
    Deleted records don't exist (RecordNotFoundException), and should not be returned.
    * The comment of delete method said that "makeing the record number and associated disk storage available for reuse". What's this mean? Should I delete the record physically or justly set the record to a "deleted" record?
    Set the DELETED flag.
    * In the implementing of create method, should I first call find(data) to judge the data whether or not exists in the database? Like the following coding:
    For URLyBird, it appears multiple identical records can exist. Your assignment may have the same trait. Just create.
    However, you don't show all your record's fields. so opinions may vary.
    Tx
    Light Wan
    Ranch Hand

    Joined: May 15, 2002
    Posts: 31
    Hi Bob,
    Thanks very much! I do agree with you about the question 1 and 2.
    For URLyBird, it appears multiple identical records can exist. Your assignment may have the same trait. Just create.

    In my assignement, there is no identical records existing in the db-1x1.db file, and method create(data) throws DuplicateKeyException. If I just create a new record at the end of the database file, at what condition will the DuplicateKeyException be thrown?
    Regards, Light
    Bob Reeves
    Ranch Hand

    Joined: May 01, 2003
    Posts: 64
    Hi Light:
    My assignment has the same create with DuplicateKeyException. When and if the exception is ever thrown depends if you believe there really is a key that must be unique. The URLyBird database only has fields that reflect room attributes (price, capacity, etc.). A hotel could have multiple rooms to list, so there could be identical records in the database. Thus, my opinion is that the exception is NEVER thrown in my assignment. You need to pursue a similar reasoning process. The important thing, I think, is to document your logic in your design document.
    Tx
    Light Wan
    Ranch Hand

    Joined: May 15, 2002
    Posts: 31
    Hi Bob:

    Thanks you remind me to document my logic in the design document.

    Best regards, Light
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: NX: methods problem in DBMain is puzzling me!