Class AutoCatchingPostgreConnection

java.lang.Object
net.hectus.sql.PostgreConnection
net.hectus.sql.AutoCatchingPostgreConnection

public class AutoCatchingPostgreConnection extends PostgreConnection
Modified version of the PostgreConnection, but with the key difference of throwing no exceptions and instead handling them automatically inside the methods, using a code snipped provided in the constructor or optionally modified using changeExceptionHandling(Consumer). Can break if the code for handling the exceptions isn't proper.
  • Constructor Details

  • Method Details

    • closeConnection

      public void closeConnection()
      Description copied from class: PostgreConnection
      Closes the connection to the database. Recommended to use this before shutting down the program, to not cause any connection issues with the database.
      Overrides:
      closeConnection in class PostgreConnection
    • createNewStatement

      public void createNewStatement()
      Description copied from class: PostgreConnection
      Generates a new statement to use for queries. Can be useful for clearing some memory.
      Overrides:
      createNewStatement in class PostgreConnection
    • changeExceptionHandling

      public void changeExceptionHandling(Consumer<SQLException> exceptionHandling)
      Changes what should be done with the SQLExceptions, when they are caught. No usage case for normal users.
      Parameters:
      exceptionHandling - The new way of handling the SQLExceptions.
    • executeQuery

      public <T> T executeQuery(String sql, Object @NotNull ... params)
      Description copied from class: PostgreConnection
      Executes a parameterized SQL query and returns the result. When the result has multiple values, it will choose the first column index.
      Overrides:
      executeQuery in class PostgreConnection
      Type Parameters:
      T - The type of the result to be returned.
      Parameters:
      sql - The parameterized query to be executed.
      params - The parameters that should be set into the sql query input.
      Returns:
      The result of the query execution, or null if it's empty.
    • getRowArray

      public Object[] getRowArray(UUID uuid)
      Description copied from class: PostgreConnection
      Get a whole row from the table based on a player UUID.
      Overrides:
      getRowArray in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the row from.
      Returns:
      All objects of the row as an array.
    • getRowMap

      public Map<String,Object> getRowMap(UUID uuid)
      Description copied from class: PostgreConnection
      Get a whole row with column names and values from the table based on a player UUID.
      Overrides:
      getRowMap in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the row from.
      Returns:
      All objects of the row as a map.
    • getRow

      public ResultSet getRow(UUID uuid)
      Description copied from class: PostgreConnection
      Get the result of getting a row based on a player UUID.
      Overrides:
      getRow in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the row from.
      Returns:
      The result of the query.
    • get

      public Object get(UUID uuid, String column)
      Description copied from class: PostgreConnection
      Get a value from a specific player's data, based on a player UUID and the column name.
      Overrides:
      get in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the value from.
      column - The column/value's name.
      Returns:
      The value in the specified field.
    • get

      public Object get(UUID uuid, int column)
      Description copied from class: PostgreConnection
      Get a value from a specific player's data, based on a player UUID and the column index.
      Overrides:
      get in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the value from.
      column - The column/value's index (starting at 1).
      Returns:
      The value in the specified field.
    • set

      public void set(UUID uuid, String column, Object newValue)
      Description copied from class: PostgreConnection
      Set a value from a specific player's data to a new value, based on a player UUID and the column name.
      Overrides:
      set in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the value from.
      column - The column/value's name.
      newValue - The new value for the specified field.
    • set

      public void set(UUID uuid, int column, Object newValue)
      Description copied from class: PostgreConnection
      Set a value from a specific player's data to a new value, based on a player UUID and the column index.
      Overrides:
      set in class PostgreConnection
      Parameters:
      uuid - The UUID of the player to get the value from.
      column - The column/value's index (starting at 1).
      newValue - The new value for the specified field.
    • add

      public void add(UUID uuid, Object @NotNull ... values)
      Description copied from class: PostgreConnection
      Inserts a new row with a player and the values into the table.
      Overrides:
      add in class PostgreConnection
      Parameters:
      uuid - The player's UUID, which is the first column.
      values - All other values for the new row. Has to be valid according to database settings, otherwise will throw the following Exception.
    • remove

      public void remove(UUID uuid)
      Description copied from class: PostgreConnection
      Removed a player's row based on his UUID.
      Overrides:
      remove in class PostgreConnection
      Parameters:
      uuid - The player's UUID.
    • contains

      public boolean contains(UUID uuid)
      Description copied from class: PostgreConnection
      Checks whether the table contains an entry/row for the player or not.
      Overrides:
      contains in class PostgreConnection
      Parameters:
      uuid - The player's UUID.
      Returns:
      true if the table contains the player's UUID, false otherwise.
    • getRowArraysContaining

      public List<Object[]> getRowArraysContaining(Object object, String... checkedColumns)
      Description copied from class: PostgreConnection
      Get all rows of the table containing a specific value in any specified column as a List of arrays, where the list represents the rows and the arrays are each row's columns.
      Overrides:
      getRowArraysContaining in class PostgreConnection
      Parameters:
      object - What object must be contained in at least one of the rows.
      checkedColumns - All columns that are checked for the object.
      Returns:
      A list containing all columns as an array.
    • getRowMapsContaining

      public List<Map<String,Object>> getRowMapsContaining(Object object, String... checkedColumns)
      Description copied from class: PostgreConnection
      Get all rows of the table containing a specific value in any specified column as a List of arrays, where the list represents the rows and the maps are each row's columns with their name first and then their value.
      Overrides:
      getRowMapsContaining in class PostgreConnection
      Parameters:
      object - What object must be contained in at least one of the rows.
      checkedColumns - All columns that are checked for the object.
      Returns:
      A map containing all columns with their names and values.