Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val rs = TimeHelpers.logTime("Create result set") {
- SQL("""
- SELECT * FROM assets_vehicles JOIN
- models m ON model_id = m.id JOIN
- brands b on brand_id = b.id
- WHERE account_id={tid} AND org_unit_id={ou}
- """).
- on("tid" -> tenantId, "ou" -> rootOrgUnitId).resultSet()
- }
- TimeHelpers.logTime("Parse result set") {
- val s = new collection.mutable.ListBuffer[(VehicleListItem, VehicleListSpec)]()
- def str(c: String) = rs.getString(c)
- def optStr(c: String) = {
- val s = rs.getString(c)
- if (rs.wasNull) None else Some(s)
- }
- def long(c: String) = rs.getLong(c)
- def optInt(c: String) = {
- val i = rs.getInt(c)
- if (rs.wasNull) None else Some(i)
- }
- def optDate(c: String) = {
- val d = rs.getDate(c)
- if (rs.wasNull) None else Some(d)
- }
- while(rs.next) {
- val vli = VehicleListItem(java.util.UUID.randomUUID, VIN(str("vin")), OrgUnitId(long("org_unit_id")),
- optStr("license_plate").getOrElse(""), optStr("driver").getOrElse(""), optStr("leasing_company").getOrElse(""), optDate("contract_start").map(LocalDate.fromDateFields(_)), optInt("contract_duration").getOrElse(0))
- val vls = VehicleListSpec(str("vehicle_type"), str("brand"), str("model"), str("variant"), optStr("body_type").getOrElse(""))
- s += (vli -> vls)
- }
- s.toSeq
- }
- }
- /*
- Result
- 18:46:08.065 INFO net.liftweb.util.TimeHelpers account=21, user=27 - Create result set took 654 Milliseconds
- 18:46:08.952 INFO net.liftweb.util.TimeHelpers account=21, user=27 - Parse result set took 886 Milliseconds
- 18:46:08.954 TRACE f.a.VehicleMenus$$anonfun$listOp$1$$anon$1 account=21, user=27 - Fetched all 20068 records
- */
Add Comment
Please, Sign In to add comment