Skip to content

Commit

Permalink
Fixed an incompatibility between Record and ProtoUser by introducing …
Browse files Browse the repository at this point in the history
…the saveThisRecord() method
  • Loading branch information
dpp committed Jun 2, 2011
1 parent 5fe041a commit b8f4e35
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ trait CouchRecord[MyType <: CouchRecord[MyType]] extends JSONRecord[MyType] {
/** Save the record instance and return it */
def save: Box[MyType] = for (ok <- meta.save(this)) yield this

/**
* Save the instance and return the instance
*/
override def saveTheRecord(): Box[MyType] = this.save

/** Return whether this instance was saved into the backing store or not */
def saved_? : Boolean = meta.saved_?(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ import net.liftweb.common.{Box, Empty, Failure, Full}
import Box.{box2Iterable, option2Box}
import net.liftweb.http.js.{JsExp, JsObj}
import net.liftweb.json.JsonParser
import net.liftweb.json.JsonAST.{JArray, JBool, JInt, JDouble, JField, JNothing, JNull, JObject, JString, JValue}
import net.liftweb.json.JsonAST._
import net.liftweb.record.{Field, MandatoryTypedField, MetaRecord, Record}
import net.liftweb.record.RecordHelpers.jvalueToJsExp
import net.liftweb.record.FieldHelpers.expectedA
import net.liftweb.record.field._
import net.liftweb.util.ThreadGlobal
import net.liftweb.util.BasicTypesHelpers.{toBoolean, toInt}
import net.liftweb.util.ControlHelpers.tryo
import net.liftweb.util.Helpers.{base64Decode, base64Encode}
import net.liftweb.util.TimeHelpers.{boxParseInternetDate, toInternetDate}
import net.liftweb.util.Helpers._
import java.util.prefs.BackingStoreException

private[couchdb] object JSONRecordHelpers {

Expand Down Expand Up @@ -71,6 +69,13 @@ trait JSONRecord[MyType <: JSONRecord[MyType]] extends Record[MyType] {
* Default implementation preserves the fields intact and returns them via additionalJFields
*/
def additionalJFields_= (fields: List[JField]): Unit = _additionalJFields = fields



/**
* Save the instance and return the instance
*/
override def saveTheRecord(): Box[MyType] = throw new BackingStoreException("JSON Records don't save themselves")
}

object JSONMetaRecord {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import net.liftweb.record.{Field, MetaRecord, Record}
import net.liftweb.record.field._

import com.mongodb._
import java.util.prefs.BackingStoreException

/** Specialized Record that can be encoded and decoded from BSON (DBObject) */
trait BsonRecord[MyType <: BsonRecord[MyType]] extends Record[MyType] {
Expand Down Expand Up @@ -55,6 +56,12 @@ trait BsonRecord[MyType <: BsonRecord[MyType]] extends Record[MyType] {

"%s={%s}" format (this.getClass.toString, fieldList.mkString(", "))
}


/**
* Save the instance and return the instance
*/
override def saveTheRecord(): Box[MyType] = throw new BackingStoreException("BSON Records don't save themselves")
}

/** Specialized MetaRecord that deals with BsonRecords */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package net.liftweb
package mongodb
package record

import net.liftweb.common.{Box, Full}
import net.liftweb.record.{MetaRecord, Record}

import com.mongodb.{BasicDBObject, DBObject, DBRef, WriteConcern}

import org.bson.types.ObjectId
import common.{Full, Box}

trait MongoRecord[MyType <: MongoRecord[MyType]] extends BsonRecord[MyType] {
self: MyType =>
Expand Down Expand Up @@ -52,6 +52,12 @@ trait MongoRecord[MyType <: MongoRecord[MyType]] extends BsonRecord[MyType] {
this
}


/**
* Save the instance and return the instance
*/
override def saveTheRecord(): Box[MyType] = {save; Full(this)}

/**
* Save the instance and return the instance
* @param safe - if true will use WriteConcern SAFE else NORMAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ trait DBRecord[MyType <: DBRecord[MyType]] extends Record[MyType] {
this
}


/**
* Save the instance and return the instance
*/
override def saveTheRecord(): Box[MyType] = {save(); Full(this)}

/**
* Delete the instance from backing store
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ trait MetaMegaProtoUser[ModelType <: MegaProtoUser[ModelType]] extends MetaRecor
/**
* Save the user to backing store
*/
def save(): Boolean = in.save
def save(): Boolean = in.saveTheRecord().isDefined
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import util._
import field._

import scala.xml._
import java.util.prefs.BackingStoreException

trait Record[MyType <: Record[MyType]] extends FieldContainer {
self: MyType =>
Expand Down Expand Up @@ -81,6 +82,11 @@ trait Record[MyType <: Record[MyType]] extends FieldContainer {
* @return a JsObj
*/
def asJSON: JsExp = meta.asJSON(this)

/**
* Save the instance and return the instance
*/
def saveTheRecord(): Box[MyType] = throw new BackingStoreException("Raw Records don't save themselves")

/**
* Retuns the JSON representation of this record, converts asJValue to JsObj
Expand Down

0 comments on commit b8f4e35

Please sign in to comment.