docs: @Override
    public Xid[] recover(int flag) throws XAException {
      // Check preconditions
      if (flag != TMSTARTRSCAN && flag != TMENDRSCAN && flag != TMNOFLAGS
          && flag != (TMSTARTRSCAN | TMENDRSCAN)) {
        throw new PGXAException(GT.tr("Invalid flags {0}", flag), XAException.XAER_INVAL);
      }
  
      // We don't check for precondition 2, because we would have to add some additional state in
      // this object to keep track of recovery scans.
  
      // All clear. We return all the xids in the first TMSTARTRSCAN call, and always return
      // an empty array otherwise.
      if ((flag & TMSTARTRSCAN) == 0) {
        return new Xid[0];
      } else {
        try {
          Statement stmt = conn.createStatement();
          try {
            // If this connection is simultaneously used for a transaction,
            // this query gets executed inside that transaction. It's OK,
            // except if the transaction is in abort-only state and the
            // backed refuses to process new queries. Hopefully not a problem
            // in practise.
            ResultSet rs = stmt.executeQuery(
                "SELECT gid FROM pg_prepared_xacts where database = current_database()");
            LinkedList<Xid> l = new LinkedList<Xid>();
            while (rs.next()) {
              Xid recoveredXid = RecoveredXid.stringToXid(rs.getString(1));
              if (recoveredXid != null) {
                l.add(recoveredXid);
              }
            }
            rs.close();
  
            return l.toArray(new Xid[0]);
          } finally {
            stmt.close();
          }
        } catch (SQLException ex) {
          throw new PGXAException(GT.tr("Error during recover"), ex, XAException.XAER_RMERR);
        }
      }
    }