Class DummySQLConnection<T>

Type Parameters:
T - The primary key's type.

public class DummySQLConnection<T> extends AutoCatchingSQLConnection<T>
A dummy SQL connection for testing purposes or to have something like a null value, but without throwing NullPointerExceptions.
This extends the AutoCatchingSQLConnection, meaning it does not throw anything.
Getters will always return null and setters will do nothing.
  • Constructor Details

  • Method Details

    • createNewStatement

      public void createNewStatement()
      Description copied from class: SQLConnection
      Generates a new statement to use for queries. Can be useful for clearing some memory.
      Overrides:
      createNewStatement in class AutoCatchingSQLConnection<T>
    • executeQuery

      public <T2> T2 executeQuery(String sql, Object @NotNull ... params)
      Description copied from class: SQLConnection
      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 AutoCatchingSQLConnection<T>
      Type Parameters:
      T2 - 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(T primaryKey)
      Description copied from class: SQLConnection
      Get a whole row from the table based on the primary key.
      Overrides:
      getRowArray in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key to get the row from.
      Returns:
      All objects of the row as an array.
    • getRowMap

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

      public ResultSet getRow(T primaryKey)
      Description copied from class: SQLConnection
      Get the result of getting a row based on the primary key.
      Overrides:
      getRow in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key to get the row from.
      Returns:
      The result of the query.
    • get

      public Object get(T primaryKey, String column)
      Description copied from class: SQLConnection
      Get a specified column, based on the primary key and the column name.
      Overrides:
      get in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key to get the value from.
      column - The column/value's name.
      Returns:
      The value in the specified field.
    • get

      public Object get(T primaryKey, int column)
      Description copied from class: SQLConnection
      Get a specified column, based on the primary key and the column index.
      Overrides:
      get in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key 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(T primaryKey, String column, Object newValue)
      Description copied from class: SQLConnection
      Set a value of a specified row to a new value, based on the primary key and the column name.
      Overrides:
      set in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key to get the value from.
      column - The column/value's name.
      newValue - The new value for the specified field.
    • set

      public void set(T primaryKey, int column, Object newValue)
      Description copied from class: SQLConnection
      Set a value of a specified row to a new value, based on the primary key and the column index.
      Overrides:
      set in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key 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(@NotNull @NotNull Map<String,Object> values)
      Description copied from class: SQLConnection
      Inserts a new row with the specified values into the table.
      Overrides:
      add in class AutoCatchingSQLConnection<T>
      Parameters:
      values - All values for the new row. The keys are the column names and the values are the values. Has to be valid according to database settings, otherwise throws an Exception.
    • remove

      public void remove(T primaryKey)
      Description copied from class: SQLConnection
      Removed a row based on the primary key.
      Overrides:
      remove in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key to remove.
    • contains

      public boolean contains(T primaryKey)
      Description copied from class: SQLConnection
      Checks whether the table contains an entry/row with the primary key or not.
      Overrides:
      contains in class AutoCatchingSQLConnection<T>
      Parameters:
      primaryKey - The primary key to check for.
      Returns:
      true if the table contains the primary key, false otherwise.
    • getAllRowArrays

      public List<Object[]> getAllRowArrays()
      Description copied from class: SQLConnection
      Get all rows of the table, where the list represents the rows and the arrays are each row's columns.
      Overrides:
      getAllRowArrays in class AutoCatchingSQLConnection<T>
      Returns:
      A list containing all columns as an array.
    • getAllRowMaps

      public List<Map<String,Object>> getAllRowMaps()
      Description copied from class: SQLConnection
      Get all rows of the table, where the list represents the rows and the maps are each row's columns with their name first and then their value.
      Overrides:
      getAllRowMaps in class AutoCatchingSQLConnection<T>
      Returns:
      A map containing all columns with their names and values.
    • getRowArraysContaining

      public List<Object[]> getRowArraysContaining(Object object, String... checkedColumns)
      Description copied from class: SQLConnection
      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 AutoCatchingSQLConnection<T>
      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: SQLConnection
      Get all rows of the table containing a specific value in any specified column as a List of maps, 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 AutoCatchingSQLConnection<T>
      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.
    • getRowArraysMatching

      public Collection<Object[]> getRowArraysMatching(String wherePredicate, Object @NotNull ... replacements)
      Description copied from class: SQLConnection
      Get all rows matching a specified WHERE predicate as a Collection of arrays, where the list represents the rows and the arrays are each row's columns with their name first and then their value.
      Overrides:
      getRowArraysMatching in class AutoCatchingSQLConnection<T>
      Parameters:
      wherePredicate - The SQL WHERE predicate, like column = ? AND another_column = ?. This is inserted right after the WHERE.
      replacements - What objects the question marks should be replaced with.
      Returns:
      All rows that match the WHERE predicate as arrays.
    • getRowMapsMatching

      public Collection<Map<String,Object>> getRowMapsMatching(String wherePredicate, Object @NotNull ... replacements)
      Description copied from class: SQLConnection
      Get all rows matching a specified WHERE predicate as a Collection of arrays, where the collection represents the rows and the arrays are each row's columns with their name first and then their value.
      Overrides:
      getRowMapsMatching in class AutoCatchingSQLConnection<T>
      Parameters:
      wherePredicate - The SQL WHERE predicate, like column = ? AND another_column = ?. This is inserted right after the WHERE.
      replacements - What objects the question marks should be replaced with.
      Returns:
      All rows that match the WHERE predicate as arrays.