Re: [OJB-developers] Let's fix the testsuite!
Brought to you by:
thma
From: ïÌÅÇ î. <on...@uk...> - 2002-05-29 08:42:16
|
Hi Thomas, I am afraid I was not clear enough, actually I proposed two alternatives, and you commented only the first one, see below. -----Original Message----- From: Thomas Mahler <tho...@ho...> To: Oleg Nitz <on...@uk...> Date: Tue, 28 May 2002 23:05:59 +0200 Subject: Re: AW: [OJB-developers] Let's fix the testsuite! > > I see. To achieve this we should either 1) > > remember the original state of the m:n relation You commented this one, and I agree that it requires locks. > > or 2) > > to read the set of all indirection instances from the > > database in storeMtoNImplementor(), then compare them against > > the current set of indirection instances in memory, > > then insert/delete the two differences of two sets. > > Then there is no need in multiple database lookups. This approach is almost as simple as yours. First we execute SELECT fk_for_items FROM indirect_table WHERE fk_for_this=? and put then into the set1 The identities for the current m:n collection we put into set2 Then we calculate "set1 minus set2" and DELETE these records Then we calculate "set2 minus set1" and INSERT these records > A much simpler aproach: > before inserting entries for a given relation in storeMtoNImplementor(), > just delete all existing entries. > This way we > - can avoid exception caused by failing inserts, > - won't need to track object state to detect removed entries. > Overhead should be rather small we'll need to execute only one DELETE > statement. You are right, we need to execute only one DELETE statement, but every time we will execute 1 DELETE and many INSERTs, even if nothing changed. With my 2nd approach we will execute 1 SELECT and the number of DELETEs and INSERTs that is really necessary, i.e. zero if nothing changed. And in general this approach seems more careful :) Do you agree? Oleg |