Hi Pedro,

That kind of functionality you're after isn't available in the XML:DB API
specification.

However it certainly is in the The XQuery API for Java™ specification.

In the XQJ API there are XQPreparedExpression and XQExpression classes.

XQPreparedExpression essentially allows you to first compile an XQuery
expression which can be executed repeatedly while also validating bound
variables against an XML Schema datatype.

The API docs for XQPreparedExpression are available here:
http://www.cfoster.net/html/xqj/api/javax/xml/xquery/XQPreparedExpression.html

XQExpression works in a similar fashion, except you can bind variables
first and then execute a query of your choice later making use of those
external variables.

The API docs for XQExpression are available here:
http://www.cfoster.net/html/xqj/api/javax/xml/xquery/XQExpression.html

These classes can also behave differently depending on how you have set
their their XQStaticContext properties, for instance if you switch the
binding mode to deferred, the XQJ API will not consume the bound value
during the invocation of the bindXXX method and will only consume it
during the execution of the query itself, allowing you to stream content
to Sedna of potentially an enormous size.

You may also wish to check this page:
http://www.cfoster.net/articles/xqj-tutorial/binding-java-variables.xml

The Sedna XML:DB API is a good, robust, solid and well documented database
driver, however it is highly unlikely that it will see any development in
the future, other than bug fixes (if they are found).

I recommend using the Sedna XQJ API instead of the XML:DB API where-ever
possible as it is richer in features as well as its conformance against
the official XQJ Test suite.

Regards,

Charles


> Hi,
>
> I have a question regarding the use the XML:DB API with Compiled
> Expressions
> and Variables
>
> I want to execute the following query a lot of times:
> let $col :=
> document("Indentifier.xml","myCollection")/IdentifierList/Identifiers/identifi...@iid
> = $IID] return $col
>
> So I though I would compile the Expression the first time I use it and
> then
> reuse it, something like
>
> //Get a XQUery Service
> XQueryService service = (XQueryService)
> session.getCollections().systemControlCollection.getService(XQueryService.SERVICE_NAME,
> "1.0");
> //The expressions variable is a map of String -> CompiledExpression
> CompiledExpression currentExpression;
> if (!expressions.containsKey(GET_MRI_FROM_IID))
> {
> service.declareVariable("IID", IID);
> String query = "let $col :=
> document(\"Indentifier.xml\",\"myCollection\")/IdentifierList/Identifiers/identifi...@iid
> = $IID] return $col";
> currentExpression = service.compile(query);
> expressions.put(GET_MRI_FROM_IID, currentExpression);
> }
> else
> {
> currentExpression = expressions.get(GET_MRI_FROM_IID);
> currentExpression.reset();
> service.declareVariable("IID", IID);
> }
>
> The ideia is, if it's the first time the query is run, it's compiled and
> kept in the map, if it's the second (or more) time I reuse it from
> the map and reset it declaring the variable (IID) again.
>
> The problem I'm having is that the variable is not reset and the second
> time
> it runs, it's using the previous value for the variable ($IID)
>
> Am I Doing something wrong?
>
> Also, Is it possible to used declared variables in expressions inside a
> Sedna Update Statement (and filling the value with XML:DB API, using the
> declare variable statement)?
> I tried but not with much luck, but I've never seen an example so I can be
> doing something wrong.
>
> Thanks in advance to anyone who tries to help :)
>
>
> --
> Pedro Pereira
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference_______________________________________________
> Sedna-discussion mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sedna-discussion
>


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Sedna-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sedna-discussion

Reply via email to