[bdbxml] Re:[bdbxml] Document modifications are not applied
"Stephan Korthoff" <[email protected]>
| Newsgroups | gmane.comp.db.dbxml.general |
|---|---|
| Message-ID | <[email protected]> |
I tested your suggestions and think I now understand what you wanted to tell
me.
My query is now free from any collection stuff and works fine on the
console:
dbxml> open xmachberk.dbxml
dbxml> query 'doc("xmachberk.dbxml/d378")'
1 objects returned for eager expression 'doc("xmachberk.dbxml/d378")'
dbxml> contextquery /kenndaten/felder_als_attribute/@double_feld_r
1 objects returned for expression
dbxml> print
{}double_feld_r="1,0"
dbxml>
But the java programm will hang as soon as it runs BerkModifier.execute.
XmlQueryContext context = BerkManager.createQueryContext();
XmlUpdateContext BerkUpdContext = BerkManager.createUpdateContext();
XmlModify BerkModifier = BerkManager.createModify();
XmlQueryExpression BerkQExp =
BerkManager.prepare("/kenndaten/felder_als_attribute/@double_feld_r",
context);
BerkModifier.addUpdateStep(BerkQExp, newAttributeValue );
System.out.println("DEBUG new value: " + newAttributeValue);
XmlDocument retDoc = BerkContainer.getDocument(docId);
XmlValue docValue = new XmlValue(retDoc);
System.out.println("\nDEBUG docValue asString: " + docValue.asString());
bla=BerkModifier.execute( docValue, context, BerkUpdContext);
System.out.println("\nDEBUG Number of changes: " + String.valueOf(bla));
System.out.println("\nDEBUG docValue after: " + docValue.asString());
XmlDocument retDoc2 = BerkContainer.getDocument(docId);
d
System.out.println("\nDEBUG docValue ret2: " +
retDoc2.getContentAsString());
Stephan
On Jun 24, 2005, at 9:54 AM, Stephan Korthoff wrote:
> I tried to run that query on the console and it returned the
> desired result.
Which query? The one using "collection()" or the one that does not?
You need to do the latter to be sure it's correct.
What series of commands did you use on the console?
Here is an example of how to do a context-based query (where it
queries based on previous results):
dbxml> query "doc('contName/docName')"
1 objects returned for eager expression 'doc('mem/foo')'
dbxml> contextQuery "/root/a"
1 objects returned for expression '/root/a'
(in the above, the content of the document was "<root><a/></root>")
If you want to try again, you have to execute the initial "doc" query
again to reset the context.
There are at least 2 reasons why you will not see modifications, and
ways to check them:
1. The query expression passed to execute() returns no results,
so nothing is modified. Remember that the expression needs
to be written as if it starts with the document root. Leading "/" or
maybe
"./" and no collection() or doc().
o test this by printing the result returned by the
XmlModify.execute(),
which is the number of modifications made. This will be the same
as the number of results returned by the query. If it's 0, your
query
is incorrect, or your document is not what you think.
2. The modifications are not being written back. You said
that the XmlUpdateContext is set to do this.
o verify this using XmlUpdateContext.getApplyChangesToContainer(),
and make sure the value is true.
>
> Stephan
>
>
>
>
>> --- Ursprüngliche Nachricht ---
>> Von: George Feinberg <gmf@...>
>> An: Stephan Korthoff <stephan.korthoff@...>
>> Betreff: Re: [bdbxml] Document modifications are not applied
>> Datum: Fri, 24 Jun 2005 09:35:05 -0400
>>
>>
>> All I can think of is that your query is not actually returning
>> results, which means there will be no modifications.
>> Try tuning your query so you know it's selecting
>> the desired attribute using a combination of:
>> XmlManager.prepare()
>> and this execute method:
>> XmlQueryContext.execute(XmlValue&, XmlQueryContext &, u_int32_t
>> flags)
>>
>> Use the XmlValue object based on your document as the first argument.
>>
>> George
>>
>>
>>> I tried your suggestion but the result is still the same.
>>>
>>> Stephan
>>>
>>>
>>> George wrote:
>>>
>>> I see it now. The context item for your modification is the
>>> document itself, so you query for the modification must
>>> take that into consideration.
>>> So, instead of:
>>> BerkManager.prepare("collection('xmachberk.dbxml')/kenndaten
>>> [ <at> doc_id=d" + String.valueOf(intDocId) +"]/
>>> felder_als_attribute/ <at> double_feld_r", context);
>>> You should use:
>>> BerkManager.prepare("./kenndaten[ <at> doc_id=d" +
>>> String.valueOf
>>> (intDocId) +"]/felder_als_attribute/ <at> double_feld_r", context);
>>>
>>> Or something that is relative to the root of the document.
>>>
>>> George
>>>
>>>
>>>
>>>> Does nobody have an idea what the problem could be?
>>>>
>>>> Stephan
>>>>
>>>>
>>>> Stephan Korthoff wrote:
>>>>
>>>>
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> I've got a problem with the modification of documents. I took the
>>>>> modification example from sleepycat.com and
>>>>> implemented an attribute value change as follows:
>>>>>
>>>>>
>>>>> .... try
>>>>> {
>>>>> XmlModify BerkModifier = BerkManager.createModify();
>>>>> XmlQueryContext context = BerkManager.createQueryContext();
>>>>>
>>>>> XmlQueryExpression BerkQExp =
>>>>> BerkManager.prepare("collection('xmachberk.dbxml')/kenndaten
>>>>> [ <at> doc_id=d" + String.valueOf(intDocId) +
>>>>> "]/felder_als_attribute/ <at> double_feld_r", context);
>>>>>
>>>>> System.out.println("DEBUG Anfrage:
>>>>> collection('xmachberk.dbxml')/kenndaten[ <at> doc_id=d"
>>>>> + String.valueOf(intDocId) +
>>>>> "]/felder_als_attribute/ <at> double_feld_r");
>>>>>
>>>>> BerkModifier.addUpdateStep(BerkQExp, newAttributeValue );
>>>>> System.out.println("DEBUG retdoc: " + retDoc.getContentAsString
>>>>> ());
>>>>>
>>>>> XmlDocument retDoc = BerkContainer.getDocument(docId);
>>>>>
>>>>> XmlValue docValue = new XmlValue(retDoc);
>>>>> System.out.println("DEBUG docValue asString: " +
>>>>> docValue.asString());
>>>>> BerkModifier.execute( docValue, context,
>>>>> BerkUpdContext);
>>>>> XmlDocument retDoc2 = BerkContainer.getDocument
>>>>> (docId); // +
>>>>> String.valueOf(intDocId));
>>>>> System.out.println("DEBUG docValue ret2: " +
>>>>> retDoc2.getContentAsString());
>>>>> }
>>>>>
------------------------------------------
To remove yourself from this list, send an
email to xml-unsubscribe@...
--
Weitersagen: GMX DSL-Flatrates mit Tempo-Garantie!
Ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
------------------------------------------
To remove yourself from this list, send an
email to [email protected]