Problems with eXIst

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with eXIst

Marc Petit-Huguenin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I am using  eXist as an embedded database. For now I am just need to
load an XML document from the database as a DOM tree, modify it, and
then update the document in the database. I use the XML:DB API.

My first minor problem is that the XMLResource.getContentAsDOM() returns
an Element object, instead of a Document object.

Then when I try to modify the DOM tree, the modifications are partially
saved. For example if I do this:

Collection collection =
DatabaseManager.getCollection("xmldb:exist:///db/data/", "admin", null);
XMLResource resource =
(XMLResource)collection.getResource("registration.xml");
Element registration = (Element)resource.getContentAsDOM();
Document document = registration.getOwnerDocument();
Element c = document.createElement("contact");
registration.appendChild(c);
c.setAttribute("since", Long.toString(System.currentTimeMillis() / 100));
Element uri = document.createElement("uri");
c.appendChild(uri);
uri.appendChild(document.createTextNode("test"));
resource.setContent(registration);
collection.storeResource(resource);

The XML document stored before the execution of the program is:

<?xml version="1.0" encoding="UTF-8"?>
<registration/>

After execution of the program:

<?xml version="1.0" encoding="UTF-8"?>
<registration xmlns:exist="http://exist.sourceforge.net/NS/exist"
exist:id="1" exist:document="registration.xml">
    <contact/>
</registration>

Obviously the uri element and the since attribute were not saved.

I use the code from the head of the CVS tree, as eXist-20050805 was
throwing the "java.lang.IllegalStateException: Thread does not have
lock" exception when storing the modified document.

Any help appreciated.

Thanks.

- --
Marc Petit-Huguenin
Home: [hidden email]
Professional: [hidden email]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDSlbv9RoMZyVa61cRAr43AJ4pUewMxcRjbWhIsvLcmqqFkcJaJgCeIwoN
cDw9Vb0oNb12LE0/VOpZXIA=
=DJhv
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Problems with eXIst

wolfgangmm
Hi,

> I am using  eXist as an embedded database. For now I am just need to load an XML document from the database as a DOM tree, modify it, and then update the document in the database. I use the XML:DB API.

In embedded mode, the DOM returned by getContentAsDOM() is live, i.e.
directly connected to the db. Manipulating this DOM is possible
somehow (if you know the internals), but very dangerous. Better think
of it as read-only (read-only behaviour should actually be enforced by
eXist).

You should either work on a copy of the persistent DOM or manipulate
the stored document via XUpdate or XQuery update extensions. The
XUpdate and XQuery update processors take care to handle all the
synchronization issues that arise in a multi-user environment.

If you connect to a remote server, manipulating the DOM is safe as you
are working on a copy of the data.

Wolfgang


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

when are built-in functions instantiated?Hi

Chris Tomlinson-2
Hi,

I've written a Java builtin function and would like to cache some information across invocations of the function. So my question is whether the function class is instantiated once for the life of eXist or on each invocation of the function from XQuery.

I'm running eXist snapshot 20050805 in tomcat 5.0.28.

Thanks,
Chris


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: when are built-in functions instantiated?Hi

Wolfgang Meier-2
Hi,

> I've written a Java builtin function and would like to cache some
> information across invocations of the function. So my question is whether
> the function class is instantiated once for the life of eXist or on each
> invocation of the function from XQuery.

Builtin functions are instantiated once at compile time for every function
call. Information cached in an object will be available until the query is
recompiled. Queries are recompiled if the compiled query times out (due to
inactivity) or to answer concurrent requests to the same query.

However, there's no global cache that is guaranteed to persist across query
invocations. It might be an idea to provide such a global cache. Someone else
asked for it recently, I think.

Wolfgang


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: when are built-in functions instantiated?Hi

Chris Tomlinson-2
Wolfgang,

Thanks for the response.

My testing suggests that I can just use static variables to accumulate information since I don't think classes are reloaded unless eXist itself is recycled or does eXist unload classes after a time?

Thanks again,
Chris

