[Lift] Re: Stamped Trait question
Thank you very much. It works great now :) On 30 Jul., 04:43, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 5:54 PM, fbettag fr...@bett.ag wrote: Now the last and final question: how would i go about and add this to the trait: object test extends MappedBoolean(this) ? You can't add this to a MetaMapper trait, it must be part of a trait that's mixed into the Mapper. Look for the implementation of IdPK and you'll have the right pattern. i tried: private val thisTyped = this.asInstanceOf[A] object published extends MappedBoolean(thisTyped) and just this and self. Any ideas? On 30 Jul., 02:46, fbettag fr...@bett.ag wrote: And the final version: trait Stamped[A : LongKeyedMapper[A] with IdPK] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = override def afterSave = (createLog(_: A, create)) :: super.afterSave override def afterUpdate = (createLog(_: A, update)) :: super.afterUpdate override def afterDelete = (createLog(_: A, delete)) :: super.afterDelete private def createLog(obj: A, action: String) = { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record( obj.id).save } } On 30 Jul., 02:19, fbettag fr...@bett.ag wrote: Okay i got this so far, only one tiny thing i can't get to work now: trait Stamped[A : LongKeyedMapper[A]] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record( obj.id).save } } The problem relies in the last method called. log.action... at obj.id. Where do i have to define that A (obj) is with IdPK? After that this should be working. Ah one scala syntax question. why can't i call createLog(_, create) at the List? On 30 Jul., 01:22, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Keyed... when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with
[Lift] Re: Stamped Trait question
On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? def afterUpdate { createActionLog(update, this.getClass.toString, this.id) } def beforeDelete { createActionLog(delete, this.getClass.toString, this.id) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } Now i ensured that the OwnerType class has a LongKeyedMapper with IdPK. The final problem is: afterSave is supposed to return a List(Any) meaning List(OwnerType).. how can i find out what the OwnerType class is? And what is it supposed to return? Simply the unmodified record in my case? best regards On 27 Jul., 05:07, fbettag fr...@bett.ag wrote: Hey guys, i#ve gotten this together, to get a log of who's editing what. The trait will give you the idea: import java.util.Date import model._ import net.liftweb.mapper._ trait Stamped[OwnerType : Stamped[OwnerType]] extends LongKeyedMapper [OwnerType] with IdPK { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] def afterSave { createActionLog(create, this.getClass.toString, this.id) } def afterUpdate { createActionLog(update, this.getClass.toString, this.id) } def beforeDelete { createActionLog(delete, this.getClass.toString, this.id) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } On every action i create a log. It's better than having only createdAt/ On which only idicates only the last change, but to have a history. My only problem is, the extends LongKeyedMapper is the only way to make it compile with this.id as last parameter of createActionLog(). The question is, how can i find out if the supplied OwnerType Model is extended with LongKeyedMapper? Is it possible to supply some kinda subclass check on the supplied OwnerType. Btw, i forgot what : does (like in Stamped[OwnerType : Stamped [OwnerType]]). any help would be great! -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
how would i use that trait? with MyLogger[MyModel, MyModel] ? What is A and what is K supposed to be? On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/KeyedMapper.html when i click on KeyType or OwnerType it gives me a 404.. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/KeyedMapper.html when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
On Thursday, July 30, 2009, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/KeyedMapper.html when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
K is the type of the primary key: object MyModel extends MyModel with KeyedMetaMapper[Long, MyModel] with MyLogger[MyModel, Long] On Wed, Jul 29, 2009 at 4:18 PM, fbettag fr...@bett.ag wrote: how would i use that trait? with MyLogger[MyModel, MyModel] ? What is A and what is K supposed to be? On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about the fact that the functions are not meant to return anything. Does this help? -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Stamped Trait question
Okay i got this so far, only one tiny thing i can't get to work now: trait Stamped[A : LongKeyedMapper[A]] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save } } The problem relies in the last method called. log.action... at obj.id. Where do i have to define that A (obj) is with IdPK? After that this should be working. Ah one scala syntax question. why can't i call createLog(_, create) at the List? On 30 Jul., 01:22, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Keyed... when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } There's no afterSave method on Mapper... that method is on MetaMapper. You need to split your trait into two pieces... one that will be mixed into the model instances and one that'll be mixed into the Meta model singleton (or perhaps just one mixed into the Meta). In terms of the afterSave (and other before and after stuff) method on MetaMapper, that method returns a List of functions that take the instance as a model that's being saved and does something. I've changed the signature to List[A = Unit] rather than List[A = Any] to avoid confusion about
[Lift] Re: Stamped Trait question
trait Stamped[A : LongKeyedMapper[A] with IdPK] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save println(Got: +obj) } } this works! On 30 Jul., 02:19, fbettag fr...@bett.ag wrote: Okay i got this so far, only one tiny thing i can't get to work now: trait Stamped[A : LongKeyedMapper[A]] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save } } The problem relies in the last method called. log.action... at obj.id. Where do i have to define that A (obj) is with IdPK? After that this should be working. Ah one scala syntax question. why can't i call createLog(_, create) at the List? On 30 Jul., 01:22, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Keyed... when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper
[Lift] Re: Stamped Trait question
And the final version: trait Stamped[A : LongKeyedMapper[A] with IdPK] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = override def afterSave = (createLog(_: A, create)) :: super.afterSave override def afterUpdate = (createLog(_: A, update)) :: super.afterUpdate override def afterDelete = (createLog(_: A, delete)) :: super.afterDelete private def createLog(obj: A, action: String) = { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save } } On 30 Jul., 02:19, fbettag fr...@bett.ag wrote: Okay i got this so far, only one tiny thing i can't get to work now: trait Stamped[A : LongKeyedMapper[A]] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save } } The problem relies in the last method called. log.action... at obj.id. Where do i have to define that A (obj) is with IdPK? After that this should be working. Ah one scala syntax question. why can't i call createLog(_, create) at the List? On 30 Jul., 01:22, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Keyed... when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best regards On 29 Jul., 21:55, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Jul 28, 2009 at 5:12 PM, fbettag fr...@bett.ag wrote: So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave {
[Lift] Re: Stamped Trait question
Now the last and final question: how would i go about and add this to the trait: object test extends MappedBoolean(this) ? i tried: private val thisTyped = this.asInstanceOf[A] object published extends MappedBoolean(thisTyped) and just this and self. Any ideas? On 30 Jul., 02:46, fbettag fr...@bett.ag wrote: And the final version: trait Stamped[A : LongKeyedMapper[A] with IdPK] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = override def afterSave = (createLog(_: A, create)) :: super.afterSave override def afterUpdate = (createLog(_: A, update)) :: super.afterUpdate override def afterDelete = (createLog(_: A, delete)) :: super.afterDelete private def createLog(obj: A, action: String) = { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save } } On 30 Jul., 02:19, fbettag fr...@bett.ag wrote: Okay i got this so far, only one tiny thing i can't get to work now: trait Stamped[A : LongKeyedMapper[A]] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record(obj.id).save } } The problem relies in the last method called. log.action... at obj.id. Where do i have to define that A (obj) is with IdPK? After that this should be working. Ah one scala syntax question. why can't i call createLog(_, create) at the List? On 30 Jul., 01:22, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Keyed... when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait Foo[A : Mapper[A]] { self: MetaMapper[A] = } On Wed, Jul 29, 2009 at 1:38 PM, fbettag fr...@bett.ag wrote: Yes thanks, it gives me an idea of the issue which i now see. Could you provide a very simple example on how you would make the Meta- Mixin? That would be very good best
[Lift] Re: Stamped Trait question
On Wed, Jul 29, 2009 at 5:54 PM, fbettag fr...@bett.ag wrote: Now the last and final question: how would i go about and add this to the trait: object test extends MappedBoolean(this) ? You can't add this to a MetaMapper trait, it must be part of a trait that's mixed into the Mapper. Look for the implementation of IdPK and you'll have the right pattern. i tried: private val thisTyped = this.asInstanceOf[A] object published extends MappedBoolean(thisTyped) and just this and self. Any ideas? On 30 Jul., 02:46, fbettag fr...@bett.ag wrote: And the final version: trait Stamped[A : LongKeyedMapper[A] with IdPK] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = override def afterSave = (createLog(_: A, create)) :: super.afterSave override def afterUpdate = (createLog(_: A, update)) :: super.afterUpdate override def afterDelete = (createLog(_: A, delete)) :: super.afterDelete private def createLog(obj: A, action: String) = { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record( obj.id).save } } On 30 Jul., 02:19, fbettag fr...@bett.ag wrote: Okay i got this so far, only one tiny thing i can't get to work now: trait Stamped[A : LongKeyedMapper[A]] extends KeyedMetaMapper[Long, A] { self: A with MetaMapper[A] with KeyedMapper[Long, A] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave = createSaveLog _ :: super.afterSave override def afterUpdate = createUpdateLog _ :: super.afterSave override def afterDelete = createDeleteLog _ :: super.afterSave private def createSaveLog(obj: A) = createLog(obj, create) private def createUpdateLog(obj: A) = createLog(obj, update) private def createDeleteLog(obj: A) = createLog(obj, delete) private def createLog(obj: A, action: String) { val log = new ActionLog log.action(action).klass(obj.getClass.toString).record( obj.id).save } } The problem relies in the last method called. log.action... at obj.id. Where do i have to define that A (obj) is with IdPK? After that this should be working. Ah one scala syntax question. why can't i call createLog(_, create) at the List? On 30 Jul., 01:22, David Pollak feeder.of.the.be...@gmail.com wrote: On Wed, Jul 29, 2009 at 4:21 PM, fbettag fr...@bett.ag wrote: Btw. the docs for KeyedMapper don't work.. http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/Keyed... when i click on KeyType or OwnerType it gives me a 404.. This is a limitation of vscaladoc... sorry. On 30 Jul., 00:55, David Pollak feeder.of.the.be...@gmail.com wrote: It's not pretty, but: trait MyLogger[A : KeyedMapper[K, A], K] extends KeyedMetaMapper[K,A] { self: A with MetaMapper[A] with KeyedMapper[K, A] = override def afterSave = doSomething _ :: super.afterSave private def doSomething(in: A) { println(Got +in) } } On Wed, Jul 29, 2009 at 3:35 PM, fbettag fr...@bett.ag wrote: Hm. i changed it to this: trait Stamped[OwnerType : Mapper[OwnerType] with IdPK] { self: MetaMapper[OwnerType] = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave: List[Any] = { createActionLog(create, this.getClass.toString, thisTyped.id) return List(None) } def afterUpdate: List[Any] = { createActionLog(update, this.getClass.toString, thisTyped.id) return List(None) } def beforeDelete: List[Any] = { createActionLog(delete, this.getClass.toString, thisTyped.id) return List(None) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } and i extend the object now and not the class. still i get these: src/main/scala/ag/bett/lift/cms/lib/Stamped.scala:12: error: method afterSave overrides nothing override def afterSave: List[Any] = { ^ method afterSave in trait Stamped of type = List[Any] needs `override' modifier object Content extends Content with LongKeyedMetaMapper[Content] with Stamped[Content] { ^ This is voodoo again :( On 29 Jul., 22:55, David Pollak feeder.of.the.be...@gmail.com wrote: trait
[Lift] Re: Stamped Trait question
So far it looks like this: trait Stamped[OwnerType : Stamped[OwnerType] with LongKeyedMapper [OwnerType] with IdPK] { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] override def afterSave { createActionLog(create, this.getClass.toString, this.id) } def afterUpdate { createActionLog(update, this.getClass.toString, this.id) } def beforeDelete { createActionLog(delete, this.getClass.toString, this.id) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } Now i ensured that the OwnerType class has a LongKeyedMapper with IdPK. The final problem is: afterSave is supposed to return a List(Any) meaning List(OwnerType).. how can i find out what the OwnerType class is? And what is it supposed to return? Simply the unmodified record in my case? best regards On 27 Jul., 05:07, fbettag fr...@bett.ag wrote: Hey guys, i#ve gotten this together, to get a log of who's editing what. The trait will give you the idea: import java.util.Date import model._ import net.liftweb.mapper._ trait Stamped[OwnerType : Stamped[OwnerType]] extends LongKeyedMapper [OwnerType] with IdPK { this: OwnerType = private val thisTyped = this.asInstanceOf[MapperType] def afterSave { createActionLog(create, this.getClass.toString, this.id) } def afterUpdate { createActionLog(update, this.getClass.toString, this.id) } def beforeDelete { createActionLog(delete, this.getClass.toString, this.id) } private def createActionLog(action: String, klass: String, obj: Long) { val log = new ActionLog log.action(action).klass(klass).record(obj).save } } On every action i create a log. It's better than having only createdAt/ On which only idicates only the last change, but to have a history. My only problem is, the extends LongKeyedMapper is the only way to make it compile with this.id as last parameter of createActionLog(). The question is, how can i find out if the supplied OwnerType Model is extended with LongKeyedMapper? Is it possible to supply some kinda subclass check on the supplied OwnerType. Btw, i forgot what : does (like in Stamped[OwnerType : Stamped [OwnerType]]). any help would be great! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---