Skip to content
Browse files

Clean up and refactor MapperSpec to run under SBT

Closes #927

Had to refactor quite a bit of the setup code to ensure that
it was being run. The previous incarnation relied on JUnit's
ordering guarantees, which didn't appear to hold under SBT.
Among other things, the MapperRules object appeared to actually
have multiple instances, as some runs failed because it had
default values instead of those configured!
  • Loading branch information...
1 parent 58ee9a0 commit b8eb1d0828500d1e2a457185420b8463482783e9 @dchenbecker dchenbecker committed Mar 9, 2011
View
8 persistence/mapper/src/main/scala/net/liftweb/mapper/Schemifier.scala
@@ -332,9 +332,13 @@ object Schemifier extends Loggable {
() => "ALTER TABLE "+table._dbTableNameLC+" ADD FOREIGN KEY ( "+field._dbColumnNameLC+" ) REFERENCES "+other._dbTableNameLC+" ( "+field.dbKeyToColumn._dbColumnNameLC+" ) "
}
field.dbAddedForeignKey.toList
- } else Nil
+ } else {
+ Nil
+ }
}
- } else Nil
+ } else {
+ Nil
+ }
Collector(ret, cmds.toList)
}
View
30 persistence/mapper/src/test/scala/net/liftweb/mapper/MappedLongForeignKeySpec.scala
@@ -27,24 +27,22 @@ import util._
* Systems under specification for MappedLongForeignKey.
*/
object MappedLongForeignKeySpec extends Specification("MappedLongForeignKey Specification") {
- def provider = DbProviders.H2MemoryProvider
-
- def doLog = false
-
- private def ignoreLogger(f: => AnyRef): Unit = ()
-
- def cleanup() {
- try { provider.setupDB } catch { case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e)) }
- Schemifier.destroyTables_!!(DefaultConnectionIdentifier, if (doLog) Schemifier.infoF _ else ignoreLogger _, SampleTag, SampleModel, Dog, Mixer, Dog2, User)
- Schemifier.destroyTables_!!(DbProviders.SnakeConnectionIdentifier, if (doLog) Schemifier.infoF _ else ignoreLogger _, SampleTagSnake, SampleModelSnake)
- Schemifier.schemify(true, if (doLog) Schemifier.infoF _ else ignoreLogger _, DefaultConnectionIdentifier, SampleModel, SampleTag, User, Dog, Mixer, Dog2)
- Schemifier.schemify(true, if (doLog) Schemifier.infoF _ else ignoreLogger _, DbProviders.SnakeConnectionIdentifier, SampleModelSnake, SampleTagSnake)
- }
+ // Make sure we have everything configured first
+ MapperSpecsModel.setup()
+ def provider = DbProviders.H2MemoryProvider
"MappedLongForeignKey" should {
+ doBefore {
+ (try {
+ provider.setupDB
+ MapperSpecsModel.cleanup()
+ } catch {
+ case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e))
+ }) must not(throwAnException[Exception]).orSkipExample
+ }
+
"Not allow comparison to another FK" in {
- cleanup()
val dog = Dog.create.name("Froo").saveMe
val user = {
def ret: User = {
@@ -63,24 +61,20 @@ object MappedLongForeignKeySpec extends Specification("MappedLongForeignKey Spec
}
"be primed after setting a reference" in {
- cleanup()
val dog = Dog.create
val user = User.create
dog.owner(user)
dog.owner.obj.isDefined must beTrue
}
"be primed after setting a Boxed reference" in {
- cleanup()
val dog = Dog.create
val user = User.create
dog.owner(Full(user))
dog.owner.obj.isDefined must beTrue
}
"be empty after setting an Empty" in {
- cleanup()
-
val user = User.create
val dog = Dog.create.owner(user)
dog.owner(Empty)
View
406 persistence/mapper/src/test/scala/net/liftweb/mapper/MapperSpec.scala
@@ -30,61 +30,31 @@ import http.provider.HTTPRequest
/**
- * Systems under specification for Mapper.
+ * Systems under specification for Mapper. The model classes here are
+ * defined in MapperSpecsModel.scala
*/
object MapperSpec extends Specification("Mapper Specification") {
+ // Do everything in order.
+ setSequential()
- val doLog = false
+ // Make sure we have everything configured first
+ MapperSpecsModel.setup()
- // def providers =
- // if (false || Props.getBool("lift.fasttest", false))
- // (DbProviders.H2MemoryProvider :: Nil)
- // else
- // DbProviders.asList
- def providers = DbProviders.H2MemoryProvider :: DbProviders.DerbyProvider :: Nil
-
- def dbSetup() {
- Schemifier.destroyTables_!!(ignoreLogger _, SampleModel, SampleTag, Dog, User, Mixer, Dog2)
- Schemifier.schemify(true, ignoreLogger _, SampleModel, SampleTag, User, Dog, Mixer, Dog2)
- }
-
- def snakify(connid: ConnectionIdentifier, name: String): String = {
- if (connid.jndiName == "snake")
- StringHelpers.snakify(name)
- else
- name.toLowerCase
- }
+ def providers = DbProviders.H2MemoryProvider :: Nil
/*
- if (!DB.loggingEnabled_? && doLog)
- DB.addLogFunc(logDBStuff)
-*/
-
- MapperRules.columnName = snakify
- MapperRules.tableName = snakify
-
- // Simple name calculator
- def displayNameCalculator(bm: BaseMapper, l: Locale, name: String) = {
- val mapperName = bm.dbName
- val displayName = name match {
- case "firstName" if l == Locale.getDefault() => "DEFAULT:" + mapperName + "." + name
- case "firstName" if l == new Locale("da", "DK") => "da_DK:" + mapperName + "." + name
- case _ => name
- }
- displayName
- }
+ private def logDBStuff(log: DBLog, len: Long) {
+ println(" in log stuff "+log.getClass.getName)
+ log match {
+ case null =>
+ case _ => println(log.allEntries)
+ }
+ }
- MapperRules.displayNameCalculator.default.set(displayNameCalculator _)
+ DB.addLogFunc(logDBStuff)
+ */
- // Snake connection doesn't create FK constraints
- MapperRules.createForeignKeys_? = c => c.jndiName != "snake"
-
- def cleanup() {
- Schemifier.destroyTables_!!(DefaultConnectionIdentifier, if (doLog) Schemifier.infoF _ else ignoreLogger _, SampleTag, SampleModel, Dog, Mixer, Dog2, User, TstItem, Thing)
- Schemifier.destroyTables_!!(DbProviders.SnakeConnectionIdentifier, if (doLog) Schemifier.infoF _ else ignoreLogger _, SampleTagSnake, SampleModelSnake)
- Schemifier.schemify(true, if (doLog) Schemifier.infoF _ else ignoreLogger _, DefaultConnectionIdentifier, SampleModel, SampleTag, User, Dog, Mixer, Dog2, TstItem, Thing)
- Schemifier.schemify(true, if (doLog) Schemifier.infoF _ else ignoreLogger _, DbProviders.SnakeConnectionIdentifier, SampleModelSnake, SampleTagSnake)
- }
+// if (!DB.loggingEnabled_? && doLog) DB.addLogFunc(logDBStuff)
providers.foreach(provider => {
@@ -93,12 +63,11 @@ object MapperSpec extends Specification("Mapper Specification") {
doBefore {
(try {
provider.setupDB
- cleanup
+ MapperSpecsModel.cleanup()
} catch {
case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e))
}) must not(throwAnException[Exception]).orSkipExample
}
- setSequential()
"schemify" in {
val elwood = SampleModel.find(By(SampleModel.firstName, "Elwood")).open_!
@@ -229,12 +198,12 @@ object MapperSpec extends Specification("Mapper Specification") {
"enforce FK constraint on DefaultConnection" in {
val supportsFK = DB.use(DefaultConnectionIdentifier) { conn => conn.driverType.supportsForeignKeys_? }
if (!supportsFK) skip("Driver %s does not support FK constraints".format(provider))
-
+
SampleTag.create.model(42).save must throwA[java.sql.SQLException]
}
"not enforce FK constraint on SnakeConnection" in {
- SampleTagSnake.create.model(42).save
+ SampleTagSnake.create.model(42).save must_== true
}
"Precache works" in {
@@ -323,7 +292,7 @@ object MapperSpec extends Specification("Mapper Specification") {
"Non-autogenerated primary key items should be savable after a field has been changed" in {
val item = TstItem.create.tmdbId(1L).saveMe
- item.name("test").save
+ item.name("test").save must_== true
}
"we can read and write String primary keys" in {
@@ -407,339 +376,6 @@ object MapperSpec extends Specification("Mapper Specification") {
}
}
})
-
- private def ignoreLogger(f: => AnyRef): Unit = ()
-}
-
-
-object SampleTag extends SampleTag with LongKeyedMetaMapper[SampleTag] {
- override def dbAddTable = Full(populate _)
-
- private def populate {
- val samp = SampleModel.findAll()
- val tags = List("Hello", "Moose", "Frog", "WooHoo", "Sloth",
- "Meow", "Moof")
- for (t <- tags;
- m <- samp) SampleTag.create.tag(t).model(m).save
- }
-}
-
-
-class SampleTag extends LongKeyedMapper[SampleTag] with IdPK {
- def getSingleton = SampleTag
-
- // what's the "meta" server
- object tag extends MappedString(this, 32)
-
- object model extends MappedLongForeignKey(this, SampleModel)
-
- object extraColumn extends MappedString(this, 32) {
- override def dbColumnName = "AnExtraColumn"
- }
-}
-
-
-object SampleModel extends SampleModel with KeyedMetaMapper[Long, SampleModel] {
- override def dbAddTable = Full(populate _)
-
- def encodeAsJson(in: SampleModel): JsonAST.JObject = encodeAsJSON_!(in)
-
- def buildFromJson(json: JsonAST.JObject): SampleModel = decodeFromJSON_!(json, false)
-
- private def populate {
- create.firstName("Elwood").save
- create.firstName("Madeline").save
- create.firstName("Archer").save
- create.firstName("NotNull").moose(Full(99L)).save
- }
-}
-
-
-class SampleModel extends KeyedMapper[Long, SampleModel] {
- def getSingleton = SampleModel
-
- // what's the "meta" server
- def primaryKeyField = id
-
- object id extends MappedLongIndex(this)
-
- object firstName extends MappedString(this, 32)
-
- object moose extends MappedNullableLong(this)
-
- object notNull extends MappedString(this, 32) {
- override def dbNotNull_? = true
- }
-
- def encodeAsJson(): JsonAST.JObject = SampleModel.encodeAsJson(this)
-}
-
-
-object SampleTagSnake extends SampleTagSnake with LongKeyedMetaMapper[SampleTagSnake] {
- override def dbAddTable = Full(populate _)
-
- private def populate {
- val samp = SampleModelSnake.findAll()
- val tags = List("Hello", "Moose", "Frog", "WooHoo", "Sloth",
- "Meow", "Moof")
- for (t <- tags;
- m <- samp) SampleTagSnake.create.tag(t).model(m).save
- }
-
- override def dbDefaultConnectionIdentifier = DbProviders.SnakeConnectionIdentifier
-}
-
-
-class SampleTagSnake extends LongKeyedMapper[SampleTagSnake] with IdPK {
- def getSingleton = SampleTagSnake
-
- // what's the "meta" server
-
- object tag extends MappedString(this, 32)
-
- object model extends MappedLongForeignKey(this, SampleModelSnake)
-
- object extraColumn extends MappedString(this, 32) {
- override def dbColumnName = "AnExtraColumn"
- }
-
-}
-
-
-object SampleModelSnake extends SampleModelSnake with KeyedMetaMapper[Long, SampleModelSnake] {
- override def dbAddTable = Full(populate _)
-
- def encodeAsJson(in: SampleModelSnake): JsonAST.JObject = encodeAsJSON_!(in)
-
- def buildFromJson(json: JsonAST.JObject): SampleModelSnake = decodeFromJSON_!(json, false)
-
- private def populate {
- create.firstName("Elwood").save
- create.firstName("Madeline").save
- create.firstName("Archer").save
- create.firstName("NotNull").moose(Full(99L)).save
- }
-
- override def dbDefaultConnectionIdentifier = DbProviders.SnakeConnectionIdentifier
-}
-
-
-class SampleModelSnake extends KeyedMapper[Long, SampleModelSnake] {
- def getSingleton = SampleModelSnake
-
- // what's the "meta" server
- def primaryKeyField = id
-
- object id extends MappedLongIndex(this)
-
- object firstName extends MappedString(this, 32)
-
- object moose extends MappedNullableLong(this)
-
- object notNull extends MappedString(this, 32) {
- override def dbNotNull_? = true
- }
-
- def encodeAsJson(): JsonAST.JObject = SampleModelSnake.encodeAsJson(this)
-}
-
-
-/**
- * The singleton that has methods for accessing the database
- */
-object User extends User with MetaMegaProtoUser[User] {
- override def dbAddTable = Full(populate _)
-
- private def populate {
- create.firstName("Elwood").save
- create.firstName("Madeline").save
- create.firstName("Archer").save
- }
-
- override def dbTableName = "users"
-
- // define the DB table name
- override def screenWrap = Full(<lift:surround with="default" at="content"><lift:bind/></lift:surround>)
-
- // define the order fields will appear in forms and output
- override def fieldOrder = List(id, firstName, lastName, email, locale, timezone, password, textArea)
-
- // comment this line out to require email validations
- override def skipEmailValidation = true
-}
-
-
-/**
- * An O-R mapped "User" class that includes first name, last name, password and we add a "Personal Essay" to it
- */
-class User extends MegaProtoUser[User] {
- def getSingleton = User
-
-
- // what's the "meta" server
-
- // define an additional field for a personal essay
- object textArea extends MappedTextarea(this, 2048) {
- override def textareaRows = 10
-
- override def textareaCols = 50
-
- override def displayName = "Personal Essay"
- }
-
-
-}
-
-
-class Dog extends LongKeyedMapper[Dog] with IdPK {
- def getSingleton = Dog
-
- object name extends MappedPoliteString(this, 128)
-
- object weight extends MappedInt(this)
-
- object owner extends MappedLongForeignKey(this, User)
-}
-
-
-object Dog extends Dog with LongKeyedMetaMapper[Dog] {
- override def dbAddTable = Full(populate _)
-
- private def populate {
- create.name("Elwood").save
- create.name("Madeline").save
- create.name("Archer").save
- create.name("fido").owner(User.find(By(User.firstName, "Elwood"))).save
- }
-
- def who(in: Dog): Box[User] = in.owner
-}
-
-
-class Mixer extends LongKeyedMapper[Mixer] with IdPK {
- def getSingleton = Mixer
-
- object name extends MappedPoliteString(this, 128) {
- override def dbColumnName = "NaM_E"
- override def defaultValue = "wrong"
- }
-
- object weight extends MappedInt(this) {
- override def dbColumnName = "WEIGHT"
- override def defaultValue = -99
- }
-}
-
-
-object Mixer extends Mixer with LongKeyedMetaMapper[Mixer] {
- override def dbAddTable = Full(populate _)
- override def dbTableName = "MIXME_UP"
-
- private def populate {
- create.name("Elwood").weight(33).save
- create.name("Madeline").weight(44).save
- create.name("Archer").weight(105).save
- }
-}
-
-object Thing extends Thing with KeyedMetaMapper[String, Thing] {
- override def dbTableName = "things"
-
- import java.util.UUID
- override def beforeCreate = List((thing: Thing) => {
- thing.thing_id(UUID.randomUUID().toString())
- })
-}
-
-
-class Thing extends KeyedMapper[String, Thing] {
- def getSingleton = Thing
-
- def primaryKeyField = thing_id
-
- object thing_id extends MappedStringIndex(this, 36) {
- override def writePermission_? = true
- override def dbAutogenerated_? = false
- override def dbNotNull_? = true
- }
-
- object name extends MappedString(this, 64)
-}
-
-
-/**
- * Test class to see if you can have a non-autogenerated primary key
- * Issue 552
- */
-class TstItem extends LongKeyedMapper[TstItem] {
- def getSingleton = TstItem
- def primaryKeyField = tmdbId
-
- object tmdbId extends MappedLongIndex(this) {
- override def writePermission_? = true
- override def dbAutogenerated_? = false
- }
-
- object name extends MappedText(this)
-}
-
-
-object TstItem extends TstItem with LongKeyedMetaMapper[TstItem]
-
-
-class Dog2 extends LongKeyedMapper[Dog2] with CreatedUpdated {
- def getSingleton = Dog2
- override def primaryKeyField = dog2id
-
- object dog2id extends MappedLongIndex[Dog2](this.asInstanceOf[MapperType]) {
- override def dbColumnName = "DOG2_Id"
- }
-
- object name extends MappedPoliteString(this, 128)
-
- object weight extends MappedInt(this)
-
- object owner extends MappedLongForeignKey(this, User)
-
- object actualAge extends MappedInt(this) {
- override def dbColumnName = "ACTUAL_AGE"
- override def defaultValue = 1
- override def dbIndexed_? = true
- }
-
-
- object isDog extends MappedBoolean(this) {
- override def dbColumnName = "is_a_dog"
- override def defaultValue = false
- override def dbIndexed_? = true
- }
-
-
- object createdTime extends MappedDateTime(this) {
- override def dbColumnName = "CreatedTime"
- override def defaultValue = new _root_.java.util.Date()
- override def dbIndexed_? = true
- }
-
-
}
-object Dog2 extends Dog2 with LongKeyedMetaMapper[Dog2] {
- override def dbTableName = "DOG2"
- override def dbAddTable = Full(populate _)
-
- private def populate {
- create.name("Elwood").actualAge(66).save
- create.name("Madeline").save
- create.name("Archer").save
- create.name("fido").owner(User.find(By(User.firstName, "Elwood"))).isDog(true).save
- create.name("toto").owner(User.find(By(User.firstName, "Archer"))).actualAge(3).isDog(true)
- .createdTime(Dog2.getRefDate).save
- }
-
- // Get new instance of fixed point-in-time reference date
- def getRefDate: _root_.java.util.Date = {
- new _root_.java.util.Date(1257089309453L)
- }
-}
View
413 persistence/mapper/src/test/scala/net/liftweb/mapper/MapperSpecsModel.scala
@@ -0,0 +1,413 @@
+/*
+ * Copyright 2011 WorldWide Conferencing, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.liftweb
+package mapper
+
+import java.util.Locale
+
+import common._
+import json._
+import util._
+import Helpers._
+
+/*
+ * This file contains a number of objects that are common to several
+ * of the Mapper specs. By placing them here we reduce code duplication
+ * and get rid of some timing errors found when we moved to SBT for build.
+ *
+ * Derek Chen-Becker, Mar 8, 2011
+ */
+
+object MapperSpecsModel {
+ // These rules are common to all Mapper specs
+ def snakify(connid: ConnectionIdentifier, name: String): String = {
+ if (connid.jndiName == "snake") {
+ StringHelpers.snakify(name)
+ } else {
+ name.toLowerCase
+ }
+ }
+
+ MapperRules.columnName = snakify
+ MapperRules.tableName = snakify
+
+ // Simple name calculator
+ def displayNameCalculator(bm: BaseMapper, l: Locale, name: String) = {
+ val mapperName = bm.dbName
+ val displayName = name match {
+ case "firstName" if l == Locale.getDefault() => "DEFAULT:" + mapperName + "." + name
+ case "firstName" if l == new Locale("da", "DK") => "da_DK:" + mapperName + "." + name
+ case _ => name
+ }
+ displayName
+ }
+
+ MapperRules.displayNameCalculator.default.set(displayNameCalculator _)
+
+ def setup() {
+ // For now, do nothing. Just force this object to load
+ }
+
+ def doLog = false
+
+ private def ignoreLogger(f: => AnyRef): Unit = ()
+
+ def cleanup() {
+ // Snake connection doesn't create FK constraints (put this here to be absolutely sure it gets set before Schemify)
+ MapperRules.createForeignKeys_? = c => {
+ c.jndiName != "snake"
+ }
+
+ Schemifier.destroyTables_!!(DefaultConnectionIdentifier, if (doLog) Schemifier.infoF _ else ignoreLogger _, SampleTag, SampleModel, Dog, Mixer, Dog2, User, TstItem, Thing)
+ Schemifier.destroyTables_!!(DbProviders.SnakeConnectionIdentifier, if (doLog) Schemifier.infoF _ else ignoreLogger _, SampleTagSnake, SampleModelSnake)
+ Schemifier.schemify(true, if (doLog) Schemifier.infoF _ else ignoreLogger _, DefaultConnectionIdentifier, SampleModel, SampleTag, User, Dog, Mixer, Dog2, TstItem, Thing)
+ Schemifier.schemify(true, if (doLog) Schemifier.infoF _ else ignoreLogger _, DbProviders.SnakeConnectionIdentifier, SampleModelSnake, SampleTagSnake)
+ }
+}
+
+
+object SampleTag extends SampleTag with LongKeyedMetaMapper[SampleTag] {
+ override def dbAddTable = Full(populate _)
+
+ private def populate {
+ val samp = SampleModel.findAll()
+ val tags = List("Hello", "Moose", "Frog", "WooHoo", "Sloth",
+ "Meow", "Moof")
+ for (t <- tags;
+ m <- samp) SampleTag.create.tag(t).model(m).save
+ }
+}
+
+
+class SampleTag extends LongKeyedMapper[SampleTag] with IdPK {
+ def getSingleton = SampleTag
+
+ // what's the "meta" server
+ object tag extends MappedString(this, 32)
+
+ object model extends MappedLongForeignKey(this, SampleModel)
+
+ object extraColumn extends MappedString(this, 32) {
+ override def dbColumnName = "AnExtraColumn"
+ }
+}
+
+
+object SampleModel extends SampleModel with KeyedMetaMapper[Long, SampleModel] {
+ override def dbAddTable = Full(populate _)
+
+ def encodeAsJson(in: SampleModel): JsonAST.JObject = encodeAsJSON_!(in)
+
+ def buildFromJson(json: JsonAST.JObject): SampleModel = decodeFromJSON_!(json, false)
+
+ private def populate {
+ create.firstName("Elwood").save
+ create.firstName("Madeline").save
+ create.firstName("Archer").save
+ create.firstName("NotNull").moose(Full(99L)).save
+ }
+}
+
+
+class SampleModel extends KeyedMapper[Long, SampleModel] {
+ def getSingleton = SampleModel
+
+ // what's the "meta" server
+ def primaryKeyField = id
+
+ object id extends MappedLongIndex(this)
+
+ object firstName extends MappedString(this, 32)
+
+ object moose extends MappedNullableLong(this)
+
+ object notNull extends MappedString(this, 32) {
+ override def dbNotNull_? = true
+ }
+
+ def encodeAsJson(): JsonAST.JObject = SampleModel.encodeAsJson(this)
+}
+
+
+object SampleTagSnake extends SampleTagSnake with LongKeyedMetaMapper[SampleTagSnake] {
+ override def dbAddTable = Full(populate _)
+
+ private def populate {
+ val samp = SampleModelSnake.findAll()
+ val tags = List("Hello", "Moose", "Frog", "WooHoo", "Sloth",
+ "Meow", "Moof")
+ for (t <- tags;
+ m <- samp) SampleTagSnake.create.tag(t).model(m).save
+ }
+
+ override def dbDefaultConnectionIdentifier = DbProviders.SnakeConnectionIdentifier
+}
+
+
+class SampleTagSnake extends LongKeyedMapper[SampleTagSnake] with IdPK {
+ def getSingleton = SampleTagSnake
+
+ // what's the "meta" server
+
+ object tag extends MappedString(this, 32)
+
+ object model extends MappedLongForeignKey(this, SampleModelSnake)
+
+ object extraColumn extends MappedString(this, 32) {
+ override def dbColumnName = "AnExtraColumn"
+ }
+
+}
+
+
+object SampleModelSnake extends SampleModelSnake with KeyedMetaMapper[Long, SampleModelSnake] {
+ override def dbAddTable = Full(populate _)
+
+ def encodeAsJson(in: SampleModelSnake): JsonAST.JObject = encodeAsJSON_!(in)
+
+ def buildFromJson(json: JsonAST.JObject): SampleModelSnake = decodeFromJSON_!(json, false)
+
+ private def populate {
+ create.firstName("Elwood").save
+ create.firstName("Madeline").save
+ create.firstName("Archer").save
+ create.firstName("NotNull").moose(Full(99L)).save
+ }
+
+ override def dbDefaultConnectionIdentifier = DbProviders.SnakeConnectionIdentifier
+}
+
+
+class SampleModelSnake extends KeyedMapper[Long, SampleModelSnake] {
+ def getSingleton = SampleModelSnake
+
+ // what's the "meta" server
+ def primaryKeyField = id
+
+ object id extends MappedLongIndex(this)
+
+ object firstName extends MappedString(this, 32)
+
+ object moose extends MappedNullableLong(this)
+
+ object notNull extends MappedString(this, 32) {
+ override def dbNotNull_? = true
+ }
+
+ def encodeAsJson(): JsonAST.JObject = SampleModelSnake.encodeAsJson(this)
+}
+
+
+/**
+ * The singleton that has methods for accessing the database
+ */
+object User extends User with MetaMegaProtoUser[User] {
+ override def dbAddTable = Full(populate _)
+
+ private def populate {
+ create.firstName("Elwood").save
+ create.firstName("Madeline").save
+ create.firstName("Archer").save
+ }
+
+ override def dbTableName = "users"
+
+ // define the DB table name
+ override def screenWrap = Full(<lift:surround with="default" at="content"><lift:bind/></lift:surround>)
+
+ // define the order fields will appear in forms and output
+ override def fieldOrder = List(id, firstName, lastName, email, locale, timezone, password, textArea)
+
+ // comment this line out to require email validations
+ override def skipEmailValidation = true
+}
+
+
+/**
+ * An O-R mapped "User" class that includes first name, last name, password and we add a "Personal Essay" to it
+ */
+class User extends MegaProtoUser[User] {
+ def getSingleton = User
+
+
+ // what's the "meta" server
+
+ // define an additional field for a personal essay
+ object textArea extends MappedTextarea(this, 2048) {
+ override def textareaRows = 10
+
+ override def textareaCols = 50
+
+ override def displayName = "Personal Essay"
+ }
+
+
+}
+
+
+class Dog extends LongKeyedMapper[Dog] with IdPK {
+ def getSingleton = Dog
+
+ object name extends MappedPoliteString(this, 128)
+
+ object weight extends MappedInt(this)
+
+ object owner extends MappedLongForeignKey(this, User)
+}
+
+
+object Dog extends Dog with LongKeyedMetaMapper[Dog] {
+ override def dbAddTable = Full(populate _)
+
+ private def populate {
+ create.name("Elwood").save
+ create.name("Madeline").save
+ create.name("Archer").save
+ create.name("fido").owner(User.find(By(User.firstName, "Elwood"))).save
+ }
+
+ def who(in: Dog): Box[User] = in.owner
+}
+
+
+class Mixer extends LongKeyedMapper[Mixer] with IdPK {
+ def getSingleton = Mixer
+
+ object name extends MappedPoliteString(this, 128) {
+ override def dbColumnName = "NaM_E"
+ override def defaultValue = "wrong"
+ }
+
+ object weight extends MappedInt(this) {
+ override def dbColumnName = "WEIGHT"
+ override def defaultValue = -99
+ }
+}
+
+
+object Mixer extends Mixer with LongKeyedMetaMapper[Mixer] {
+ override def dbAddTable = Full(populate _)
+ override def dbTableName = "MIXME_UP"
+
+ private def populate {
+ create.name("Elwood").weight(33).save
+ create.name("Madeline").weight(44).save
+ create.name("Archer").weight(105).save
+ }
+}
+
+object Thing extends Thing with KeyedMetaMapper[String, Thing] {
+ override def dbTableName = "things"
+
+ import java.util.UUID
+ override def beforeCreate = List((thing: Thing) => {
+ thing.thing_id(UUID.randomUUID().toString())
+ })
+}
+
+
+class Thing extends KeyedMapper[String, Thing] {
+ def getSingleton = Thing
+
+ def primaryKeyField = thing_id
+
+ object thing_id extends MappedStringIndex(this, 36) {
+ override def writePermission_? = true
+ override def dbAutogenerated_? = false
+ override def dbNotNull_? = true
+ }
+
+ object name extends MappedString(this, 64)
+}
+
+
+/**
+ * Test class to see if you can have a non-autogenerated primary key
+ * Issue 552
+ */
+class TstItem extends LongKeyedMapper[TstItem] {
+ def getSingleton = TstItem
+ def primaryKeyField = tmdbId
+
+ object tmdbId extends MappedLongIndex(this) {
+ override def writePermission_? = true
+ override def dbAutogenerated_? = false
+ }
+
+ object name extends MappedText(this)
+}
+
+
+object TstItem extends TstItem with LongKeyedMetaMapper[TstItem]
+
+
+class Dog2 extends LongKeyedMapper[Dog2] with CreatedUpdated {
+ def getSingleton = Dog2
+ override def primaryKeyField = dog2id
+
+ object dog2id extends MappedLongIndex[Dog2](this.asInstanceOf[MapperType]) {
+ override def dbColumnName = "DOG2_Id"
+ }
+
+ object name extends MappedPoliteString(this, 128)
+
+ object weight extends MappedInt(this)
+
+ object owner extends MappedLongForeignKey(this, User)
+
+ object actualAge extends MappedInt(this) {
+ override def dbColumnName = "ACTUAL_AGE"
+ override def defaultValue = 1
+ override def dbIndexed_? = true
+ }
+
+
+ object isDog extends MappedBoolean(this) {
+ override def dbColumnName = "is_a_dog"
+ override def defaultValue = false
+ override def dbIndexed_? = true
+ }
+
+
+ object createdTime extends MappedDateTime(this) {
+ override def dbColumnName = "CreatedTime"
+ override def defaultValue = new _root_.java.util.Date()
+ override def dbIndexed_? = true
+ }
+
+
+}
+
+
+object Dog2 extends Dog2 with LongKeyedMetaMapper[Dog2] {
+ override def dbTableName = "DOG2"
+ override def dbAddTable = Full(populate _)
+
+ private def populate {
+ create.name("Elwood").actualAge(66).save
+ create.name("Madeline").save
+ create.name("Archer").save
+ create.name("fido").owner(User.find(By(User.firstName, "Elwood"))).isDog(true).save
+ create.name("toto").owner(User.find(By(User.firstName, "Archer"))).actualAge(3).isDog(true)
+ .createdTime(Dog2.getRefDate).save
+ }
+
+ // Get new instance of fixed point-in-time reference date
+ def getRefDate: _root_.java.util.Date = {
+ new _root_.java.util.Date(1257089309453L)
+ }
+}
View
9 project/build/LiftFrameworkProject.scala
@@ -94,15 +94,8 @@ class LiftFrameworkProject(info: ProjectInfo) extends ParentProject(info) with L
// FIXME: Build fails with -Xcheckinit -Xwarninit
override def compileOptions = super.compileOptions.toList -- compileOptions("-Xcheckinit", "-Xwarninit").toList
- // System properties necessary during test
+ // System properties necessary during test TODO: Figure out how to make this a subdir of persistence/ldap/
System.setProperty("apacheds.working.dir", (outputPath / "apacheds").absolutePath)
-
- // FIXME: breaks with SBT
- override def testOptions =
- ExcludeTests(
- // Persistence tests
- "net.liftweb.mapper.MapperSpec" :: Nil) ::
- super.testOptions.toList
}
}

0 comments on commit b8eb1d0

Please sign in to comment.
Something went wrong with that request. Please try again.