Permalink
Browse files

Updated for use with mongo-java-driver 1.4 and lift 2.0-M4

  • Loading branch information...
1 parent 810e1d6 commit 8110ef112c73abccd16cb6157fae6bb4298bc780 @eltimn committed Apr 26, 2010
View
@@ -1,3 +1,10 @@
+README: Scamongo is being moved to the Lift project. In doing so I'm comtemplating
+what to do with the scamongo-document part of this library. I'm trying to decide if I
+should move that with it, discontinue support for it, or keep it as a separate project.
+Please contact me if you are using this at all and let me know what you think.
+
+Tim
+
See wiki for project info.
To build you will need to use sbt
@@ -7,9 +14,26 @@ Jar is available at:
http://dl.dropbox.com/u/1154284/scamongo-0.1.jar
http://dl.dropbox.com/u/1154284/scamongo-0.1.1.jar
http://dl.dropbox.com/u/1154284/scamongo-0.1.2.jar
+http://dl.dropbox.com/u/1154284/scamongo-0.1.3.jar
h2. Release Notes
+*version-0.1.3*
+* Updated for use with mongo-java-driver 1.4 and lift 2.0-M4
+NOTE: There is a small breaking change in this version for scamongo-record users;
+record companion objects must now include a createRecord method. Here's an example:
+
+class TestRecord extends MongoRecord[TestRecord] with MongoId[TestRecord] {
+
+ def meta = TestRecord
+
+ object stringfield extends StringField(this, 32)
+}
+
+object TestRecord extends TestRecord with MongoMetaRecord[TestRecord] {
+ def createRecord = new TestRecord
+}
+
*version-0.1.2*
* Added harryh's changes to DBRef
View
@@ -1,8 +1,8 @@
#Project properties
-#Tue Mar 30 11:20:07 CDT 2010
+#Mon Apr 26 13:31:31 CDT 2010
project.organization=com.eltimn
project.name=scamongo
sbt.version=0.5.6
-project.version=0.1.3
+project.version=0.1.4
scala.version=2.7.7
project.initialize=false
@@ -4,13 +4,13 @@ class ScamongoProject(info: ProjectInfo) extends DefaultProject(info) {
//override def compileOptions = super.compileOptions ++ Seq(Unchecked)
- val mongo = "org.mongodb" % "mongo-java-driver" % "1.3" % "compile->default"
+ val mongo = "org.mongodb" % "mongo-java-driver" % "1.4" % "compile->default"
- val liftjson = "net.liftweb" % "lift-json" % "2.0-M3" % "compile->default"
- val liftrecord = "net.liftweb" % "lift-record" % "2.0-M3" % "compile->default"
+ val liftjson = "net.liftweb" % "lift-json" % "2.0-M4" % "compile->default"
+ val liftrecord = "net.liftweb" % "lift-record" % "2.0-M4" % "compile->default"
- val junit = "junit" % "junit" % "4.5"
- val specs = "org.scala-tools.testing" % "specs" % "1.5.0"
+ val junit = "junit" % "junit" % "4.7"
+ val specs = "org.scala-tools.testing" % "specs" % "1.6.1"
// other repositories
//val scalaToolsSnapshots = ScalaToolsSnapshots
@@ -16,9 +16,10 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
-import net.liftweb.common.{Box, Empty, Failure, Full}
-import net.liftweb.http.js.JE.Str
-import net.liftweb.record.{Field, Record}
+import _root_.net.liftweb.common.{Box, Empty, Failure, Full}
+import _root_.net.liftweb.http.js.JE.Str
+import _root_.net.liftweb.json.JsonAST.{JNothing, JObject, JValue}
+import _root_.net.liftweb.record.{Field, Record}
import com.mongodb.{BasicDBObject, BasicDBObjectBuilder, DBObject, DBRef, ObjectId}
import com.mongodb.util.JSON
@@ -28,7 +29,7 @@ import com.mongodb.util.JSON
*/
//abstract class MongoRefField[OwnerType <: MongoRecord[OwnerType]](rec: OwnerType)
//abstract class MongoRefField[OwnerType <: MongoRecord[OwnerType], RefType <: MongoMetaRecord[RefType]](rec: OwnerType, ref: RefType)
-abstract class DBRefField[OwnerType <: MongoRecord[OwnerType], RefType <: MongoRecord[RefType]](rec: OwnerType, ref: RefType)
+class DBRefField[OwnerType <: MongoRecord[OwnerType], RefType <: MongoRecord[RefType]](rec: OwnerType, ref: RefType)
extends Field[DBRef, OwnerType] {
/*
@@ -53,6 +54,10 @@ abstract class DBRefField[OwnerType <: MongoRecord[OwnerType], RefType <: MongoR
private var _calcedObj = false
def asJs = Str(toString)
+
+ def asJValue = (JNothing: JValue) // not implemented
+
+ def setFromJValue(jvalue: JValue) = Empty // not implemented
def asXHtml = <div></div>
@@ -16,15 +16,19 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
-import net.liftweb.common.{Box, Empty, Failure, Full}
-import net.liftweb.http.js.JE.Str
-import net.liftweb.json.JsonAST.JObject
-import net.liftweb.json.JsonParser
-import net.liftweb.record.{Field, Record}
+import _root_.net.liftweb.common.{Box, Empty, Failure, Full}
+import _root_.net.liftweb.http.js.JE.Str
+import _root_.net.liftweb.json.JsonAST.{JNothing, JObject, JValue}
+import _root_.net.liftweb.json.JsonParser
+import _root_.net.liftweb.record.{Field, Record}
class JObjectField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends Field[JObject, OwnerType] {
def asJs = Str(toString)
+
+ def asJValue = (JNothing: JValue) // not implemented
+
+ def setFromJValue(jvalue: JValue) = Empty // not implemented
def asXHtml = <div></div>
@@ -20,10 +20,10 @@ import java.util.Date
import scala.collection.jcl.Conversions._
-import net.liftweb.common.{Box, Empty, Failure, Full}
-import net.liftweb.json.JsonAST.JObject
-import net.liftweb.http.js.JE.Str
-import net.liftweb.record.{Field, Record}
+import _root_.net.liftweb.common.{Box, Empty, Failure, Full}
+import _root_.net.liftweb.json.JsonAST.{JNothing, JObject, JValue}
+import _root_.net.liftweb.http.js.JE.Str
+import _root_.net.liftweb.record.{Field, Record}
import com.mongodb._
import com.mongodb.util.JSON
@@ -37,6 +37,10 @@ class MongoListField[OwnerType <: MongoRecord[OwnerType], ListType](rec: OwnerTy
import Meta.Reflection._
def asJs = Str(toString)
+
+ def asJValue = (JNothing: JValue) // not implemented
+
+ def setFromJValue(jvalue: JValue) = Empty // not implemented
def asXHtml = <div></div>
@@ -16,20 +16,25 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
-import net.liftweb.common.{Box, Empty, Failure, Full}
-import net.liftweb.http.js.JE.Str
-import net.liftweb.record.{Field, Record}
-import net.liftweb.util.Log
+import _root_.net.liftweb.common.{Box, Empty, Failure, Full}
+import _root_.net.liftweb.http.js.JE.Str
+import _root_.net.liftweb.json.JsonAST.{JNothing, JValue}
+import _root_.net.liftweb.record.{Field, Record}
+import _root_.net.liftweb.util.Log
import com.mongodb._
class MongoMapField[OwnerType <: MongoRecord[OwnerType], MapValueType](rec: OwnerType)
extends Field[Map[String, MapValueType], OwnerType]
with MongoFieldFlavor[Map[String, MapValueType]] {
- def asJs = Str(toString)
+ def asJs = Str(toString) // not implemented
+
+ def asJValue = (JNothing: JValue) // not implemented
+
+ def setFromJValue(jvalue: JValue) = Empty // not implemented
- def asXHtml = <div></div>
+ def asXHtml = <div></div> // not implemented
def defaultValue = Map[String, MapValueType]()
@@ -50,7 +55,7 @@ class MongoMapField[OwnerType <: MongoRecord[OwnerType], MapValueType](rec: Owne
}
}
- def toForm = <div></div>
+ def toForm = <div></div> // not implemented
def owner = rec
@@ -16,9 +16,11 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
-import net.liftweb.common.{Box, Empty, Failure, Full}
-import net.liftweb.http.js.JE.Str
-import net.liftweb.record.{Field, Record}
+import _root_.net.liftweb.common.{Box, Empty, Failure, Full}
+import _root_.net.liftweb.http.js.JE.{JsNull, Str}
+import _root_.net.liftweb.json.JsonAST.{JNothing, JNull, JString, JValue}
+import _root_.net.liftweb.record.{Field, Record}
+import _root_.net.liftweb.record.FieldHelpers
import com.mongodb.{ObjectId, DBRef}
@@ -27,8 +29,16 @@ import com.mongodb.{ObjectId, DBRef}
*/
class ObjectIdField[OwnerType <: MongoRecord[OwnerType]](rec: OwnerType)
extends Field[ObjectId, OwnerType] {
-
- def asJs = Str(toString)
+
+ def asJs = valueBox.map(v => Str(v.toString)) openOr JsNull
+
+ def asJValue: JValue = valueBox.map(v => JString(v.toString)) openOr (JNothing: JValue)
+
+ def setFromJValue(jvalue: JValue): Box[ObjectId] = jvalue match {
+ case JNothing|JNull if optional_? => setBox(Empty)
+ case JString(s) => setFromString(s)
+ case other => setBox(FieldHelpers.expectedA("JString", other))
+ }
def asXHtml = <div></div>
@@ -33,9 +33,9 @@ import com.mongodb.{BasicDBObject, BasicDBObjectBuilder, DBObject}
object DirectExamples extends Specification {
- doFirst {
+ doBeforeSpec {
// define the db
- MongoDB.defineDb(DefaultMongoIdentifier, MongoAddress(MongoHost("localhost", 27017), "test_direct"))
+ MongoDB.defineDb(DefaultMongoIdentifier, MongoAddress(MongoHost(), "test_direct"))
}
import com.mongodb.util.JSON // Mongo parser/serializer
@@ -228,15 +228,15 @@ object DirectExamples extends Specification {
doc2.put("type", "db")
doc2.put("count", 1)
- doc3.put("name", "MongoDB")
+ doc3.put("name", "MongoDB")
doc3.put("type", "db")
doc3.put("count", 1)
// save the docs to the db
coll.save(doc)
db.getLastError.get("err") must beNull
coll.save(doc2) // this should return an error
- db.getLastError.get("err").toString must startWith("E11000 duplicate key errorindex")
+ db.getLastError.get("err").toString must startWith("E11000 duplicate key error index")
coll.save(doc3)
db.getLastError.get("err") must beNull
@@ -290,7 +290,7 @@ object DirectExamples extends Specification {
})
}
- doLast {
+ doAfterSpec {
if (!debug) {
/* drop the collections */
MongoDB.useCollection(DefaultMongoIdentifier, "testCollection") ( coll => {
@@ -41,7 +41,7 @@ object TestDBb extends MongoIdentifier {
//class DocumentExampleTest extends Runner(DocumentExamples) with JUnit
object DocumentExamples extends Specification {
- doFirst {
+ doBeforeSpec {
// create a Mongo instance
val mongoHost = MongoHost("localhost", 27017)
// define the dbs
@@ -325,7 +325,7 @@ object DocumentExamples extends Specification {
TestCollection.save(tc, db)
db.getLastError.get("err") must beNull
TestCollection.save(tc2, db) // this should return an error
- db.getLastError.get("err").toString must startWith("E11000 duplicate key errorindex")
+ db.getLastError.get("err").toString must startWith("E11000 duplicate key error index")
TestCollection.save(tc3, db)
db.getLastError.get("err") must beNull
@@ -443,7 +443,7 @@ object DocumentExamples extends Specification {
}
- doLast {
+ doAfterSpec {
if (!debug) {
/** drop the collections */
SimplePerson.drop
@@ -40,7 +40,7 @@ object RecordExamples extends Specification {
val debug = false
- doFirst {
+ doBeforeSpec {
// define the db
MongoDB.defineDb(DefaultMongoIdentifier, MongoAddress(MongoHost("localhost", 27017), "test_record"))
}
@@ -312,7 +312,7 @@ object RecordExamples extends Specification {
}
}
- doLast {
+ doAfterSpec {
if (!debug) {
/** drop the collections */
TestRecord.drop
@@ -390,7 +390,9 @@ class TestRecord extends MongoRecord[TestRecord] {
*/
}
-object TestRecord extends TestRecord with MongoMetaRecord[TestRecord]
+object TestRecord extends TestRecord with MongoMetaRecord[TestRecord] {
+ def createRecord = new TestRecord
+}
case class RPerson(name: String, age: Int, address: Address, children: List[Child])
extends JsonObject[RPerson] {
@@ -414,12 +416,16 @@ class MainDoc extends MongoRecord[MainDoc] with MongoId[MainDoc] {
def obj = RefDoc.find(value)
}
}
-object MainDoc extends MainDoc with MongoMetaRecord[MainDoc]
+object MainDoc extends MainDoc with MongoMetaRecord[MainDoc] {
+ def createRecord = new MainDoc
+}
class RefDoc extends MongoRecord[RefDoc] with MongoId[RefDoc] {
def meta = RefDoc
}
-object RefDoc extends RefDoc with MongoMetaRecord[RefDoc]
+object RefDoc extends RefDoc with MongoMetaRecord[RefDoc] {
+ def createRecord = new RefDoc
+}
// string as id
class RefStringDoc extends MongoRecord[RefStringDoc] {
@@ -436,7 +442,9 @@ class RefStringDoc extends MongoRecord[RefStringDoc] {
new DBRef(db, meta.collectionName, _id.value)
)
}
-object RefStringDoc extends RefStringDoc with MongoMetaRecord[RefStringDoc]
+object RefStringDoc extends RefStringDoc with MongoMetaRecord[RefStringDoc] {
+ def createRecord = new RefStringDoc
+}
class ListDoc extends MongoRecord[ListDoc] with MongoId[ListDoc] {
def meta = ListDoc
@@ -505,7 +513,8 @@ class ListDoc extends MongoRecord[ListDoc] with MongoId[ListDoc] {
}
object ListDoc extends ListDoc with MongoMetaRecord[ListDoc] {
- override def formats = DefaultFormats.lossless // adds .000
+ override def formats = DefaultFormats.lossless // adds .000 to Dates
+ def createRecord = new ListDoc
}
case class JsonDoc(id: String, name: String) extends JsonObject[JsonDoc] {
@@ -525,6 +534,7 @@ class MapDoc extends MongoRecord[MapDoc] with MongoId[MapDoc] {
}
object MapDoc extends MapDoc with MongoMetaRecord[MapDoc] {
override def formats = DefaultFormats.lossless // adds .000
+ def createRecord = new MapDoc
}
class OptionalDoc extends MongoRecord[OptionalDoc] with MongoId[OptionalDoc] {
@@ -535,5 +545,7 @@ class OptionalDoc extends MongoRecord[OptionalDoc] with MongoId[OptionalDoc] {
override def defaultValue = "nothin"
}
}
-object OptionalDoc extends OptionalDoc with MongoMetaRecord[OptionalDoc]
+object OptionalDoc extends OptionalDoc with MongoMetaRecord[OptionalDoc] {
+ def createRecord = new OptionalDoc
+}

0 comments on commit 8110ef1

Please sign in to comment.