Monday, November 28, 2011

Entity abstraction for Scalapi

I created an abstraction for storing and accessing persistent entities using the Scalapi library.

I find it useful when experimenting with various data providers and comparing benchmarks results.

Below you can see example of its usage to feel the flavor of this API.
// Define entity class
case class SampleEntity(id: String) extends Entity[String] {
  entityId = Some(id)

// create DB4O entity store
val objectContainer = Db4oEmbedded.openFile("/tmp/db")
val entityStore = new Db4oEntityStore(objectContainer)

// Store entity SampleEntity("id"))

// Find entity
val query: Predicate[SampleEntity] = (entity: SampleEntity) => entity.getEntityId() == Some("id")
val results = store.query[SampleEntity](query)

No comments:

Post a Comment