• 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

Question on search/update

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on urlybird assignment. From the decribed assignment there is no primary key to identify a particular record. (I am assuming a hotel can have more than one room to be rented.)

I have folowing test case:
1. User performs search.
2. fetches search results.
3. Recoed from result is updated (says room is set as booked).

Updated record should be reflected in the dbfile. As mentioned since I have no primary I have to ensure that appropiate record gets updated.

Here is what I do. Every record entry in the dbfile has a number assigned to it. This is a sequential number which also defines the record location in the db. This also helps me in jumping directly to a particular record location (to perform read/write).

A deleted record also gets a number. As deletion does not remove a record from the dbfile. Record is just marked as deleted.

I have kept this assigned number as primary key till the database session is alive. This number is not stored in the database file (as format of file cannot be modified)

Questions:
1. Am I doing things rite? anybody has any suggestions??
2. In a concurrent user scenario, say 'A' & 'B' user performs search & yeild similar search results. I have taken care of concurrancy so there is no race condition. But say user A updates the record & save it. Now user B also perfoms some operation on same record as that of 'A'. Since search results are not locked, how should we handle this scenario? Actually 'A' has changed the state of a record & this is not reflected to 'B'. please let me know how should we handle this scenario??
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Archana,

1. I think it is ablolutely ok to use the "position" of the record in the database file as a primary key since there is no other option. Don't forget to document it in choises.txt

2. Google for optimistic locking vs. pessimistic locking. You can achieve optimistic locking by the following update scenario:

- db.lock(recNo)
- db.read(recNo) (check if there is the record is already booked, if so, throw an exception)
- db.update(rechno,.....)
- db.unlock(recNo)

Greetings
Romeo
 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, that it is not OK. Because recNo is an int and position is long. Unless you do some sort of conversion recno/(positionInFile/recordLength).
[ October 26, 2007: Message edited by: Pavel Kubal ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe, you can think about constraints instead of key fields. For example, you may assume that during creation of a new record, the same customer cannot make 2 reservations for the same day.
This time, you may also say in the assignment (at least in mine) there is such statement

... The system you're writing does not interact with these numbers (owner-customer id), rather it simply records them. ...


As you may guess, I am also in trouble about that topic
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Archana,

I’m using recNo as key as well.
RecnO is an int (in my assignment, might be different in others), and size is a long.
However: an int is large enough in this case.

About concurrency: in my application if a users wants to book a room (update a record), it reads the record again, to check if it is still available.

Herman

[ November 01, 2007: Message edited by: Herman Scheltinga ]
[ November 01, 2007: Message edited by: Herman Scheltinga ]
 
archana kher
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the input guys.

Record nos I am talking about are valid only till the database session is alive. For me its a int.

There is difference between record nos & record location. I think I have confused few of you above.

A record is set of sequential bytes. Record length is fixed.

To a record which constitues of fixed length bytes I assign nos. Which depends of its postion in the db file.

This assigned nos is primary key for me. So 1st record is just end of header length.

so if I have to read 1st record I jump to that location using this formula.

header_length + ((record nos - 1) *size of each record).

No record nos are stored in the db.

Guys please let me know if I am successful in explaining you the concept. This is very imp as I need to document the same.
 
archana kher
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
forgot to add, Herman thanks a ton, you solved my issues on search. I liked the idea!!! simple and sleek.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic