One Transaction for select and update

From: JR Ruggentaler (JR.Ruggentale..pv.com)
Date: Sun Feb 13 2005 - 00:18:13 EST

  • Next message: Koen Segers: "postgres serial"

    I have a TABLE with one record. I am trying to use it like the primary key table (auto_pk_support) is used in Cayenne. I want to get the current value (NEXT_ACCOUNT_ID) and increment it by one in a single transaction. The code looks like this.

    SelectQuery query = new SelectQuery(AccountSequence.class);
    AccountSequence accSequence = (AccountSequence) list.get(0);
    Long nextAccountId = accSequence.getNextAccountId();
    long value = nextAccountId.longValue();
    nextAccountId = new Long(++value);
    accSequence.setNextAccountId(nextAccountId);
    ctxt.commitChanges();
    List list = ctxt.performQuery(query);

    How do I do the select and update in one transaction?

    Here is the log output from the above code:

    - --- transaction started.
    - SELECT t0.NEXT_ACCOUNT_ID, t0.ACCOUNT_SEQUENCE_ID FROM ACCOUNT_SEQUENCE t0 - prepared in 20 ms.
    - === returned 1 row. - took 50 ms.
    - +++ transaction committed.
    - --- transaction started.
    - --- will run 1 query.
    - UPDATE ACCOUNT_SEQUENCE SET NEXT_ACCOUNT_ID = ? WHERE ACCOUNT_SEQUENCE_ID = ?
    - [bind: 1234100020003003, 200]
    - === updated 1 row.
    - +++ transaction committed.



    This archive was generated by hypermail 2.0.0 : Sun Feb 13 2005 - 00:18:16 EST