I got a compiler error when I tried to compile: val newOrders = LimitOrderMetaObj.findMap(By(LimitOrderMetaObj.status, "NEW")){o2 => Full(o2).filter(o2.tradeType.name != o1.tradeType.name)}
--------------------------------- error: type mismatch; found : Boolean required: (org.tobster.model.LimitOrder) => Boolean val newOrders = LimitOrderMetaObj.findMap(By(LimitOrderMetaObj.status, "NEW")){o2 => Full(o2).filter(o2.tradeType.name != o1.tradeType.name)} > 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/> != > 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 <hannes.flo...@gmx.li > <mailto:hannes.flo...@gmx.li>> 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> != 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> == "BUY") > newOrders.filter(o2 => o2.marketPoint.is > <http://o2.marketPoint.is> <= > o1.marketPoint.is <http://o1.marketPoint.is>).sort((s, t) => > s.marketPoint.is <http://s.marketPoint.is> < 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> == "SELL") > newOrders.filter(o2 => o2.marketPoint.is > <http://o2.marketPoint.is> >= > o1.marketPoint.is <http://o1.marketPoint.is>).sort((s, t) => > s.marketPoint.is <http://s.marketPoint.is> > 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>)).map(_.status.set("OPEN")) openOr 0L > LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, > o1.id <http://o1.id>)).map(_.save) openOr 0L > done = true > } > if (remainingOrders(i).lots.is <http://lots.is> < > 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>)).map(_.lots.set(o1.lots.is > <http://o1.lots.is> - remainingOrders(i).lots.is > <http://lots.is>)) openOr 0L > LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, > o1.id <http://o1.id>)).map(_.save) openOr 0L > } > if (remainingOrders(i).lots.is <http://lots.is> > > o1.lots.is <http://o1.lots.is>) { > LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, > o1.id <http://o1.id>)).map(_.status.set("OPEN")) openOr 0L > LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, > 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> - > 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 > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---