Re: Savepoints?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Feb 08 2005 - 09:51:18 EST

  • Next message: Mike Kienenberger: "Re: Building with JUnit"

    Hi Lars,

    Your solution (nested DataContexts) will be possible at some point in 1.2
    - it is on the schedule, but not supported yet. Not sure if it solves the
    problem though - child contexts will commit to parent context, not to the
    DB.

    One possible solution [fully compatible with 1.1] is to go with a single
    DataContext and use a custom TransactionDelegate
    (http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/access/TransactionDelegate.html)

    to invalidate a subset of your objects on failure.

    Andrus

    > Hi all,
    >
    > Is it possible to create some kind of savepoints in Cayenne?
    > What I want: Normally the user creates new objects and manipulates them
    > and commits the changes. But at one point the application should change
    > several objects (hidden from the the user) but these changes may fail
    > for several reasons (business rules etc.). If one change fails the
    > changes should be rolled back to the earlier (stable) state that was
    > controlled by the user.
    > But if everything works fine the changes must be committed by the user
    > again (the changes are not committed by the application, only rolled
    > back if one of the changes failed).
    >
    > May I reach the my goal with the following (pseudo) code?
    >
    > DataContext parentContext = getDataContext();
    > DataContext subContext = parentContext.createDataContext();
    > subContext.setParent(parentContext);
    > try {
    > // do something
    > catch (MyException ex) {
    > subContext.rollbackChanges();
    > }
    >
    > Will the changes created within the subContext automatically submitted
    > if the user submits the changes in the parent context?
    >
    > Are there better solutions?
    >
    > Thanks in advance and best regards,
    > Lars



    This archive was generated by hypermail 2.0.0 : Tue Feb 08 2005 - 09:51:19 EST