I think that is most likely your best bet.

Larry


On 3/15/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

I would agree that this would be an easy implementation that I would prefer. The problem is that I am working with an existing Data Model that I inherited and I cannot change without having an enormous impact on multiple groups and application UI's. (Not something that I am ready to propose)  This is the model that I am stuck with unfortunately.

I think I have a solution to the problem but I feel that it is a very dirty one. I could define an additional field in each domain object and call it 'now', which would get the current timestamp, set by the Dao, just prior to performing the insert. I would then update the value in the SQL as follows:

   update customer set
    name = #name#,
    record_date = #now#,

    ...

  where

    id = #id#

  and

    record_date = #recordDate#  
 

Then if the update was successful I could have the Dao update the record date with the value of now. It's dirty, so I am in hopes that someone has a better solution for me.

Thanks...


Chris Mathrusse
[EMAIL PROTECTED]
Sybase, Inc
One Sybase Drive
Dublin, CA 94568
(925) 236-5553



"MCCORMICK, Paul" <[EMAIL PROTECTED]>

03/15/2006 05:30 PM

Please respond to

To
cc

Subject
RE: Optimistic locking question







Instead of using a timestamp I use an integer and increment the value on every update.
 
update customer
set NAME= #name#,
    VERSION_ID = VERSION_ID + 1  
where ID = #ID# and VERSION_ID  = #VERSION_ID#
 
Then in the Dao I would increment versionId value on the CustomerDTO object if the update succeeded.
        int rowCount = getSqlMapClientTemplate().update( "Customer-update", record);
       
       if(rowCount == 0) {

           throw new OptimisticLockingFailureException("Optimistic Lock Failure! Unable to update record: " + record);            

       }

        record.setVersionId(record.getVersionId() + 1 );



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent:
Wednesday, 15 March 2006 11:55 PM
To:
[email protected]
Subject:
Optimistic locking question



I have a table:


CREATE TABLE CUSTOMER

       ID NUMBER NOT NULL,

       NAME VARCHAR(32) NOT NULL,

       RECORD_DATE TIMESTAMP NOT NULL,

       ...


The Record_Date is used to determine the last time the record was updated, so when I perform an update my SQL would look something like:


  update customer set
    name = #name#,
    record_date = getDate(),

    ...

  where

    id = #id#

  and

    record_date = #recordDate#  
 

This allows me to do the following in my Dao:

       

       int rowCount = getSqlMapClientTemplate().update( "Customer-update", record);

       
       if(rowCount == 0) {

           throw new OptimisticLockingFailureException("Optimistic Lock Failure! Unable to update record: " + record);            

       }

       
       return rowCount;        



The problem that I have is if my SQL is performing the update of the record_date field when the insert is performed, how do I update my domain object with the new value without performing a read from the table?



Thanks for the help...


Chris Mathrusse
[EMAIL PROTECTED]
Sybase, Inc
One Sybase Drive
Dublin, CA 94568
(925) 236-5553
"DISCLAIMER: This email, including any attachments, is intended only for use by the addressee(s) and may contain confidential and/or personal information and may also be the subject of legal privilege. If you are not the intended recipient, you must not disclose or use the information contained in it. In this case, please let me know by return email, delete the message permanently from your system and destroy any copies.

Before you take any action based upon advice and/or information contained in this email you should carefully consider the advice and information and consider obtaining relevant independent advice.



Reply via email to