I am usig JDOM to modify Elements.
// ---------------------
private void performUpdate(TQuery query, Element newElement) throws TException {
TLocalTransaction localTransaction = null;
// Perform query and update operations within a transaction
try {
// Switch to local transaction mode
localTransaction = connection.useLocalTransactionMode();
// Invoke the query to obtain the document and to lock it
System.out.println(“query : “+ query.toString());
response = accessor.query( query );
// Obtain the TXMLObject from the response
TXMLObject xmlObject = response.getFirstXMLObject();
if ( xmlObject == null )
return;
// Obtain the JDOM element and update its content
Element element = (Element)xmlObject.getElement();
element.setAttributes(newElement.getAttributes());
element.setChildren(newElement.getChildren());
System.out.println(”hallo 1”);
// Invoke the update
response = accessor.update( xmlObject );
System.out.println( “Update succeeded!” );
// Commit the transaction
localTransaction.commit();
}
// TQueryException and TUpdateException are both derived from TAccessorException
// so we simply use the base class here
catch (TAccessorException accessorException) {
localTransaction.rollback();
throw accessorException;
}
finally {
// Switch back to auto-commit mode
connection.useAutoCommitMode();
}
}
// ---------------------
I call the function above with :
performUpdate(currentVendorQuery, vendorChild);
// ---------------------
I get this Errormessage:
Message
query : /labDevices[@ino:id=“1”]/vendor[@name=“A”]
hallo 6
com.softwareag.common.instrumentation.contract.ViolatedPrecondition: Violated Precondition: Update not possible. TXMLObject instance does not contain an ino:id!
at com.softwareag.common.instrumentation.contract.Precondition.check(Unknown Source)
at com.softwareag.tamino.db.API.accessor.TStreamAccessorImpl.update(Unknown Source)
I assume that one of the following statements:
element.setAttributes(newElement.getAttributes());
element.setChildren(newElement.getChildren());
removes the ino:id from the TXMLObject. An update of the same document in Tamino requires the ino:id - so you either have to restore it or use the “insert()” method to create a new document in Tamino.
Right now I have Tamino 3.1.2.1
I will get the Vers. 4 in couple days.
With the version I have right now, I can update a whole document, but not a part of it.
Let’s say I have just one ino:id=1
It has one huge xml file: elements with child elements and so on …
If I want to modify just one attribute of
a child, I have to update the whole document.
Question 1
Am I doing something wrong,
OR is that not possible to modify
parts of a document wirh Tamino 3.1.2.1
Question 2
With the version 4, is it possible to modify
particular parts of a document ?
Question 3
Tamino 3.1.2.1 supports JDOM beta 6.
Do you know which JDOM beta version Tamino Vers. 4 does support ?
Aykut
Hello Aykut,
(1) With Tamino v3121 and the TaminoAPI4J it is only possible to update the entire document because the TaminoAPI4J does not support the NodeLevelUpdate filter (which was only available if using IIS).
(2) With Tamino v4141 it is possible to update parts of the document using the XQuery-Update mechanism. The TaminoAPI4J supports this new feature by introducing a xquery() method to the TXMLObjectAccessor object.
(3) The TaminoAPI4J that comes with v4141 is delivered with JDOM beta 8.
Hope this helps.
Stuart Fyffe-Collins
Software AG (UK) Ltd.
Hello Stuart, Hello Aykut,
perhaps it is interesting to know that in this thread: Error when UPDATING a Tamino-Xml-Element, we succeeded in using JDOM b0.9 RC1 with the Tamino API for Java (from Tamino 4.1.1.1).
Greetings,
Trevor.
Hello Stuart, Hello Trevor
thank you for the information.
I hopefully get the update package today.
Then I will try the assistance you gave me.
Aykut
I have installed Tamino Version 4.1.4.1.
The db is working. I also define the schema
and upload an xml file.In the Tamino Documentation
I could find some examples about XQuery,
but I could not find any examples XQuery with Java (JDOM)
I have an XML Document like the follwing one:
docu for vendor A
docu for vendor Y
------------------------------------------------------
I would like to update, insert and delete
Attributes and Element content.
------------------------------------------------------
Update : Atribute & Element A => X
docu for vendor X
docu for vendor Y
Insert : Element Z (at the End)
docu for vendor X
docu for vendor Y
docu for vendor Z
Insert : Element K (certain position, after Y)
docu for vendor X
docu for vendor Y
docu for vendor K
docu for vendor Z
Delete: Element Z
docu for vendor X
docu for vendor Y
docu for vendor K
[This message was edited by Aykut on 05 Jun 2003 at 18:09.]
[This message was edited by Aykut on 05 Jun 2003 at 18:14.]
[This message was edited by Aykut on 05 Jun 2003 at 18:14.]
[This message was edited by Aykut on 05 Jun 2003 at 18:16.]
[This message was edited by Aykut on 05 Jun 2003 at 18:19.]
Hello Aykut,
with Tamino 4.1 there are two mechanisms for updating the content of stored documents: replace the document in Tamino with a [complete] updated version of the document (the familiar mechanism - similar to insert, but specifying an ino:id) or execute an XQuery Update statement (which is new with Tamino 4.1).
It is possible to use either of these mechanisms from the Tamino API for Java, but both require different actions from the user.
When using one of the API’s object models, the API presents you with a set of objects to represent the content of a document.
So, in the case of JDOM, you get JDOM objects to work with.
These objects are just an “in memory copy” of the document(s) stored in Tamino. The user does whatever they need to do in order to modify the content of the document. When a call to TXMLObjectAccessor.update(obj) is made, the document represented by the objects is sent back to Tamino as a complete document, and Tamino replaces the old document with the new one.
When using XQuery to perform updates, the documents are updated on the Tamino server - an in memory object model is not created on the client side.
Rather, the user simply requests that Tamino update specific documents in a certain way.
I hope that this explains why there are no examples of using XQuery with JDOM!
The updates that you wish to make to your document are possible through either mechanism, I believe. Which mechanism is more appropriate depends upon the context of your application.
For example: if your application has some sort of GUI frontend which displays document content, allows users to modify the content and then click “Save”, perhaps it makes more sense to load the document into an object model on the client side.
On the other hand: if you just need to perform a big batch update (like “add one to everyone’s salary”) in a non-interactive way, then an XQuery Update statement is likely to be more appropriate.
I’m sorry that this doesn’t really answer your questions, but I hope it is helpful…
If you get stuck with the specifics, please don’t hesistate to post the problems!
Greetings,
Trevor.