M
Mark
Hi, I don't have a code problem. I have an understanding problem.
This is a made up situation that mimics my real situation but it is
easier to understand.
1. I call a web method with an account number and retrieve an employee
object called employee on computer 1 (user 1). The employee object
getFirstName() returns "Michelle".
2. I repeat the process on computer 2 as above for the same account
number using the same web method (user 2). The employee object
getFirstName() returns "Michelle"
3. (user 1) I call employee.setFirstname("Mary") and then I invoke
employee.save(). The web method is called and the database for the
employee is saved.
4. (user 3) I perform a SELECT statement in the database and can see
that the table now contains 'Mary'.
5. (user 2) I call employee.setFirstname("Margaret") and then I invoke
employee.save(). The web method is called but an exception is raised.
When I query the database it still shows "Mary".
This is the behaviour I want but I do not know how it works. If I was
using a database where I had a connection for each user this behaviour
is easy to understand. But as I am using a web method and there is no
explicit connection to the database, and each user probably uses the
same database connection, I don't know how it is done.
I think it must work like this but is this right?
"Employee carries around an old copy with itself, and before doing an
update of the database, reads from the database, compares with the old
copy, and throw an exception if changed. "
The observed behaviour is what I want but would like clarification that
I am thinking how it is done is correct.
Thank you for when you help.
Mark
This is a made up situation that mimics my real situation but it is
easier to understand.
1. I call a web method with an account number and retrieve an employee
object called employee on computer 1 (user 1). The employee object
getFirstName() returns "Michelle".
2. I repeat the process on computer 2 as above for the same account
number using the same web method (user 2). The employee object
getFirstName() returns "Michelle"
3. (user 1) I call employee.setFirstname("Mary") and then I invoke
employee.save(). The web method is called and the database for the
employee is saved.
4. (user 3) I perform a SELECT statement in the database and can see
that the table now contains 'Mary'.
5. (user 2) I call employee.setFirstname("Margaret") and then I invoke
employee.save(). The web method is called but an exception is raised.
When I query the database it still shows "Mary".
This is the behaviour I want but I do not know how it works. If I was
using a database where I had a connection for each user this behaviour
is easy to understand. But as I am using a web method and there is no
explicit connection to the database, and each user probably uses the
same database connection, I don't know how it is done.
I think it must work like this but is this right?
"Employee carries around an old copy with itself, and before doing an
update of the database, reads from the database, compares with the old
copy, and throw an exception if changed. "
The observed behaviour is what I want but would like clarification that
I am thinking how it is done is correct.
Thank you for when you help.
Mark