If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Inventory Control

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-30-05, 11:06
JFercan JFercan is offline
Registered User
 
Join Date: Sep 2005
Posts: 4
Question Inventory Control

I need the following functionally on my program:

User1 starts order and takes 2 of product1 a into order.

User2 queries inventory for product1 while User1 is still adding products to his order.

I want User2 to see that we have (qty - 2) left before User1 commits his transaction.

I am using PostgreSQL which does not support Read Uncommitted isolation level. Is there a way to get this to work?

Thank you,

Fernando
Reply With Quote
  #2 (permalink)  
Old 10-01-05, 00:35
B Jarvis B Jarvis is offline
Registered User
 
Join Date: Sep 2005
Posts: 22
What happens if User1 leaves his/her order open for 24 hours?
Reply With Quote
  #3 (permalink)  
Old 10-01-05, 13:09
JFercan JFercan is offline
Registered User
 
Join Date: Sep 2005
Posts: 4
Smile

If the DB supports read uncommitted abandoned transactions are rolled back when they time out.

I have found that the solution when the DB does not supports read uncommited, which appearently is not a good thing either, what can be done is have a table that holds the quantity. You call this qty on hold. When user2 checks inventory you check the qty of the product and add the qty on hold and display this to user2. Then you can check the qty on hold table for entries older that your chosen time out and remove those.

I think this is the way to go.

Thank you and I hope this helps someone else.

Fernando
Reply With Quote
  #4 (permalink)  
Old 10-05-05, 15:05
rajiravi rajiravi is offline
Registered User
 
Join Date: Apr 2004
Location: Toronto, Canada
Posts: 249
Another way to do this follows. The assumption here is that once a user requests n units of product x, these n units become unavailable for any other user.

At the time the database is started, I would store the current inventory in a hash map with the product_id as the key and the number of units available as the value.

When any user requests n units of product p, I'd look into this hash map and check if there are at least n units of product p.

If yes, then in the hashmap, I'd decrement the available quantity by n and allow the user to order n units.

If no, then I'd tell the user that there are not enough items in stock.

This way, there is only one key for each product in the hashmap. The timestamps do not come into the picture, neither does the question of deleting rows from a table. You do not have to create a table unnecessarily.

Synchronization problems, such as those that occur when two or more users ask for the same product at the same time, can be handled relatively easily.

Hope that helps.

Ravi
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On