Advertisement
Guest User

Scala Example

a guest
Jan 19th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.65 KB | None | 0 0
  1. import com.mongodb.casbah.Imports._
  2.  
  3. class Report(builder: ReportBuilder) {
  4. var result = builder.result
  5.  
  6. def save = {
  7. val mongoObj = buildMongoDbObject
  8. MongoFactory.getCollection(MongoFactory.getConnection).save(mongoObj)
  9. }
  10.  
  11. def buildMongoDbObject: MongoDBObject = {
  12. val builder = MongoDBObject.newBuilder
  13. builder += "result" -> this.result
  14. builder += "_id" -> "report"
  15. builder.result
  16. }
  17. }
  18.  
  19.  
  20. object Report {
  21. def newBuilder: ReportBuilder = new ReportBuilder()
  22. }
  23.  
  24.  
  25. class ReportBuilder{
  26. var result: Boolean = true
  27.  
  28. def setResult(result:Boolean): ReportBuilder = {
  29. this.result = result
  30. this
  31. }
  32.  
  33. def build: Report = new Report(this)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement