-
-
Save conikeec/1507393 to your computer and use it in GitHub Desktop.
Usando Riak com Scala
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 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