Interface AsyncDBManager

All Superinterfaces:
Copyable<DBManager>, DBManager
All Known Implementing Classes:
AsyncMariaDBManager, AsyncSqliteManager

public interface AsyncDBManager extends DBManager
Parent interface of all async database managers
  • Method Details

    • createOrAlter

      CompletableFuture<Void> createOrAlter(@NotNull @NotNull DBTable dbTable) throws IllegalArgumentException
      Create a database table using a DBTable object, suitable for the DBManager (AsyncMariaDBManager: MariaDBTable AsyncSqliteManager: SqliteTable)
      Parameters:
      dbTable - Table that is created or altered
      Throws:
      IllegalArgumentException - when the dbTable param is not the suitable type for the DBManager
    • executeSql

      CompletableFuture<Integer> executeSql(@NotNull @NotNull String sql, @NotNull @NotNull String tableName, @Nullable @Nullable String type, @NotNull @NotNull List<Object> sqlParams)
      Execute a SQL query with a List replacing the question marks in the sql
      e.g.:
      executeSql("UPDATE users SET name = ? WHERE id = ?", List.of(username, userId), "users", "update username"); sync
      Parameters:
      sql - Query that should be executed
      tableName - Name of the table, querying to
      type - Type of the execution
      sqlParams - Values replacing the ?'s in the sql query
      Returns:
      A CompletableFuture supplying the return value of the PreparedStatement.executeUpdate()
    • executeSql

      CompletableFuture<Integer> executeSql(@NotNull @NotNull String sql, @NotNull @NotNull String tableName, @Nullable @Nullable String type)
      Execute a SQL query
      e.g.:
      executeSql("UPDATE users SET name = " + username + " WHERE id = " + userId, "users", "update username");
      Parameters:
      sql - Query that should be executed
      tableName - Name of the table, querying to
      type - Type of the execution
      Returns:
      A CompletableFuture supplying the return value of the PreparedStatement.executeUpdate()
    • executeBatchSql

      @Deprecated default CompletableFuture<int[]> executeBatchSql(@NotNull @NotNull List<BatchSqlStatement> sqlStatements, @NotNull @NotNull String tableName) throws IllegalArgumentException
      Executes multiple SQL statements in batch mode for better performance
      e.g.:
      executeBatchSql(batchStatementList, "users", "batch update");
      Parameters:
      sqlStatements - List of SQL statements with their parameters
      tableName - Name of the table, querying to
      Returns:
      A CompletableFuture supplying the return value of Statement.executeBatch()
      Throws:
      IllegalArgumentException - if the SQL statements are not the same structure
    • executeBatchSql

      default CompletableFuture<int[]> executeBatchSql(@NotNull @NotNull BatchSqlStatements sqlStatements, @NotNull @NotNull String tableName)
      Executes multiple SQL statements in batch mode for better performance
      e.g.:
      executeBatchSql(batchStatementList, "users", "batch update");
      Parameters:
      sqlStatements - List of SQL statements with their parameters
      tableName - Name of the table, querying to
      Returns:
      A CompletableFuture supplying the return value of Statement.executeBatch()
    • executeSelect

      CompletableFuture<SelectionResults> executeSelect(@NotNull @NotNull String sql, @NotNull @NotNull String tableName, @NotNull @NotNull List<Object> sqlParams)
      Execute a selection query with a List replacing the question marks in the sql
      e.g.
      executeSelect("SELECT email, number FROM users WHERE username = ?", List.of("Mr_Tesz"), "users");
      Parameters:
      sql - Sql query
      tableName - Name of the table, to select from
      sqlParams - Values replacing the ?'s in the sql query
      Returns:
      A CompletableFuture supplying a SelectionResults object
    • executeSelect

      CompletableFuture<SelectionResults> executeSelect(@NotNull @NotNull String sql, @NotNull @NotNull String tableName)
      Execute a selection query
      e.g.
      executeSelect("SELECT email, number FROM users WHERE username = Mr_Tesz", "users");
      Parameters:
      sql - Sql query
      tableName - Name of the table, to select from
      Returns:
      A CompletableFuture supplying a SelectionResults object
    • insertInto

      CompletableFuture<Integer> insertInto(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values)
      Insert into a table
      e.g.:
      Map<String, Object> values = new HashMapinvalid input: '<'>();
      values.put("id", userId);
      values.put("name", username)
      dbManager.insertInto("users", values);
      Parameters:
      tableName - Name of the table, inserting into
      values - Values to insert
      Returns:
      A CompletableFuture supplying the return value of the PreparedStatement.executeUpdate()
    • insertIgnore

      CompletableFuture<Integer> insertIgnore(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values)
      Insert into a table ignoring when a unique is duplicated
      e.g.:
      Map<String, Object> values = new HashMapinvalid input: '<'>();
      values.put("id", userId);
      values.put("name", username);
      dbManager.insertInto("users", values);
      Parameters:
      tableName - Name of the table, inserting into
      values - Values to insert
      Returns:
      A CompletableFuture supplying the return value of the PreparedStatement.executeUpdate()
    • deleteFrom

      CompletableFuture<Integer> deleteFrom(@NotNull @NotNull String tableName, @Nullable @Nullable String whereClause, @NotNull @NotNull List<Object> whereParams)
      Delete entries with a List replacing the question marks in the whereClause
      e.g.:
      deleteFrom("users", "userId = ?", List.of(userId));
      Parameters:
      tableName - Name of the table, deleting from
      whereClause - Clause, narrowing the targeted columns
      whereParams - Values replacing the ?'s in the whereClause
      Returns:
      A CompletableFuture supplying the rows affected
    • deleteFrom

      CompletableFuture<Integer> deleteFrom(@NotNull @NotNull String tableName, @Nullable @Nullable String whereClause)
      Delete entries
      e.g.:
      deleteFrom("users", "userId = " + userId);
      Parameters:
      tableName - Name of the table, deleting from
      whereClause - Clause, narrowing the targeted columns
      Returns:
      A CompletableFuture supplying the rows affected
    • update

      CompletableFuture<Integer> update(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values, @Nullable @Nullable String whereClause, @NotNull @NotNull List<Object> whereParams)
      Update a table with a List replacing the question marks in the whereClause
      e.g.:
      Map<String, Object> values = new HashMapinvalid input: '<'>();
      values.put("name", username);
      update("users", values, "id = ?", List.of(userId);
      Parameters:
      tableName - Name of the table, updating
      values - Values to update
      whereClause - Clause, narrowing the targeted columns
      whereParams - Values replacing the ?'s in the whereClause
      Returns:
      A CompletableFuture supplying the rows affected
    • update

      CompletableFuture<Integer> update(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values, @Nullable @Nullable String whereClause)
      Update a table
      e.g.:
      Map<String, Object> values = new HashMapinvalid input: '<'>();
      values.put("name", username);
      update("users", values, "id = " + userId);
      Parameters:
      tableName - Name of the table, updating
      values - Values to update
      whereClause - Clause, narrowing the targeted columns
      Returns:
      A CompletableFuture supplying the rows affected
    • dropTable

      CompletableFuture<Integer> dropTable(@NotNull @NotNull String tableName)
      Drop a table from the database
      e.g.:
      dropTable("current-weak-save");
      Parameters:
      tableName - Name of the table to drop
      Returns:
      A CompletableFuture supplying the return value of the PreparedStatement.executeUpdate()
    • columnExists

      CompletableFuture<Boolean> columnExists(@NotNull @NotNull String tableName, @NotNull @NotNull String columnName)
      Show if a column exists in a table
      Parameters:
      tableName - Name of the table, checking
      columnName - Name of the column to be checked
      Returns:
      A CompletableFuture supplying true if the column exists
    • indexExists

      CompletableFuture<Boolean> indexExists(@NotNull @NotNull String tableName, @NotNull @NotNull String indexName)
      Show if an index exists in a table
      Parameters:
      tableName - Name of the table, checking
      indexName - Name of the index to be checked
      Returns:
      A CompletableFuture supplying true if the index exists