Esempio n. 1
0
  public Result readAll() {
    try {

      String sql =
          String.format(
              "select id, shop_id, user_id, create_time from shake_record"
                  + " join shop on shop.id = shop_id"
                  + " where shop.app_id = %s",
              session("appId"));

      RawSql rawSql =
          RawSqlBuilder.parse(sql)
              .columnMapping("id", "id")
              .columnMapping("shop_id", "shop_id")
              .columnMapping("user_id", "user_id")
              .columnMapping("create_time", "create_time")
              .create();

      Query<ShakeRecord> query = Ebean.find(ShakeRecord.class);
      query.setRawSql(rawSql);

      List<ShakeRecord> shakeList = query.findList();

      return ok(Json.toJson(shakeList));
    } catch (Throwable e) {
      return status(ErrDefinition.E_SHAKE_RECORD_READ_ERROR, Messages.get("shakerecord.failure"));
    }
  }
Esempio n. 2
0
  // find airport whose name is closest to the argument string
  protected static List<Airport> getAirportsLevenshtein(String string) {
    String sql =
        "select id, name, city, country, code, icao as ICAO, latitude, longitude, altitude, timezone, dst as DST "
            + "from airport "
            + "order by levenshtein(upper(replace(name, ' Intl', '')), '"
            + string
            + "') asc limit 1";
    // TODO: if string contains intl or interntnl or international...
    // replace it with intl and dont remove it from name?
    // or easier to remove it and add name like '%Intl%'?

    RawSql rawSql = RawSqlBuilder.parse(sql).create();
    Query<Airport> query = Ebean.find(Airport.class);
    query.setRawSql(rawSql);
    return query.findList();
  }