Skip to content

Instantly share code, notes, and snippets.

@Swind
Created October 6, 2011 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swind/1266995 to your computer and use it in GitHub Desktop.
Save Swind/1266995 to your computer and use it in GitHub Desktop.
[Scala][DB] Db4o Example
package tw.teremolo.example
import com.db4o.Db4oEmbedded
import scala.collection.JavaConverters._
/**
* Date: 2011/10/6
* Time: 下午 5:21
*/
object Hello_db4o {
def main(args: Array[String]) {
//accessDb4o
val db = Db4oEmbedded.openFile(Db4oEmbedded.newConfiguration(),"TestDb4O")
//Store Object
db.store(HelloDB4O("Test1","Test1 Title"))
db.store(HelloDB4O("Test2","Test2 Title"))
//Retriaving objects
//Query By Example (QBE)
val QBEResult = db.queryByExample[HelloDB4O](HelloDB4O(null,null))
println("===Query By Example===")
QBEResult.toArray.foreach(
result=>
{
println(result)
//Delete Object
db.delete(result)
}
)
db.close()
}
}
case class HelloDB4O(
name:String,
title:String
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment