Google Groups

Re: [Lift] LifecycleCallBacks and squerlyrecord


Olek Swirski Apr 26, 2012 9:52 AM
Posted in group: Lift
hi David,
I was using lifecycle callbacks with 0.9.5-SNAPSHOT
and noticed kind of inconsistent behavior. here is
a subsection of my Schema with comment, that
summarizes my observations. Please take a look
at comments in a subset of MySchema definition

I'm not sure if it's the same with 0.9.5 final, so I
point out this inconsistency, just in case it's still there


object MySchema extends Schema {
   
   
    /* Topic table definitions */
    val topics = table[Topic]("topic")
   

    /* lifecycle callbacks */
    override def callbacks = Seq(
        beforeInsert(topics) call (Topic.beforeInsert),
        beforeUpdate(topics) call (Topic.beforeUpdate),
        afterInsert(topics) call (Topic.afterInsert),
        afterUpdate(topics) call (Topic.afterUpdate)
       
        /* and it goes like this:
         * first beforeInsert, beforeUpdate or beforeUpdate, beforeInsert is called (in same order as in this Seq)
         * then afterInsert, then afterUpdate
         * but: beforeUpdate is called only with initial insert and not anymore later
         * but: beforeDelete & afterDelete does not work at all
         */
    )

}

On 26/04/12 16:51, David Whittaker wrote:
Hi Jono,

No hassle.  I put a pull request with the upgrade to 0.9.5 on github yesterday: https://github.com/lift/framework/pull/1257.  I'll give it to the end of the day for comments and then merge it if there aren't any negative ones.  So we should have a 2.5-SNAPSHOT with the ability to register Lifecycle callbacks the Squeryl way sometime tomorrow.  If you haven't seen that, you override the callbacks method in your Schema like so: https://github.com/max-l/Squeryl/blob/master/src/test/scala/org/squeryl/test/schooldb/SchoolDb.scala#L211.  Will that do the trick for you, for now?  Integration with the Record  LifecycleCallbacks trait is in the plan as well, but may take a little longer.

On Thu, Apr 26, 2012 at 6:47 AM, Jonathan Ferguson <jo...@spiralarm.com> wrote:
Hi Dave, 

Do you have a rough timescale for this? I don't want to hassle just trying to slot it into my plan. 


Cheers 
Jono


On 18 April 2012 08:00, Jonathan Ferguson <jo...@spiralarm.com> wrote:
Hi Dave, 

I can wait a few days and I don't see a problem using SNAPSHOTS. 

Cheers

Jono


On 18 April 2012 00:48, David Whittaker <da...@iradix.com> wrote:
Hi Jono,

Unfortunately Squeryl 0.9.4 doesn't include callbacks.  Squeryl 0.9.5-final, which was published yesterday, does include them and I should have a new record module using it for Lift 2.5-SNAPSHOT soon.  I hadn't planned on doing the LifecycleCallback integration immediately, but considering you're the second person to bring it up in the past two days maybe I should.  Is this something you can wait a few days for and are you able to use the latest Lift SNAPSHOTs?

-Dave


On Tue, Apr 17, 2012 at 1:14 AM, Jonathan Ferguson <jo...@spiralarm.com> wrote:
Hello Lifters, 

 I'm having trouble with LifecycleCallBacks and squerlyrecord. None of the overridden functions appear to be called apart from defaultValue.   Does anyone have any pointers, would it be helpful if I posted a runnable example? 

The code in question: 

trait Updated[T <: Updated[T]] extends Record[T] with Loggable {

  self: T ⇒

  val updated = new DateTimeField(this) with LifecycleCallbacks {

    override def defaultValue = { 

      logger.info("updated default value")

      Calendar.getInstance()

    }    

    override def beforeCreate = {

      logger.info("set updated")

      this.set(Calendar.getInstance())

    }

    override def beforeUpdate {

      logger.info("set updated")

      this.set(Calendar.getInstance())

    }

    override def beforeSave = {logger.info("before save updated")}

  }

}





Cheers 

Jono
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code


--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code