Skip to content

Instantly share code, notes, and snippets.

@conikeec
Forked from agnaldo4j/DBWrapper.scala
Created December 21, 2011 19:48
Show Gist options
  • Save conikeec/1507393 to your computer and use it in GitHub Desktop.
Save conikeec/1507393 to your computer and use it in GitHub Desktop.
Usando Riak com Scala
package com.softsimples.social.persistence
import scala.collection.JavaConverters._
import com.basho.riak.client.{IRiakClient, RiakFactory}
import com.basho.riak.client.bucket.Bucket
class DBWrapper(private val riakClient:IRiakClient) {
def createHashWrapperFor( bucketName:String ): HashWrapper = {
HashWrapper.buildTableWrapper( buildBucket( bucketName ) )
}
private def buildBucket( bucketName:String ): Bucket = {
var bucket = riakClient.fetchBucket( bucketName ).execute()
if (bucket == null) bucket = riakClient.createBucket(bucketName).nVal(1).execute()
bucket
}
def listOfTables(): Set[String] = riakClient.listBuckets.asScala.toSet[String]
}
object DBWrapper {
def buildDBWrapper(host:String, port:Int): DBWrapper = new DBWrapper( RiakFactory.pbcClient(host, port) )
def buildDBWrapper(host:String): DBWrapper = new DBWrapper( RiakFactory.pbcClient(host, 8087) )
def buildDBWrapper(): DBWrapper = new DBWrapper( RiakFactory.pbcClient("127.0.0.1", 8087) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment