Class QRCodeDatabase


  • public class QRCodeDatabase
    extends java.lang.Object
    Manages all QRCode-related database operations, and ensures that the collection of QRCodes that a each player has scanned is consistent with the collection of players that have scanned a specific QR code.
    • Method Detail

      • getInstance

        public static QRCodeDatabase getInstance()
        Retrieves the QRCodeDatabase
        Returns:
        QRCodeDatabase
      • mockInstance

        public static void mockInstance​(QRCodeDatabase mockInstance)
        Manually set QRCodeDatabase to some mocked instance for testing
        Parameters:
        mockInstance - The mocked QRCodeDatabase
      • getQRCodeByHash

        public void getQRCodeByHash​(java.lang.String hash,
                                    DatabaseConsumer<QRCode> callback)
        Retrieve a QRCode by its hash from the database
        Parameters:
        hash - QRCode hash to lookup
        callback - The callback function to handle result
      • getQRCodeHashes

        public void getQRCodeHashes​(java.util.List<java.lang.String> hashes,
                                    DatabaseConsumer<java.util.List<QRCode>> callback)
        Retrieve a set of QRCodes by their hashes
        Parameters:
        hashes - the hashes
        callback - callback to call on query completion
      • getAllQRCodes

        public void getAllQRCodes​(DatabaseConsumer<java.util.List<QRCode>> callback)
        Retrieve all QRCodes stored in the database.
        Parameters:
        callback - callback to call with the qr codes.
      • updateQRCode

        public void updateQRCode​(QRCode qrCode,
                                 DatabaseConsumer<java.lang.Void> callback)
        Update a QRCode that already exists in the database.
        Parameters:
        qrCode - The QRCode to update
        callback - callback to call once the operation has finished
      • playerHasQRCode

        public void playerHasQRCode​(Player player,
                                    QRCode qrCode,
                                    DatabaseConsumer<java.lang.Boolean> callback)
        Checks if a player has already added a specific QRCode to their profile.
        Parameters:
        player - The player to check.
        qrCode - The QRCode to check.
        callback - The callback function to handle the result.
      • addQRCode

        public void addQRCode​(QRCode qrCode,
                              DatabaseConsumer<java.lang.Void> task)
        Adds a never-before-scanned QRCode to the database
        Parameters:
        qrCode - The never-before-scanned QRCode to add
        task - callback on database operation completion
      • addPlayerToQR

        public void addPlayerToQR​(Player player,
                                  QRCode qrCode,
                                  DatabaseConsumer<java.lang.Void> task)
        Adds the QRCode to the player's account, as well as the Player to the QRCode's collection of players that have added it.
        Parameters:
        player - The player to add QRCode to.
        qrCode - The QRCode to be added.
        task - callback on database operation completion
      • removeQRCodeFromPlayer

        public void removeQRCodeFromPlayer​(Player player,
                                           QRCode qrCode,
                                           DatabaseConsumer<java.lang.Void> task)
        Removes the QRCode to the player's account, as well as the Player from the QRCode's collection of players that have added it.
        Parameters:
        player - The player to remove QRCode from.
        qrCode - The QRCode to be removed
        task - callback on database operation completion
      • addListener

        public void addListener​(DatabaseChangeListener listener)
        Add snapshot listener to database
        Parameters:
        listener - listener to call on updates to the qr code database