Skip to content
laforge49 edited this page Oct 1, 2011 · 4 revisions

Sequences over a collection in a database are best handled by fetching the collection and then doing the sequencing. But if the collection is very large, e.g. it does not fit in memory, this may not be practical. DbIntSeq[V], DbLongSeq[V] and DbStringSeq[V] are subclasses of Sequence[K, V] and let you sequence over a collection in a database without having to fetch the collection.

The test code for DbIntSeq, DbLongSeq and DbStringSeq are very similar. Really the only difference is the ordering of strings vs the ordering of integers and longs. Here's the test code for DbIntSeq.

val systemServices = SystemServices(new ServicesRootComponentFactory)
val dbName = "DbIntSeqNoLog.db"
val file = new java.io.File(dbName)
file.delete
val properties = new Properties
properties.put("dbPathname", dbName)
val db = Subsystem(
  systemServices,
  new SmallNoLogComponentFactory,
  properties = properties,
  actorId = ActorId("db"))
val one = IncDesString(null)
val two = IncDesString(null)
val three = IncDesString(null)
val ten = IncDesString(null)
val dbIntSeq = new DbIntSeq[IncDesString](db, "/$")
val chain = new Chain
chain.op(systemServices, Register(db))
chain.op(db, SetRequest(db, "/$", IncDesIntStringMap(null, db)))
chain.op(one, Set(null, "One"))
chain.op(db, SetRequest(db, "/$/1", one))
chain.op(two, Set(null, "Two"))
chain.op(db, SetRequest(db, "/$/2", two))
chain.op(db, SetRequest(db, "/$/2", null))
chain.op(three, Set(null, "Three"))
chain.op(db, SetRequest(db, "/$/3", three))
chain.op(ten, Set(null, "Ten"))
chain.op(db, SetRequest(db, "/$/10", ten))
chain.op(dbIntSeq, First(), "a")
chain.op(dbIntSeq, Current(3), "b")
chain.op(dbIntSeq, Next(3), "c")
Future(systemServices, chain)
println(chain.results)
systemServices.close

Output.

{a=KVPair(1,org.agilewiki.incDes.IncDesString@19381960), 
b=KVPair(3,org.agilewiki.incDes.IncDesString@3209fa8f), 
c=KVPair(10,org.agilewiki.incDes.IncDesString@2d20dbf3)}

DbIntSeqTest
DbLongSeqTest
DbStringSeqTest

tutorial

Clone this wiki locally