Dear BaseXers,
So far, BaseX has been a lot of fun to work with! Thanks for all your efforts on this codebase.
i've got a couple of questions, though.
- Whether i've got no documents in a freshly created BXCollection, or i've ensured that there is at least one document present, a call to listResources always throws an IndexOutOfBounds exception. Is that the intended behavior? - The reason i'm using this API is that i need to be able to update a single document in a collection guaranteed to have exactly one document. So, i thought i would simply ask the BXCollection to list it's resources, grab the first one (since there should only be one) and then use the id from the list returned by that API in subsequent queries. Maybe that's not the preferred approach? Is there a better one?
Any help would be greatly appreciated.
Best wishes,
--greg
override def getCollection( createIfMissing : Boolean )( xmlCollStr : String ) : Option[Collection] = { try { // BUGBUG -- LGM the semantics of BXCollection a little // different than createIfMissing; and requires catching the // database not found exception Some( new BXCollection( xmlCollStr, true ) ) } catch { case e : XMLDBException => { val bxColl = new BXCollection( xmlCollStr, false ) val document = bxColl.createResource( null, XMLResource.RESOURCE_TYPE ).asInstanceOf[XMLResource]
document.setContent( "<database></database>" ) bxColl.storeResource( document ) Some( bxColl ) } case _ => None } }
override def update( xmlCollStr : String )( cnxn : CnxnCtxtLabel[Namespace,Var,String] ) : Unit = { for( xmlColl <- getCollection( true )( xmlCollStr ) ) { val resourceList : Array[String] = xmlColl.listResources if ( resourceList.size == 0 ) { val document = xmlColl.createResource( null, XMLResource.RESOURCE_TYPE ).asInstanceOf[XMLResource]
document.setContent( xmlIfier.asXML( cnxn ).toString ) xmlColl.storeResource( document ) } else { val cnxnElem = xmlIfier.asXML( cnxn ) cnxnElem match { case cElem : Elem => { delete( xmlCollStr, resourceList( 0 ) )( cElem ) insert( xmlCollStr, resourceList( 0 ) )( cElem ) } case _ => { throw new Exception( "record is not an XML element" ) } } } } }
<tweet>storing to db : org.basex.api.xmldb.BXDatabase@77dc754 pair : record(contactMeUsing(email), {"com.biosimilarity.lift.model.store.MonadicTermTypes_-Ground":{"v":{"@class":"string","$":"for the win Mikail.Mauz@gmail.com"},"_-outer":{"@class":"com.biosimilarity.lift.model.store.PersistedMonadicTS$TheMTT$"}}}) in coll : Squibble</tweet> java.lang.IndexOutOfBoundsException at java.io.RandomAccessFile.readBytes(Native Method) at java.io.RandomAccessFile.read(RandomAccessFile.java:322) at java.io.RandomAccessFile.readFully(RandomAccessFile.java:381) at org.basex.io.DataAccess.cursor(DataAccess.java:225) at org.basex.io.DataAccess.readToken(DataAccess.java:147) at org.basex.data.DiskData.txt(DiskData.java:213) at org.basex.data.DiskData.text(DiskData.java:181) at org.basex.api.xmldb.BXCollection.listResources(BXCollection.java:128) at com.biosimilarity.lift.model.store.xml.BaseXCnxnStorage$$anonfun$update$1.apply(BaseXXMLPersist.scala:313) at com.biosimilarity.lift.model.store.xml.BaseXCnxnStorage$$anonfun$update$1.apply(BaseXXMLPersist.scala:312) at scala.Option.foreach(Option.scala:185) at com.biosimilarity.lift.model.store.xml.BaseXCnxnStorage$class.update(BaseXXMLPersist.scala:312) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction.update(PersistedMonadicTermStore.scala:321) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction$$anonfun$putInStore$3$$anonfun$apply$12$$anonfun$apply$13.apply(PersistedMonadicTermStore.scala:468) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction$$anonfun$putInStore$3$$anonfun$apply$12$$anonfun$apply$13.apply(PersistedMonadicTermStore.scala:459) at scala.Option.foreach(Option.scala:185) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction$$anonfun$putInStore$3$$anonfun$apply$12.apply(PersistedMonadicTermStore.scala:459) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction$$anonfun$putInStore$3$$anonfun$apply$12.apply(PersistedMonadicTermStore.scala:458) at scala.Option.foreach(Option.scala:185) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction$$anonfun$putInStore$3.apply(PersistedMonadicTermStore.scala:458) at com.biosimilarity.lift.model.store.PersistedTermStoreScope$PersistedMonadicGeneratorJunction$$anonfun$putInStore$3.apply(PersistedMonadicTermStore.scala:458) at scala.util.continuations.package$.run(package.scala:30) at scala.concurrent.cpsops$$anonfun$spawn$1.apply$mcV$sp(cpsops.scala:9) at scala.concurrent.FJTaskRunners$FJTaskRunner$$anon$1.compute(FJTaskRunners.scala:21) at jsr166y.forkjoin.RecursiveAction.exec(RecursiveAction.java:247) at jsr166y.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:286)