Guest User

Untitled

a guest
Oct 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. val rs = TimeHelpers.logTime("Create result set") {
  2. SQL("""
  3. SELECT * FROM assets_vehicles JOIN
  4. models m ON model_id = m.id JOIN
  5. brands b on brand_id = b.id
  6. WHERE account_id={tid} AND org_unit_id={ou}
  7. """).
  8. on("tid" -> tenantId, "ou" -> rootOrgUnitId).resultSet()
  9. }
  10.  
  11.  
  12. TimeHelpers.logTime("Parse result set") {
  13. val s = new collection.mutable.ListBuffer[(VehicleListItem, VehicleListSpec)]()
  14.  
  15. def str(c: String) = rs.getString(c)
  16. def optStr(c: String) = {
  17. val s = rs.getString(c)
  18. if (rs.wasNull) None else Some(s)
  19. }
  20. def long(c: String) = rs.getLong(c)
  21. def optInt(c: String) = {
  22. val i = rs.getInt(c)
  23. if (rs.wasNull) None else Some(i)
  24. }
  25. def optDate(c: String) = {
  26. val d = rs.getDate(c)
  27. if (rs.wasNull) None else Some(d)
  28. }
  29.  
  30. while(rs.next) {
  31. val vli = VehicleListItem(java.util.UUID.randomUUID, VIN(str("vin")), OrgUnitId(long("org_unit_id")),
  32. optStr("license_plate").getOrElse(""), optStr("driver").getOrElse(""), optStr("leasing_company").getOrElse(""), optDate("contract_start").map(LocalDate.fromDateFields(_)), optInt("contract_duration").getOrElse(0))
  33. val vls = VehicleListSpec(str("vehicle_type"), str("brand"), str("model"), str("variant"), optStr("body_type").getOrElse(""))
  34. s += (vli -> vls)
  35. }
  36. s.toSeq
  37. }
  38. }
  39.  
  40. /*
  41. Result
  42. 18:46:08.065 INFO net.liftweb.util.TimeHelpers account=21, user=27 - Create result set took 654 Milliseconds
  43. 18:46:08.952 INFO net.liftweb.util.TimeHelpers account=21, user=27 - Parse result set took 886 Milliseconds
  44. 18:46:08.954 TRACE f.a.VehicleMenus$$anonfun$listOp$1$$anon$1 account=21, user=27 - Fetched all 20068 records
  45. */
Add Comment
Please, Sign In to add comment