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 != 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 == "BUY") newOrders.filter(o2 => o2.marketPoint.is <= o1.marketPoint.is).sort((s, t) => s.marketPoint.is < 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 == "SELL") newOrders.filter(o2 => o2.marketPoint.is >= o1.marketPoint.is).sort((s, t) => s.marketPoint.is > 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)).map(_.status.set("OPEN")) openOr 0L LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, o1.id)).map(_.save) openOr 0L done = true } if (remainingOrders(i).lots.is < 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)).map(_.lots.set(o1.lots.is - remainingOrders(i).lots.is)) openOr 0L LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, o1.id)).map(_.save) openOr 0L } if (remainingOrders(i).lots.is > o1.lots.is) { LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, o1.id)).map(_.status.set("OPEN")) openOr 0L LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, o1.id)).map(_.save) openOr 0L LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, remainingOrders(i).id)).map(_.lots.set(remainingOrders(i).lots.is - o1.lots.is)) openOr 0L LimitOrderMetaObj.find(By(LimitOrderMetaObj.id, remainingOrders(i).id)).map(_.save) openOr 0L done = true } i = i + 1 } } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---