private String getIdSetSqlCondition() {
    if (!selectedIds.isPresent()) {
      return "";
    }

    Set<Long> ids = selectedIds.get();

    StringBuilder sb = new StringBuilder("id in (");
    if (ids.isEmpty()) {
      sb.append("null");
    } else {
      Iterator<Long> idIterator = selectedIds.get().iterator();
      while (idIterator.hasNext()) {
        Long id = idIterator.next();
        sb.append(id);
        if (idIterator.hasNext()) {
          sb.append(",");
        }
      }
    }
    sb.append(")");
    return sb.toString();
  }