LifecycleCallBacks and squerlyrecord

41 views
Skip to first unread message

Jonathan Ferguson

unread,
Apr 17, 2012, 1:14:21 AM4/17/12
to lif...@googlegroups.com
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

David Whittaker

unread,
Apr 17, 2012, 10:48:02 AM4/17/12
to lif...@googlegroups.com
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

--
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

Jonathan Ferguson

unread,
Apr 17, 2012, 6:00:13 PM4/17/12
to lif...@googlegroups.com
Hi Dave, 

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

Cheers

Jono

Jonathan Ferguson

unread,
Apr 26, 2012, 6:47:41 AM4/26/12
to lif...@googlegroups.com
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

David Whittaker

unread,
Apr 26, 2012, 10:51:38 AM4/26/12
to lif...@googlegroups.com
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.

Olek Swirski

unread,
Apr 26, 2012, 12:52:33 PM4/26/12
to lif...@googlegroups.com
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
         */
    )

David Whittaker

unread,
Apr 26, 2012, 1:16:05 PM4/26/12
to lif...@googlegroups.com
Hi Olek,

Would you mind posting this on the Squeryl group?  Max is more familiar with that code than I am and he might have some questions for you that will help him diagnose the problem.

Thanks,
Dave

Diego Medina

unread,
Apr 26, 2012, 2:48:52 PM4/26/12
to lif...@googlegroups.com
Just a side note, I didn;t get an email after you submitted that pull
request, did any other committer get that email?
I do get emails if someone does a plain pull request that is not tied
to a ticket that was already there.
If the email notifications are not going out, that may also explain
why my other pull request [1] hasn't got any comments yet

About your pull request, I don;t really have any comments.

[1] https://github.com/lift/framework/pull/1251

Regards,

Diego
>>>>> self: T =>
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Olek Swirski

unread,
Apr 26, 2012, 2:59:10 PM4/26/12
to lif...@googlegroups.com
Ok, I do that

David Whittaker

unread,
Apr 26, 2012, 3:06:11 PM4/26/12
to lif...@googlegroups.com
Hi Diego,

I think that I did get an e-mail notification on your request.  Something brought it to my attention at least because I had seen it.  It seemed like a lot to process so I flagged it as something to comment on when I had some time, if someone didn't get to it before me.  It looked good, but I remember you had some questions and I haven't had time to think them over.

-Dave

Jonathan Ferguson

unread,
Apr 27, 2012, 6:26:42 AM4/27/12
to lif...@googlegroups.com
Hi Dave, 

Sorry for the delay, I'll attempt to get to this over the weekend. 

Thanks for the quick reply 

Cheers 
Jono

Olek Swirski

unread,
Apr 27, 2012, 11:26:43 AM4/27/12
to lif...@googlegroups.com
@DavidW

Hi, I kind of prepared comprehensive info about this problem I
had with lifecycle callbacks. Now squeryl 0.9.5 just got
published, so I will first confirm if this is still the same with
the latest version before posting @ squeryl mailing list.
maybe it's fixed. and maybe it's just me doing something
wrong. Do I have to use it with 2.5-SNAPSHOT or
2.4 final is fine too? I was using 2.4 so far.

Olek Swirski

unread,
Apr 28, 2012, 11:42:19 AM4/28/12
to lif...@googlegroups.com
@DavidW

As requested :) I made a post @ squeryl mailing list about this problem
I had, with delete & update callbacks not being fired

http://groups.google.com/group/squeryl/browse_thread/thread/300713376404e17e?hl=en

I also published small LIFT application that demonstrates the issue here:
https://github.com/oolekk/sqrlrcrd.com
g...@github.com:oolekk/sqrlrcrd.com.git


On 26/04/12 19:16, David Whittaker wrote:
Reply all
Reply to author
Forward
0 new messages