Return-Path: X-Original-To: apmail-cayenne-user-archive@www.apache.org Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 79987196DA for ; Tue, 12 Apr 2016 23:32:24 +0000 (UTC) Received: (qmail 27188 invoked by uid 500); 12 Apr 2016 23:32:19 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 27161 invoked by uid 500); 12 Apr 2016 23:32:19 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 27147 invoked by uid 99); 12 Apr 2016 23:32:18 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Apr 2016 23:32:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 7ED9DC05B3 for ; Tue, 12 Apr 2016 23:32:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.183 X-Spam-Level: X-Spam-Status: No, score=0.183 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.996, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id acFPoGlueswv for ; Tue, 12 Apr 2016 23:32:15 +0000 (UTC) Received: from nm14-vm0.bullet.mail.bf1.yahoo.com (nm14-vm0.bullet.mail.bf1.yahoo.com [98.139.213.164]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 0CD0B5F239 for ; Tue, 12 Apr 2016 23:32:15 +0000 (UTC) Received: from [98.139.170.178] by nm14.bullet.mail.bf1.yahoo.com with NNFMP; 12 Apr 2016 23:32:08 -0000 Received: from [98.139.212.218] by tm21.bullet.mail.bf1.yahoo.com with NNFMP; 12 Apr 2016 23:32:08 -0000 Received: from [127.0.0.1] by omp1027.mail.bf1.yahoo.com with NNFMP; 12 Apr 2016 23:32:08 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 197260.29829.bm@omp1027.mail.bf1.yahoo.com X-YMail-OSG: WRIbZZkVM1n4m8W._bOXNpaw.N7wLRNCnJsptePhG0yNS2.cEpZXi.HWHJNQBX_ 32mIeTEPvA.irHUWJjeBfZ1d34Gk.77V4esckdjwanSZwY9xwsdnWcmP7xvG3hTGCReJuZfN6TA4 f_o1bXhJgkXWPWnZD_NBuISYgnS1hf9lTJbFx1lmMsXU3sIuBVl9fDsitp1gc2zcyDQ6FOWkjwTp CjCk6YMh1aajySI_NFEEVsmRFhZ.z.uN57Ix9hGLXSLtyiu7WAMJpdg9_aaN7aD5Gxgge3JjIvUF W7TtCJN0oMlavRacH1dup8RFqlWFi6z96BVSn_vieDgxKr1ZjuduydjxW20z6fFiPFPVzXyVWLcY mnGKa86_N7mu5MiK0ymbKhxM84RCRiYN8G9Oou8boemiGU1LeqpYBfKaRMzovVZ5nPxgabH8eD5J ePyzbUbprvUJgYWOnEZ06hY.lhciJhppnVx7Wy95DHC7iByZU_PM1UvGhWmdEBqQlFTkBGUNAviK qaOSxm4w7mOI- Received: by 66.196.81.104; Tue, 12 Apr 2016 23:32:07 +0000 Date: Tue, 12 Apr 2016 23:31:53 +0000 (UTC) From: Juan Manuel Diaz Lara Reply-To: Juan Manuel Diaz Lara To: "user@cayenne.apache.org" , Juan Manuel Diaz Lara , "dollj@xsinet.co.za" Message-ID: <1730032465.2035242.1460503913382.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <1160607407.1883685.1460487849533.JavaMail.yahoo@mail.yahoo.com> References: <1160607407.1883685.1460487849533.JavaMail.yahoo@mail.yahoo.com> Subject: Re: How to execute a stored procedure as part of a commitChanges? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2035241_951621165.1460503913376" ------=_Part_2035241_951621165.1460503913376 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Jurgen, your code is great for one dataobject, but how to do it for the ent= ire context automatically ? =C2=A0Atte. Juan Manuel D=C3=ADaz Lara=20 On Tuesday, April 12, 2016 2:04 PM, Juan Manuel Diaz Lara wrote: =20 Thanks, I will try it this later, report results. =C2=A0Atte. Juan Manuel D=C3=ADaz Lara=20 =C2=A0 =C2=A0 On Tuesday, April 12, 2016 5:16 AM, "dollj@xsinet.co.za" wrote: =20 Hi Juan With regards to your question:=C2=A0 is there some way to get a diff of the= =20 failed context and apply that to the new context ? You could try the following: 1.=C2=A0 Before context.commitChanges() do something like: DataRow=C2=A0 changes =3D context.currentSnapshot( this ).createDiff ( =C2=A0 =C2=A0 context.getObjectStore().getSnapshot( getObjectId() ) ); 2.=C2=A0 On failure do: context.rollbackChanges(); context.currentSnapshot( this ).applyDiff( changes ); Then you should be back to where you started before the attempted commit. Regards Jurgen -----Original Message-----=20 From: Juan Manuel Diaz Lara Sent: Tuesday, April 12, 2016 4:59 AM To: user@cayenne.apache.org Subject: Re: How to execute a stored procedure as part of a commitChanges? The fact is that the persistenceState of dataobjects is being set to=20 COMMITTED before the actual transaction (db transaction or whatever) is=20 committed, specially when running commitChanges()=C2=A0 inside=20 performInTransaction() for the purpose to run additional code inside the=20 same transaction and after commitChanges(). Think of a rich client=20 application with many changes, additions and deletions before we can commit= ,=20 it is not easy to replay this operations on a new context to retry all afte= r=20 making some corrections (or is there some way to get the a diff of the=20 failed context and apply then to the new context ?). Elaborating on hacking cayenne, I found we can inject a new=20 TransactionFactory and new ObjecStoreFactory on ServerRuntime, so it is=20 possible to extend cayenne. I think i can install a new ObjectStore with a= =20 modified postprocessAfterCommit(GraphDiff) that runs its code after=20 currentTransactionCommits. My hope is that if the transaction fails after= =20 commitChanges() then we can prevent=C2=A0 postprocessAfterCommit to run and= so=20 the context wil remain in the state it was before commitChanges(), after=20 that we can retry the transaction (on the same context) after making some= =20 more changes. I need help with: 1. is this the only change needed considering other things like=20 DataChannelFilters ?2. what about the interaction with nested context? how= =20 to care of this ?3. what do i need to do on rollback ? Thanks. Atte. Juan Manuel D=C3=ADaz Lara =C2=A0 =C2=A0 On Monday, April 11, 2016 3:21 PM, John Huss =20 wrote: I think changing Cayenne is the wrong solution here. The problem is that your commit failed. You have to rollback the context if you want to keep using it. On Mon, Apr 11, 2016 at 2:22 PM Juan Manuel Diaz Lara wrote: > Calling rollbackChanges will lost all changes, and create a new context > and start over is complex=C2=A0 with many and variables changes to replic= ate in > the new context... > I think the problem is that sync with db state is lost if the dataobjects > are market commited before the real transaction commits, in fact, this=20 > what > the code in ObjectStore that change the persistentceState: >=C2=A0 =C2=A0 =C2=A0 * Internal unsynchronized method to process objects s= tate after > commit. >=C2=A0 =C2=A0 =C2=A0 * >=C2=A0 =C2=A0 =C2=A0 * @since 1.2 >=C2=A0 =C2=A0 =C2=A0 */ >=C2=A0 =C2=A0 void postprocessAfterCommit(GraphDiff parentChanges) { > but that is not true, because transaction commits happen after this code > runs no before as implied. > >=C2=A0 I am considering some hacking along the lines: > 1. Allow Transaction to execute arbitrary code after commit.2. ObjectStor= e > now should register with current transaction to run postprocessAfterCommi= t > after the transaction commits; > Well this is the idea, but I need more guide to do this, maybe not the > right classes to hack o derive, how to install my changes in a modular=20 > way, > etc., I am really new to cayenne. >=C2=A0 Atte. Juan Manuel D=C3=ADaz Lara > >=C2=A0 =C2=A0 On Monday, April 11, 2016 11:04 AM, John Huss > wrote: > > >=C2=A0 Try calling context.rollbackChanges() or just create a new context = and > start over. > > On Mon, Apr 11, 2016 at 10:31 AM Juan Manuel Diaz Lara > wrote: > > > > > > > I am using 4.0.M3. > > I used the following solution, but the problem is that after > > commitChanges() the dataobjetcs are set to PersistenceState.COMMITED, i= f > > the stored procedure fails Cayenne does a DB rollback (that's ok), but > > dataobjects stay COMMITED, so I can not retry the this transaction afte= r > > errors are solved. > > Is there any way to revert the persistenceState to their values before > > commitChanges if I detect the stored procedure failed ? > > > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cayenneRuntime.performInTransa= ction(new > > TransactionalOperation() > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 { > > > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 @Override > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 public Integer perform() { > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 context.commitChanges(); > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 //... > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 SQLTemplate s =3D new SQLTemplate("SELECT > > pkg_inventario_fisico.apply( #bind($idAlmacen, 'VARCHAR')) AS id",=20 > > true); > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 s.setParamsArray(a); > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 @SuppressWarnings("unchecked") > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 List rows =3D > > CayenneDao.instance.context.performQuery(s); > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 DataRow row =3D rows.get(0); > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 //... > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 return null; > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 } > > > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } > >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ); > >=C2=A0 Atte. Juan Manuel D=C3=ADaz Lara > > > >=C2=A0 =C2=A0 On Monday, April 11, 2016 10:06 AM, Mike Kienenberger < > > mkienenb@gmail.com> wrote: > > > > > >=C2=A0 See the bottom part of this page starting at "In the second scena= rio": > > > > > > > https://cayenne.apache.org/docs/4.0/cayenne-guide/persistent-objects-obje= ctcontext.html#transactions > > > > > > On Mon, Apr 11, 2016 at 10:54 AM, Juan Manuel Diaz Lara > > wrote: > > > > > > > > >=C2=A0 I have a dataobjet graph with some changes, and a db stored pro= cedure > > that should run after this changes are in the db, but must run in the > same > > transaction because it make some more changes to other data, this=20 > > changes > > can fail so I want the commitChanges fail if the stored procedure fails= . > > >=C2=A0 Atte. Juan Manuel D=C3=ADaz Lara > > > > > > > > > > > > > > > > > > ------=_Part_2035241_951621165.1460503913376--