Update problem with ino:docname

Hi all,

I really don’t know if I’m that foolish or not as I’ve encountered so much problem with the Tamino API for Java. Having not less experience in Java, I supposed it is a few trivial call to the APIs, but I can’t make it work.
Can anyone point me out why the below code doesn’t work? When I can see Transaction committed successfully printed out, the records are really updated. But…
My records’ docname originally have the format, for example “xyz:1234”, I just want to change it to “document:1234”, but the ino:docname is missing after
the transaction committed!! Why? (Please assume all variables are declared correctly as it is only a snapshot)

--------------------------------------------------------------------------------
try {
myTransaction = connectionA.useLocalTransactionMode();
TQuery tQuery = TQuery.newInstance(“/article”);
TResponse response = accessorA.query( tQuery, 10 );
if( response.hasFirstXMLObject() ) {
TXMLObjectIterator itr = response.getXMLObjectIterator();
for ( int count = 0; itr.hasNext() && count < 10 ; count++) {
TXMLObject xmlObject = itr.next();
Element element = (Element)xmlObject.getElement();

String docname = “document” + count;
xmlObject.setId(xmlObject.getId());
xmlObject.setDocname( docname );
response = accessorA.update( xmlObject );
}
}
myTransaction.commit();
connectionA.useAutoCommitMode();
System.out.println("Transaction committed successfully … “);
} catch (TException te) {
te.printStackTrace();
myTransaction.rollback();
System.out.println(te.toString()+” - transaction rollback … ");
} finally {
// Close both connections
connectionA.close();
connectionB.close();
System.out.println("Connection closed successfully … ");
}
----------------------------------------------------------------------------------

Best regards,
Lun

The API documentation says that once a document has been stored with a docname, that name cannot be updated (see method setDocName() in TXMLObject).

Also, if a document has both ino:id and a document name, the ino:id “takes precedence”. Any supplied docname is ignored on the update, and any existing docname is deleted (see method update() in TXMLObjectAccessor).

So to achieve a change of docname you need code like this:

Element element = (Element)xmlObject.getElement();
response = xmlObjectAccessor.delete(xmlObject);
element.removeAttribute("ino:id");
String docname = "Newname";
xmlObject.setDocname( docname );
response = xmlObjectAccessor.insert( xmlObject );



This deletes your existing object, then removes the ino:id attribute from the original document’s xml, and inserts a new document with the same xml content but a new docname.

HTH

Thanks again Bill (I believe it’s you again point out my fault)

I’m really too foolish to just blindly try and try and try to debug, without just step back a little to digest the detail documentation of TXMLObject.setDocName() and TXMLObjectAccessor.update().

My apologies and many thanks!!

Best regards,
Lun