Pergunta

I have a form where you can create an order and when you save it, is checking in the database (using oracle) for the last order number and is assigning the next one to the currently saved order. What I found is that if two users are saving a new order both in the same time or at few seconds apart, because of the connection speed my app is unable to assign different numbers for the newly two created orders. The problem is that both are checking in the same time the last assigned number and both orders get the same number..

I have some ideas but all of them have advantages and disadvantages..

  1. To have the system wait a few seconds and check the order number when the user saves the order. But if both saved in the same time, the check will be done in the same time later and I guess that I will end up with the same problem..

  2. To have the system check the order number (a check is run every time the treeview is refreshed) and see if it’s been duplicated and then let the user know via the treeview with some highlight, that it’s been duplicated. But if any documents are assigned to the order before the check, then I will end up with documents having a different number in the name and inside from the order to which is assigned..

  3. To have the system check all order numbers periodically and give one of the duplicates a new order number, but Here is the same problem with the documents as at #2.. And also might cause some performance issue..

  4. Assigning the order number when a user requests a new order not when he saves the order. I could have the system do Solution #1 along with this solution and recheck to see if the number is being used within the database and then reassign it a new one. Once again, if documents get assigned, someone has to go fix those.

  5. One way of possibly stopping the documents from being assigned to duplicates is that the user is only allowed put some of the information and then save it or apply it and it does the recheck of #1, and then if it doesn't find anything, allow the user to add documents. This part of the solution could be applied possibly to any of the above but I don't want to delay the users work while is checking the numbers..

Please if you see any improvements to the ideas above or if you have new ones, let me know. I need to find the best solution and as much as possible not to affect the user's current workflow..

Foi útil?

Solução

If your Order ID is only a number you can use Oracle Sequence.

CREATE SEQUENCE order_id;

And before you save the record get a new order number.

SELECT order_id.NEXTVAL FROM DUAL;

See also Oracle/PLSQL: Sequences (Autonumber)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top