Hi Evan,
The solution is fairly simple even with CMP. I mentioned
a similar strategy we use (in production environments)
with a timestamp/versioning in the 'EJB Design Patterns"
paper at http://www.borland.com/appserver/papers
(pages 21 -23). And this strategy is used in conjunction with
the verified updates.
Anyways, since one of the CMP fields is a timestamp/version
number, the client receives this field as well (as a field in
the value object / state object or whatever you prefer). And
this same field is sent back (unmodified) to the server from
the client when an update is to be performed. The EntityBean
implementation class in the setData(MyState someState) method
simply does something along the lines of the pseudo code below:
if (entityTimestamp != null) {
if (structTimestamp == null)
throw SyncException(someMessage);
else if (entityTimestamp.getTime() != structTimestamp.getTime())
throw SyncException(someMessage);
}
The above of course can be abstracted to some utility class. And the
last line in the EntityBean implementation class's "setData(MyState someState)"
would be to update the CMP timestamp/version field. Another point to note is
that when the client sends an object (MyState) over to the server for modification,
if the modification succeeds, the client receives the [new] MyState object as a
return parameter. So in your facade, instead of a
"modify(MyState newData): void" you would have a
"modify(MyState newData): MyState".
I do not see the need for a BMP based solution as you mentioned
your customer (has/)is doing ....
Your CMP code in the Entity Bean would have just two additional
lines of code.
setData(MyState newState) throws SomeException {
SyncHelper.check(newState.getTimestamp(), this.getTimestamp());
/* above would throw exception if check failed)
newState.setTimestamp(updateTimestamp)
/* set fields from newState to the entity bean */
}
-krish
PS: Some databases round off timestamps to the nearest hundredth or tenth
of a second instead of milli/nano seconds that the timestamp is capable of.
So if yours client have extremely fast fingers and succeeds in
- requesting data from server
- entering new values
- sending new data to server
all within the same second/hundredth of a second, he could overwrite
changes ... so a version number increment might be better idea
than a timestamp in this case.
----- Original Message -----
From: "Evan Ireland" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 29, 2001 12:10 AM
Subject: Re: Are Entity Beans(CMP/BMP) really necessary???
I would like to take this discussion a step further, in line with a request
> I received yesterday from a customer. We are all now familiar with the
> notion of saving original (or timestamp column) values on ejbLoad, and
> generating an appropriate WHERE clause to verify that no fields changed
> since ejbLoad at the time of ejbStore.
>
> What my customer requested was even more interesting. They are populating
> a table on the client with some data retrived from entity beans. The
> client now (in a separate transaction) wishes to update one or more
> entities (let's say just one). The customer wishes to ensure that the
> entity being updated was not changed since the original values were
> received by the client (in an earlier transaction).
>
> So what in effect is being requested is that the WHERE clause verification
> doesn't use the values retrieved on the ejbLoad call, but instead uses the
> values that were received earlier by the client and passed back into the
> entity business method that performs an update. All of this with CMP,
> of course.
>
> Now I have a fairly simple solution in mind but before I reveal it I
> wonder if folks here think that this issue is an interesting one to
> discuss, and would be prepared to share design patterns that they are
> using (or considering using) with CMP to accomplish this.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".