I understand this method of doing it and I understand the pseudo code too. I believe this code will be in a synchronized method that should be placed in a singleton object. The code validates information. One example validation could be getting current registrations for the course and seeing if there is place left for this new user to enroll in that course. If this method is not synchronized then two different users
could be in this same function validating their data and then they would try to register for the course too.


If the number of users using the system to register for courses is high this singleton object encapsulating this synchronized method, would e a bottle neck. Is there any other solution or is this standard implementation?

On Jun 21, 2004, at 12:54 PM, Jérôme Duval wrote:

Most commercial databases implement a solution to this problem since it is
fairly common. For MySQL, you must use the InnoDB engine (at least for now).
You use the concept of transaction. To do this, you must turn the AutoCommit
mode to off (some client have this mode off by default, some do not. Check
your documentation. If you are going through JDBC Connections are always in
AutoCommit(true)!). You must also set the Transaction Mode to
Transaction_Serializable which locks table so that no one else then you can
read the data in your tables.


The code looks something like this:

try {
        //Validate information
        //Add the record in the table
        //Bill the customer
        //commit transaction
} catch (SQLException) {
        //rollback the transaction cause something went wrong
} finally {
        //close the connection
}

Where you bill the customer is dicussable (it is related to the transaction
but does not require DB access). It's all up to you really. A couple of
things to notice:


- TRANSACTION_SERIALIZABLE is the most demanding mode for your database
server.
- If you forget even one commit() or rollback() you might lose data to
locking.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Mufaddal Khumri
Software Developer
Waves In Motion
Phone: 602 956 7080 x 26
Email: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to