code: public List<Message> getFilteredList( EMessageType messageType, Long fromTsMillis, Long toTsMillis, long limit )
              throws Exception {
          String tableName = TABLE_MESSAGES;
          String sql = "select " + getQueryFieldsString() + " from " + tableName;
  
          List<String> wheresList = new ArrayList<>();
          if (messageType != null && messageType != EMessageType.ALL) {
              String where = type_NAME + "=" + messageType.getCode();
              wheresList.add(where);
          }
          if (fromTsMillis != null) {
              String where = TimeStamp_NAME + ">" + fromTsMillis;
              wheresList.add(where);
          }
          if (toTsMillis != null) {
              String where = TimeStamp_NAME + "<" + toTsMillis;
              wheresList.add(where);
          }
  
          if (wheresList.size() > 0) {
              sql += " WHERE ";
              for( int i = 0; i < wheresList.size(); i++ ) {
                  if (i > 0) {
                      sql += " AND ";
                  }
                  sql += wheresList.get(i);
              }
          }
  
          sql += " order by " + ID_NAME + " desc";
          if (limit > 0) {
              sql += " limit " + limit;
          }
  
          String _sql = sql;
          List<Message> messages = new ArrayList<Message>();
          logDb.execOnConnection(connection -> {
              try (IHMStatement stmt = connection.createStatement(); IHMResultSet rs = stmt.executeQuery(_sql);) {
                  while( rs.next() ) {
                      Message event = resultSetToItem(rs);
                      messages.add(event);
                  }
              }
              return null;
          });
          return messages;
      }
docs: Get the list of messages, filtered.
  
  @param messageType the type to filter.
  @param fromTsMillis the start time in millis.
  @param toTsMillis the end time in millis.
  @param limit the max number of messages.
  @return the list of messages.
  @throws Exception