how to use API to manage data without serialization? and data inconsistency issue

12 views
Skip to first unread message

Sophie

unread,
Jun 24, 2009, 4:20:18 PM6/24/09
to xbird-users
Hi,

I'm trying to use xbird as an embedded xml data store and query engine
for my java application.

I have two questions about xbird. My application takes in little xml
as string from clients. I don't really need to de-serialize an xml
string to some XStream annotated objects before saving it. Is there an
API to store the XML directly without using object binding?

My second question is related to the database inconsistency I
experienced. I attempted to do the following:
1) Write a class called MyInvoker, which is almost identical to
CommandInvoker, except that the run() function is public, so that I
can call it from my program.
2) Whenever my application (a server) receives an XML piece from a
client, write to a temporary file.
3) Call MyInvoker to store the XML file.
4) When my application receives a delete command, I simply remove the
file on the disk.

It works okay to add a file. However, I found that this approach
leaves the database in an inconsistent state. If I add an XML then
delete it immediately, the file cannot be deleted. After a while, if I
try deletion again, it works. Similarly, if I run a get_count xquery
immediately after the xml is added, the count does not increment.so,
how to avoid the data inconsistency issue? Is there a better strategy?

Thanks

Sophie

unread,
Jun 24, 2009, 7:26:07 PM6/24/09
to xbird-users
I tried XBirdCollectionStrategyTest from xbird source and ran into a
similar problem. It could not delete dtms files from hard drive. I
guess the file lock is not release after the xml files are added. I
use Windows XP and the stack trace is:
java.io.IOException: Unable to delete file: C:\DOCUME~1\xqian
\LOCALS~1\Temp\xbird\xstreamTest\0.xml.dtms
at xbird.util.io.FileUtils.cleanDirectory(FileUtils.java:171)
at xbird.ext.xstream.XBirdCollectionStrategyTest.tearDown
(XBirdCollectionStrategyTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod
(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runAfters
(BeforeAndAfterRunner.java:65)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:37)
at org.junit.internal.runners.TestMethodRunner.runMethod
(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run
(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run
(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run
(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
(RemoteTestRunner.java:196)

Makoto YUI

unread,
Jun 26, 2009, 5:35:50 AM6/26/09
to xbird...@googlegroups.com
Sophie wrote:
>
> I have two questions about xbird. My application takes in little xml
> as string from clients. I don't really need to de-serialize an xml
> string to some XStream annotated objects before saving it. Is there an
> API to store the XML directly without using object binding?

Though API is not officially provided, you can use an internal
API: xbird.client.command.ImportDocument#loadDocument.

Or, you can use a XQuery function:
ext:import-document(docPath as xs:string, colPath as xs:string) as
document().

> My second question is related to the database inconsistency I
> experienced. I attempted to do the following:
> 1) Write a class called MyInvoker, which is almost identical to
> CommandInvoker, except that the run() function is public, so that I
> can call it from my program.
> 2) Whenever my application (a server) receives an XML piece from a
> client, write to a temporary file.
> 3) Call MyInvoker to store the XML file.
> 4) When my application receives a delete command, I simply remove the
> file on the disk.
>
> It works okay to add a file. However, I found that this approach
> leaves the database in an inconsistent state. If I add an XML then
> delete it immediately, the file cannot be deleted. After a while, if I
> try deletion again, it works. Similarly, if I run a get_count xquery
> immediately after the xml is added, the count does not increment.so,
> how to avoid the data inconsistency issue? Is there a better strategy?

You have to explicitly call IDocumentTable#close() because
the embedded database system holds loaded XML documents in the cache
as long as they are used in applications.

The system cannot recognize whether an XML document is used or not
without explicit acknowledgment from clients.

> java.io.IOException: Unable to delete file:
C:\DOCUME~1\xqian\LOCALS~1\Temp\xbird\xstreamTest\0.xml.dtms
> at xbird.util.io.FileUtils.cleanDirectory(FileUtils.java:171)

I am aware of this problem.
XBirdCollectionStrategyTest does not properly work on windows.

Makoto YUI

Message has been deleted

Makoto YUI

unread,
Jun 27, 2009, 9:45:54 PM6/27/09
to xbird-users
xbird.storage.DbCollection#removeDocument(null, docmentName)
safely removes the specified XML document in the collection.

Thanks

Makoto
Reply all
Reply to author
Forward
0 new messages