Created
October 6, 2011 09:49
-
-
Save Swind/1266995 to your computer and use it in GitHub Desktop.
[Scala][DB] Db4o Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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