From: Gil T. <Gil...@we...> - 2005-01-05 18:07:03
|
I suspected as much. But if the references are pointing to real-life persistent nodes, then shouldn't those nodes be referenced-counted/garbage-collected, i.e. live as long as somebody is referencing them? =20 =20 =20 ________________________________ From: Wolfgang Meier [mailto:wol...@ex...]=20 Sent: Wednesday, 05 January, 2005 16:56 To: exi...@li... Subject: Re: [Exist-open] The case of the disappearing node =20 This isn't a bug: eXist is based on a persistent DOM, so the processed=20 nodes are life, i.e. they reference the real nodes stored in the db (the XQuery engine internally represents persistent nodes as instances of=20 class NodeProxy, which is a pointer to the real node). The node=20 reference in $client becomes invalid after the node has been removed=20 from the database, and $client/title finds nothing.=20 To preserve the contents of a node, you have to copy it to an in-memory=20 representation as you did by casting it to string (this reminds me that=20 we need a kind of deep-copy() function for cases where you need to have=20 a real copy of a document fragment).=20 Wolfgang=20 =20 > I believe I found a bug when keeping references to deleted nodes. Let me=20 > explain. I have this XQuery:=20 >=20 > =20 >=20 > let=20 >=20 > * **$**client **:=3D** **//**client[**@**id **=3D** **$**clientIdParameter]***=20 >=20 > return=20 >=20 > if ($client) then=20 >=20 > let $remove :=3D=20 >=20 > * **xmldb:remove**(**concat**(**'clients/client-**',=20 > **$**client**/@**id))***=20 >=20 > return=20 >=20 > * **<**success title**=3D**"{$client/title}**"**/>***=20 >=20 > else=20 >=20 > <error>=20 >=20 > <not-exist>=20 >=20 > <id>{$clientIdParameter}</id>=20 >=20 > <type>client</type>=20 >=20 > </not-exist>=20 >=20 > </error>=20 >=20 > =20 >=20 > This query will find a node ($client), delete the document containing=20 > it, and return a <success> with a subnode (title) of the $client node. > Running this query returned <success title=3D"" />.=20 >=20 > =20 >=20 > I suspected that the node was deleted and somehow the reference I have > to that node ($client) was "nulled". So I tried modifying it:=20 >=20 > =20 >=20 > let=20 >=20 > $client :=3D //client[@id =3D $clientIdParameter],=20 >=20 > $clientTitle :=3D $client/title=20 >=20 > return=20 >=20 > if ($client) then=20 >=20 > let $remove :=3D=20 >=20 > xmldb:remove(concat('clients/client-', $client/@id))=20 >=20 > return=20 >=20 > <success title=3D"{$clientTitle}"/>=20 >=20 > else=20 >=20 > <error>=20 >=20 > <not-exist>=20 >=20 > <id>{$clientIdParameter}</id>=20 >=20 > <type>client</type>=20 >=20 > </not-exist>=20 >=20 > </error>=20 >=20 > =20 >=20 > I added the temporary variable $clientTitle, but got the same result.=20 > So, last chance - get a /copy/ of the title:=20 >=20 > =20 >=20 > let=20 >=20 > $client :=3D //client[@id =3D $clientIdParameter],=20 >=20 > $clientTitle :=3D string($client/title)=20 >=20 > return=20 >=20 > if ($client) then=20 >=20 > let $remove :=3D=20 >=20 > xmldb:remove(concat('clients/client-', $client/@id))=20 >=20 > return=20 >=20 > <success title=3D"{$clientTitle}"/>=20 >=20 > else=20 >=20 > <error>=20 >=20 > <not-exist>=20 >=20 > <id>{$clientIdParameter}</id>=20 >=20 > <type>client</type>=20 >=20 > </not-exist>=20 >=20 > </error>=20 >=20 > =20 >=20 > This time it worked! By using string(...) I copied the string and now got=20 > the result I wanted.=20 >=20 > =20 >=20 > Looks like a bug...=20 >=20 > =20 >=20 > =20 >=20 > Yours,=20 >=20 > Gil Tayar=20 >=20 > WebCollage=20 >=20 > Chief Technology Officer=20 >=20 > Business: +972 (3) 766 1806=20 >=20 > Mobile: +972 (54) 634 4457=20 >=20 > =20 >=20 =20 -------------------------------------------------------=20 The SF.Net email is sponsored by: Beat the post-holiday blues=20 Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.=20 It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt=20 _______________________________________________=20 Exist-open mailing list=20 Exi...@li...=20 https://lists.sourceforge.net/lists/listinfo/exist-open=20 |