Lifecycle callbacks for Record and MongoDB

77 views
Skip to first unread message

sergio_101

unread,
Jun 7, 2013, 11:35:50 AM6/7/13
to lif...@googlegroups.com
when using Record with MongoDB, are there any lifecycle callbacks we can use for object creation? is there a best practice for this?

for example..

on creation of an order, we would fire off a request to an accounting system for a new order number..

thanks!

Diego Medina

unread,
Jun 7, 2013, 1:32:05 PM6/7/13
to Lift
This came up a few weeks ago, but I can;t find the thread, the final solution was along the lines of having a central object that did the creation  of the object, and then it triggered the  next task you need. So you don't call .save directly form your snippets, etc, you call something like:

MyCentralStorageLayer.save( newInvoice)

and the save method would take the newInvice data (a case class is a good thing to use here), and then it would trigger your accounting task

Thanks

  Diego 


--
--
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
 
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://fmpwizard.telegr.am

60v3...@gmail.com

unread,
Apr 24, 2014, 1:59:14 AM4/24/14
to lif...@googlegroups.com
What do you think about the follow idea:

  class MyCollection extends MongoRecord[MyCollection] with ObjectPk[MyCollection] {

    def afterSave: List[(MyCollection) => Unit] = Nil
    def beforeSave: List[(MyCollection) => Unit] = Nil

    override def save = {

      beforeSave.foreach(f => f(this)

      val instance = super.save

      afterSave.foreach(f => f(this)

      instance

    }
  }

Is this example exactly the same lifecycle workflow like the functions of Mapper? Or would you rather suggest another approach, e.g. a centralized LiftActor and call them? Example:

object CentralizedStorage extends LiftActor {

  def find(query) = this !? query // <- sync
  def save(instance) { this !? instance } // <- sync

  def lowPriority = { ... }

}

CentralizedStorage.save(MyCollection.createRecord...)

Diego Medina

unread,
Apr 25, 2014, 1:41:35 AM4/25/14
to Lift

Both ideas are valid

Sent from my tablet
Diego

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

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages