docs: @Override
    public int prepare(Xid xid) throws XAException {
      if (LOGGER.isLoggable(Level.FINEST)) {
        debug("preparing transaction xid = " + xid);
      }
  
      // Check preconditions
      if (currentXid == null && preparedXid != null) {
        if (LOGGER.isLoggable(Level.FINEST)) {
          debug("Prepare xid " + xid + " but current connection is not attached to a transaction"
              + " while it was prepared in past with prepared xid " + preparedXid);
        }
        throw new PGXAException(GT.tr(
            "Preparing already prepared transaction, the prepared xid {0}, prepare xid={1}", preparedXid, xid), XAException.XAER_PROTO);
      } else if (currentXid == null) {
        throw new PGXAException(GT.tr(
            "Current connection does not have an associated xid. prepare xid={0}", xid), XAException.XAER_NOTA);
      }
      if (!currentXid.equals(xid)) {
        if (LOGGER.isLoggable(Level.FINEST)) {
          debug("Error to prepare xid " + xid + ", the current connection already bound with xid " + currentXid);
        }
        throw new PGXAException(GT.tr(
            "Not implemented: Prepare must be issued using the same connection that started the transaction. currentXid={0}, prepare xid={1}", currentXid, xid),
            XAException.XAER_RMERR);
      }
      if (state != State.ENDED) {
        throw new PGXAException(GT.tr("Prepare called before end. prepare xid={0}, state={1}", xid), XAException.XAER_INVAL);
      }
  
      state = State.IDLE;
      preparedXid = currentXid;
      currentXid = null;
  
      try {
        String s = RecoveredXid.xidToString(xid);
  
        Statement stmt = conn.createStatement();
        try {
          stmt.executeUpdate("PREPARE TRANSACTION '" + s + "'");
        } finally {
          stmt.close();
        }
        conn.setAutoCommit(localAutoCommitMode);
  
        return XA_OK;
      } catch (SQLException ex) {
        throw new PGXAException(GT.tr("Error preparing transaction. prepare xid={0}", xid), ex, mapSQLStateToXAErrorCode(ex));
      }
    }