Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed an incompatibility between Record and ProtoUser by introducing …

…the saveThisRecord() method
  • Loading branch information...
commit b8f4e353418d7b5fc38b33497d7744ee46e0b5c7 1 parent 5fe041a
@dpp dpp authored
View
5 persistence/couchdb/src/main/scala/net/liftweb/couchdb/CouchRecord.scala
@@ -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)
View
15 persistence/couchdb/src/main/scala/net/liftweb/couchdb/JSONRecord.scala
@@ -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 {
@@ -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 {
View
7 persistence/mongodb-record/src/main/scala/net/liftweb/mongodb/record/BsonRecord.scala
@@ -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] {
@@ -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 */
View
8 persistence/mongodb-record/src/main/scala/net/liftweb/mongodb/record/MongoRecord.scala
@@ -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 =>
@@ -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
View
6 persistence/record/src/main/scala/net/liftweb/record/DBRecord.scala
@@ -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
*/
View
2  persistence/record/src/main/scala/net/liftweb/record/ProtoUser.scala
@@ -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
}
/**
View
6 persistence/record/src/main/scala/net/liftweb/record/Record.scala
@@ -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 =>
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.