>Hi,
>
>> I've written a Java builtin function and would like to cache some
>> information across invocations of the function. So my question is whether
>> the function class is instantiated once for the life of eXist or on each
>> invocation of the function from XQuery.
>
>Builtin functions are instantiated once at compile time for every function
>call. Information cached in an object will be available until the query is
>recompiled. Queries are recompiled if the compiled query times out (due to
>inactivity) or to answer concurrent requests to the same query.
>
>However, there's no global cache that is guaranteed to persist across query
>invocations. It might be an idea to provide such a global cache. Someone else
>asked for it recently, I think.
>
>Wolfgang
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by:
>Power Architecture Resource Center: Free content, downloads, discussions,
>and more. http://solutions.newsforge.com/ibmarch.tmpl
>_______________________________________________
>Exist-open mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/exist-open


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Problems with eXIst

Marc Petit-Huguenin
In reply to this post by wolfgangmm
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wolfgang Meier wrote:
> Hi,
>

[snip]

>
> You should either work on a copy of the persistent DOM or manipulate
> the stored document via XUpdate or XQuery update extensions. The
> XUpdate and XQuery update processors take care to handle all the
> synchronization issues that arise in a multi-user environment.

Ok thanks, I will use XQuery/XUpdate for my application. Another
question: How can I be sure that the document or the fragment I read
will not be read or modified by another thread until I modify it with a
XUpdate? Should I use TransactionService?

- --
Marc Petit-Huguenin
Home: [hidden email]
Professional: [hidden email]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDSsPH9RoMZyVa61cRAg4EAJ42EghzZY7rPt0eczP8l8umcybGnACfYgFF
sANmLuxqVxjdLGjjSGtu5Ec=
=Avp9
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Blocking the reading of a document until it is modified

Marc Petit-Huguenin
In reply to this post by wolfgangmm
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

How can I be sure that the document or the fragment I read with XQuery
will not be read or modified by another thread until I modify it with
XUpdate?

Thank you for your answers.

- --
Marc Petit-Huguenin
Home: [hidden email]
Professional: [hidden email]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDTCWE9RoMZyVa61cRAvEyAKCGacFTH93eTmauBIw6C5dwaEugqgCeIBtA
jdoj0Ke+wZ2cqt6uFvr1Oqo=
=7Cwk
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Blocking the reading of a document until it is modified

wolfgangmm
Hi,

From Java, the interface XPathQueryServiceImpl provides two methods:
beginProtected() and endProtected() to put an exclusive lock around
all documents referenced in a query. The two public interfaces:
XPathQueryService and XQueryService both implement
XPathQueryServiceImpl.

To lock a document set from within an XQuery, use the extension
function util:exclusive-lock().

Wolfgang

On 10/11/05, Marc Petit-Huguenin <[hidden email]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
>
> How can I be sure that the document or the fragment I read with XQuery
> will not be read or modified by another thread until I modify it with
> XUpdate?
>
> Thank you for your answers.
>
> - --
> Marc Petit-Huguenin


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: Blocking the reading of a document until it is modified

Marc Petit-Huguenin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Wolfgang Meier wrote:

> Hi,
>
>>From Java, the interface XPathQueryServiceImpl provides two methods:
> beginProtected() and endProtected() to put an exclusive lock around
> all documents referenced in a query. The two public interfaces:
> XPathQueryService and XQueryService both implement
> XPathQueryServiceImpl.
>
> To lock a document set from within an XQuery, use the extension
> function util:exclusive-lock().

Thank you for your answer.

>
> Wolfgang
>
> On 10/11/05, Marc Petit-Huguenin <[hidden email]> wrote:
>
>>-----BEGIN PGP SIGNED MESSAGE-----
>>Hash: SHA1
>>
>>Hi,
>>
>>How can I be sure that the document or the fragment I read with XQuery
>>will not be read or modified by another thread until I modify it with
>>XUpdate?

- --
Marc Petit-Huguenin
Home: [hidden email]
Professional: [hidden email]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDTPLx9RoMZyVa61cRAtbKAJ9dFNn6tL0Yf6QJk/hRoEkFYeIcjgCfZz6z
vd5CXtCzKVR9IfAa0f/hojg=
=FxQj
-----END PGP SIGNATURE-----


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open