Reputation: 109
I have created one method "saveInDB" which will takes 3 parameters which are passed to "imgData()" class from where all values are set to object "picDetail" of that class when i push to store to riak database only keys are stored but objects of picDetail are not being stored. I can't figure it out what's happening.
val riakClient = RiakFactory.pbcClient
val bucketName = riakClient.createBucket("bucket_name").execute
def saveInDB(title: String, desc: String, imageName: String ): Boolean = {
val picDetail = new imgData()
picDetail.title = title
picDetail.desc = desc
val s = imageName.replace(".png", "")
picDetail.imageName = imageName
try{
riakBucketName.store(s , picDetail).execute
true
}catch{
case e: Exception => false
}
}
@Update: Riak Version : 1.3.2 and Riak Java Client : 1.1.4
Any idea will be greatly appreciated. Thanks in advance
Upvotes: 1
Views: 87
Reputation: 109
Just found out another easy way to store.
def saveInDB(title: String, desc:String, imageName: String ): Boolean ={
val obj = ImgData(title, desc, imageName)
val s:String = imageName.replace(".png", "")
val jsonString: String = generate(obj)
var riakObject = RiakObjectBuilder.
newBuilder("bucket_name", s).
withContentType("application/json").
withValue(jsonString).
build
try{
riakBucketName.store(s, riakObject).returnBody(true).execute
fetchUserData(userID)
true
}catch{
case e: Exception => e
}
true
}
Upvotes: 1
Reputation: 109
I figured out the Solution as i tried to pass object "picDetail" to riak it is unable to store so i convert the object into json String. Now it is working fine. My code is like
case class ImgData(
title: String,
desc: String,
imageName: String
)
def getJsonString(title:String, desc:String, imageName:String) : String = {
import play.api.libs.json._
import play.api.libs.functional.syntax._
implicit val cardsWrites: Writes[CardsModel] = (
(__ \ "title").write[String] and
(__ \ "desc").write[String] and
(__ \ "imageName").write[String]
)(unlift(ImgData.unapply))
val jObject = (title, desc, imageName)
val jString = Json.toJson(jObject)
jString.toString
}
def saveInDB(title: String, desc:String, imageName: String ): Boolean ={
val obj:String = getJsonString(title, desc, imageName)
val s:String = imageName.replace(".png", "")
try{
riakBucketName.store(s ,obj).execute
true
}catch{
case e: Exception => false
}
true
}
Thank you!
Upvotes: 1