• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: methods problem in DBMain is puzzling me!

 
Light Wan
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


  •  
    Bob Reeves
    Ranch Hand
    Posts: 64
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 31
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 64
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 31
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic