Re: [bdbxml] Plz fix me outh with this: Updating documents in container problem
John Snelson <[email protected]> Mon, 19 Sep 2005 11:49:39 +0100
| Newsgroups | gmane.comp.db.dbxml.general |
|---|---|
| Message-ID | <[email protected]> |
You are calling XmlModify.execute() without having first added any
modification steps to the XmlModify object. Since it appears that you
are changing the entire document content, you can use
XmlContainer.updateDocument() to put your modified document back into
the container - and forget about XmlModify altogether.
John
Moe wrote:
> Hi,
>
> I've been reading this newsgroup for quite a while and decided to test Berkeley
> DB XML for myself.
>
> But actually I'm encountering a problem with this method, which is basically
> just made for testing executing document updates on existing documents in a XML-
> database storage:
>
> //-------------------------------
> public void update(String filedescription, String userName, String id, String
> ver_query, String theContainer, String binContent, boolean delete_flag)
> throws Throwable {
>
>
> File path2DbEnv = new File("C:/environment");
>
>
>
> if (path2DbEnv == null || ! path2DbEnv.isDirectory()) {
> usage();
> }
>
> myDbEnv env = null;
> XmlContainer openedContainer = null;
> XmlTransaction txn = null;
> try {
>
> // Open an environment
>
> env = new myDbEnv(path2DbEnv);
> XmlManager theMgr = env.getManager();
>
> // open a transactional container
> XmlContainerConfig config = new XmlContainerConfig();
> config.setTransactional(true);
> config.setErrorStream(System.err);
>
>
> openedContainer = theMgr.openContainer(theContainer, config);
>
> // Start a transaction
> txn = theMgr.createTransaction();
>
>
> XmlQueryContext context=theMgr.createQueryContext();
>
> String fullQuery = ver_query;
> System.out.println("Updating documents for expression: '" + fullQuery
> + "'.");
>
>
> //XmlUpdateContext updateContext = theMgr.createUpdateContext();
>
> //query for all the documents that we want to update
> XmlResults results = theMgr.query(txn, fullQuery, context, null);
> System.out.println("Found "+results.size()+" document(s) matching the
> expression ");
> results.delete();
> //txn.delete();
>
>
> //-->Modify documents
>
> XmlModify mod = theMgr.createModify();
>
> XmlResults allDocsSel = theMgr.query(fullQuery,context);
>
>
> XmlUpdateContext uc = theMgr.createUpdateContext();
> XmlValue thisValue = null;
>
>
> while((thisValue = allDocsSel.next())!=null){
> XmlDocument d = thisValue.asDocument();
> String docString=d.getContentAsString();
> String newDocString=" ";
> if (!delete_flag){newDocString = getNewDocument(theMgr, d,
> context,
> docString, theContainer,
> filedescription, id, binContent);}
> d.setContent(newDocString);
> mod.execute(thisValue,context,uc);
> d.delete();
> }
>
> allDocsSel.delete();uc.delete();thisValue.delete();mod.delete();
>
> } catch (Exception e) {
> System.err.println("Error performing document update against "
> + theContainer);
> System.err.println(" Message: " + e.getMessage());
> //In the event of an error, we abort the operation
> // The database is left in the same state as it was in before
> // we started this operation.
>
> }
> finally {
> //cleanup(env, openedContainer, txn);
> cleanup(env, openedContainer, txn);
> }
> }
> //-------------------------------
>
> This method results in the following compiler errors:
>
> (first part:)
> "Error performing document update against mainDataStorage.dbxml
> Message: null"
>
> What does the null-message refer to?
>
> The error message goes on like this (container in use is named
> mainDataStorage.dbxml):
>
> (second part:)
> "Error: closing the transaction region with active transactions
> Database handles remain at environment close
> Open database handle: mainDataStorage.dbxml/secondary_document_statistics_string
> Open database handle: mainDataStorage.dbxml/secondary_document_index_string
> Open database handle: mainDataStorage.dbxml/node_nodestorage
> Open database handle: mainDataStorage.dbxml/secondary_document
> Open database handle: mainDataStorage.dbxml/secondary_dictionary
> Open database handle: mainDataStorage.dbxml/primary_dictionary
> Open database handle: mainDataStorage.dbxml/secondary_configuration"
>
> I'm working on this for hours, I can't find the cause for this. Any ideas or
> suggestions?
>
>
> Thanks in advance,
>
> M.Brueckner
>
>
>
> ------------------------------------------
> To remove yourself from this list, send an
> email to [email protected]
>
--
John Snelson, Berkeley DB XML Engineer
Sleepycat Software, Inc
http://www.sleepycat.com
Contracted to Sleepycat through Parthenon Computing Ltd
http://blog.parthcomp.com/dbxml
------------------------------------------
To remove yourself from this list, send an
email to [email protected]