Skip to content

Instantly share code, notes, and snippets.

@agnaldo4j
Created October 14, 2011 16:23
Show Gist options
  • Save agnaldo4j/1287575 to your computer and use it in GitHub Desktop.
Save agnaldo4j/1287575 to your computer and use it in GitHub Desktop.
Operações básicas com riak usando scala
package com.softsimples.social.persistence
import scala.collection.JavaConverters._
import com.basho.riak.client.bucket.Bucket
import org.json.JSONObject
class HashWrapper(private var bucket:Bucket) {
def name():String = bucket.getName
def keys(): Iterator[String] = bucket.keys().iterator.asScala
def store(key:String, value:String): String = {
bucket.store[String](key, value).execute()
}
def delete(key:String) = {
bucket.delete(key).execute()
}
def fetch(key:String): JSONObject = {
var retorno:JSONObject = new JSONObject()
val riakObject = bucket.fetch(key).execute()
if (riakObject != null) retorno = new JSONObject( riakObject.getValueAsString )
retorno
}
}
object HashWrapper {
def buildTableWrapper(bucket:Bucket): HashWrapper = new HashWrapper( bucket )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment