Hi Dave,

Thanks for your answer and sorry for the late reply.
> In the first "filter" line... do you just want to filter out the 
> LimitOrders that do not have the same tradeType foreign key reference 
> as the FK of the parameter that you pass in?
Yes, that's part of the filtering, but I need to do more stuff.
>
> Can you post the model opens (the LimitOrder and the other stuff) as 
> well as the logic?
I gonna do some more thinking about the logic, and paste the source later.
>
> For example,
>  
> LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,remainingOrders(i).id)).map(_.status.set("OPEN"))
>  
> openOr 0L
>
> I'm not sure why you're doing a map and an openOr 0L... you're not 
> returning an expression.
This was the only way I knew to do that......but probably the wrong 
one.....8-)
>
> Also, I'm not sure why you are loading an instance out of the RDBMS in 
> order to to set the status to "OPEN" and then just discard the 
> instance.  Does the set method on the status open have some side 
> effect that you've coded?
It was the first approach to implement the logic and since I'm still not 
very close with Lift, some ugly code came out.
>
> If you want to load a bunch of records, update fields on those 
> records, and save the records, I'd like to suggest the following code:
That's really helpful, I try to use that to get a better implementation!
>
> class Dog extends LongKeyedMapper[Dog] with IdPK {
>   def getSingleton = Dog
>
>   object name extends MappedPoliteString(this, 128)
>   object weight extends MappedInt(this)
> }
>
> object Dog extends Dog with LongKeyedMetaMapper[Dog]
>
> class MyStuff extends LongKeyedMapper[MyStuff] with IdPK {
>   def getSingleton = MyStuff
>
>   object info extends MappedString(this, 128)
>   object count extends MappedInt(this)
>   object dog extends MappedLongForeignKey(this, Dog)
> }
>
>
> object MyStuff extends MyStuff with LongKeyedMetaMapper[MyStuff] {
>   def mutate(in: MyStuff) {
>     for {
>       // find all the items where info = 'NEW' and dog != the value of 
> in's dog field
>       item <- MyStuff.findAll(By(MyStuff.info, "NEW"), 
> NotBy(MyStuff.dog, in.dog))
>       // increment the count field, update the info field and save
>     } item.count(item.count + 1).info("Not so NEW").save
>   }
> }
>
>
thanks!
>
>
> On Wed, Jul 22, 2009 at 4:05 PM, Hannes <[email protected] 
> <mailto:[email protected]>> wrote:
>
>
>     I kind of found the problem. So far, it has nothing to do with save or
>     anything like that. The problem is that this line:
>
>     val newOrders = LimitOrderMetaObj.findAll(By(LimitOrderMetaObj.status,
>     "NEW")).toList.filter(o2 => o2.tradeType.name
>     <http://o2.tradeType.name> != o1.tradeType.name
>     <http://o1.tradeType.name>)
>
>     does not compare the "name" of the tradetype (TradeType has an own
>     "name" field) in the filter method, instead "name" returns "tradetype"
>     (is this the object name?). The thing is, because its a foreign key
>     reference and as you told me, it needs to be accessed via
>
>     o.tradeType.obj.map(_.name.is <http://name.is>) openOr ""
>
>     But now, when I want to compare two of those TradeType.name field
>     (which
>     are normal strings) I don't really know how to do it. I tried
>     something
>     like that, but it doesn't work:
>
>     val newOrders = LimitOrderMetaObj.findAll(By(LimitOrderMetaObj.status,
>     "NEW")).toList.filter(o2 => {o2.tradeType.obj.map(_.name.is
>     <http://name.is>) openOr ""}
>     != {o1.tradeType.obj.map(_.name.is <http://name.is>) openOr "")
>
>
>     thanks.
>
>     > Howdy,
>     >
>     > You can save some memory by using findMap:
>     >
>     > def joinOrders(o1: LimitOrder): Unit = {
>     >    /* select all orders where status=NEW and where that.tradeType !=
>     > order1.tradeType */
>     >    val newOrders =
>     > LimitOrderMetaObj.findMap(By(LimitOrderMetaObj.status, "NEW")){o2 =>
>     > Full(o2).filter(o2.tradeType.name <http://o2.tradeType.name>
>     <http://o2.tradetype.name/> !=
>     > o1.tradeType.name <http://o1.tradeType.name>
>     <http://o1.tradetype.name/>)}
>     >
>     > findMap applies the filtering operation as each row is pulled
>     from the
>     > RDBMS... so you'll have fewer objects in memory.
>     >
>     > In terms of the remaining logic... I'm a little lost in your code...
>     > can you describe the logic?  What gets updated under which
>     conditions?
>     >
>     >
>     > On Wed, Jul 22, 2009 at 5:35 AM, Hannes <[email protected]
>     <mailto:[email protected]>
>     > <mailto:[email protected] <mailto:[email protected]>>> wrote:
>     >
>     >
>     >     Hi Lifters,
>     >
>     >     It seems like I'm having problems to modify items that are
>     already in
>     >     the database. What I do is, first find the item, then set a new
>     >     value to
>     >     it and then save it. So far so good, or?
>     >
>     >     Because its a expensive filter process to find those items to
>     >     modify, I
>     >     made a local copy of the sub-list that contains the most
>     interesting
>     >     items. This sub-list is processed further on and when I
>     finally know
>     >     which items to modify, I look those ones up in the database
>     again and
>     >     set the values. I hope it makes sence...
>     >
>     >     thanks
>     >
>     >     Here's the code:
>     >
>     >     def joinOrders(o1: LimitOrder): Unit = {
>     >        /* select all orders where status=NEW and where
>     that.tradeType !=
>     >     order1.tradeType */
>     >        val newOrders =
>     >     LimitOrderMetaObj.findAll(By(LimitOrderMetaObj.status,
>     >     "NEW")).toList.filter(o2 => o2.tradeType.name
>     <http://o2.tradeType.name>
>     >     <http://o2.tradeType.name> != o1.tradeType.name
>     <http://o1.tradeType.name>
>     >     <http://o1.tradeType.name>)
>     >
>     >        def decideByTradeType: List[LimitOrder] = {
>     >            /* keep all orders where that.marketPoint <=
>     order1.marketPoint
>     >             * sort the list from lowest to highest marketPoint */
>     >            if (o1.tradeType.name <http://o1.tradeType.name>
>     <http://o1.tradeType.name> == "BUY")
>     >                newOrders.filter(o2 => o2.marketPoint.is
>     <http://o2.marketPoint.is>
>     >     <http://o2.marketPoint.is> <=
>     >     o1.marketPoint.is <http://o1.marketPoint.is>
>     <http://o1.marketPoint.is>).sort((s, t) =>
>     >     s.marketPoint.is <http://s.marketPoint.is>
>     <http://s.marketPoint.is> < t.marketPoint.is <http://t.marketPoint.is>
>     >     <http://t.marketPoint.is>)
>     >            /* keep all orders where that.marketPoint >=
>     order1.marketPoint
>     >             * sort the list from highest to lowest marketPoint */
>     >            else //because there are only two different types!
>     Its the same
>     >     as: if (o1.tradeType.name <http://o1.tradeType.name>
>     <http://o1.tradeType.name> == "SELL")
>     >                newOrders.filter(o2 => o2.marketPoint.is
>     <http://o2.marketPoint.is>
>     >     <http://o2.marketPoint.is> >=
>     >     o1.marketPoint.is <http://o1.marketPoint.is>
>     <http://o1.marketPoint.is>).sort((s, t) =>
>     >     s.marketPoint.is <http://s.marketPoint.is>
>     <http://s.marketPoint.is> > t.marketPoint.is <http://t.marketPoint.is>
>     >     <http://t.marketPoint.is>)
>     >        }
>     >
>     >        var i = 0
>     >        var done = false
>     >        val remainingOrders = decideByTradeType
>     >        while (i < remainingOrders.length && !done) {
>     >            if (remainingOrders(i).lots == o1.lots) {
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     remainingOrders(i).id)).map(_.status.set("OPEN")) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     remainingOrders(i).id)).map(_.save) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     o1.id <http://o1.id>
>     <http://o1.id>)).map(_.status.set("OPEN")) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     o1.id <http://o1.id> <http://o1.id>)).map(_.save) openOr 0L
>     >                done = true
>     >            }
>     >            if (remainingOrders(i).lots.is <http://lots.is>
>     <http://lots.is> <
>     >     o1.lots.is <http://o1.lots.is> <http://o1.lots.is>) {
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     remainingOrders(i).id)).map(_.status.set("OPEN")) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     remainingOrders(i).id)).map(_.save) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     o1.id <http://o1.id>
>     <http://o1.id>)).map(_.lots.set(o1.lots.is <http://o1.lots.is>
>     >     <http://o1.lots.is> - remainingOrders(i).lots.is
>     <http://lots.is>
>     >     <http://lots.is>)) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     o1.id <http://o1.id> <http://o1.id>)).map(_.save) openOr 0L
>     >            }
>     >            if (remainingOrders(i).lots.is <http://lots.is>
>     <http://lots.is> >
>     >     o1.lots.is <http://o1.lots.is> <http://o1.lots.is>) {
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     o1.id <http://o1.id>
>     <http://o1.id>)).map(_.status.set("OPEN")) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     o1.id <http://o1.id> <http://o1.id>)).map(_.save) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >    
>     remainingOrders(i).id)).map(_.lots.set(remainingOrders(i).lots.is
>     <http://lots.is>
>     >     <http://lots.is> -
>     >     o1.lots.is <http://o1.lots.is> <http://o1.lots.is>)) openOr 0L
>     >                LimitOrderMetaObj.find(By(LimitOrderMetaObj.id,
>     >     remainingOrders(i).id)).map(_.save) openOr 0L
>     >                done = true
>     >            }
>     >            i = i + 1
>     >        }
>     >      }
>     >
>     >
>     >
>     >
>     >
>     > --
>     > 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
>     >
>     > >
>
>
>
>
>
>
> -- 
> 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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to