Interface AsyncDBManager
- All Known Implementing Classes:
AsyncMariaDBManager,AsyncSqliteManager
Parent interface of all async database managers
-
Method Summary
Modifier and TypeMethodDescriptioncolumnExists(@NotNull String tableName, @NotNull String columnName) Show if a column exists in a tablecreateOrAlter(@NotNull DBTable dbTable) Create a database table using aDBTableobject, suitable for the DBManager (AsyncMariaDBManager:MariaDBTableAsyncSqliteManager:SqliteTable)deleteFrom(@NotNull String tableName, @Nullable String whereClause) Delete entries
e.g.:
deleteFrom("users", "userId = " + userId);deleteFrom(@NotNull String tableName, @Nullable String whereClause, @NotNull List<Object> whereParams) Delete entries with aListreplacing the question marks in thewhereClause
e.g.:
deleteFrom("users", "userId = ?"Drop a table from the database
e.g.:
dropTable("current-weak-save");default CompletableFuture<int[]> executeBatchSql(@NotNull BatchSqlStatements sqlStatements, @NotNull String tableName) Executes multiple SQL statements in batch mode for better performance
e.gdefault CompletableFuture<int[]> executeBatchSql(@NotNull List<BatchSqlStatement> sqlStatements, @NotNull String tableName) Deprecated.executeSelect(@NotNull String sql, @NotNull String tableName) Execute a selection query
e.g.executeSelect(@NotNull String sql, @NotNull String tableName, @NotNull List<Object> sqlParams) executeSql(@NotNull String sql, @NotNull String tableName, @Nullable String type) Execute a SQL query
e.g.:
executeSql("UPDATE users SET name = " + username + " WHERE id = " + userId, "users", "update username");executeSql(@NotNull String sql, @NotNull String tableName, @Nullable String type, @NotNull List<Object> sqlParams) Execute a SQL query with aListreplacing the question marks in thesql
e.g.:
executeSql("UPDATE users SET name = ?indexExists(@NotNull String tableName, @NotNull String indexName) Show if an index exists in a tableinsertIgnore(@NotNull String tableName, @NotNull Map<String, Object> values) insertInto(@NotNull String tableName, @NotNull Map<String, Object> values) Methods inherited from interface io.github.mrtesz.teszcore.api.db.manager.DBManager
async, async, buildSqlWithParams, checkConnection, close, connect, disconnect, getConnection, getName, isClosed, sync
-
Method Details
-
createOrAlter
CompletableFuture<Void> createOrAlter(@NotNull @NotNull DBTable dbTable) throws IllegalArgumentException Create a database table using aDBTableobject, suitable for the DBManager (AsyncMariaDBManager:MariaDBTableAsyncSqliteManager:SqliteTable)- Parameters:
dbTable- Table that is created or altered- Throws:
IllegalArgumentException- when thedbTableparam 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 aListreplacing the question marks in thesql
e.g.:
executeSql("UPDATE users SET name = ? WHERE id = ?",syncList.of(username, userId), "users", "update username");- Parameters:
sql- Query that should be executedtableName- Name of the table, querying totype- Type of the executionsqlParams- Values replacing the ?'s in thesqlquery- Returns:
- A
CompletableFuturesupplying the return value of thePreparedStatement.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 executedtableName- Name of the table, querying totype- Type of the execution- Returns:
- A
CompletableFuturesupplying the return value of thePreparedStatement.executeUpdate()
-
executeBatchSql
@Deprecated default CompletableFuture<int[]> executeBatchSql(@NotNull @NotNull List<BatchSqlStatement> sqlStatements, @NotNull @NotNull String tableName) throws IllegalArgumentException Deprecated.useexecuteBatchSql(BatchSqlStatements, String)insteadExecutes multiple SQL statements in batch mode for better performance
e.g.:executeBatchSql(batchStatementList, "users", "batch update");- Parameters:
sqlStatements- List of SQL statements with their parameterstableName- Name of the table, querying to- Returns:
- A
CompletableFuturesupplying the return value ofStatement.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 parameterstableName- Name of the table, querying to- Returns:
- A
CompletableFuturesupplying the return value ofStatement.executeBatch()
-
executeSelect
CompletableFuture<SelectionResults> executeSelect(@NotNull @NotNull String sql, @NotNull @NotNull String tableName, @NotNull @NotNull List<Object> sqlParams) Execute a selection query with aListreplacing the question marks in thesql
e.g.
executeSelect("SELECT email, number FROM users WHERE username = ?",List.of("Mr_Tesz"), "users");- Parameters:
sql- Sql querytableName- Name of the table, to select fromsqlParams- Values replacing the ?'s in thesqlquery- Returns:
- A
CompletableFuturesupplying aSelectionResultsobject
-
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 querytableName- Name of the table, to select from- Returns:
- A
CompletableFuturesupplying aSelectionResultsobject
-
insertInto
CompletableFuture<Integer> insertInto(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String, Object> values) Insert into a table
e.g.:
Map<String, Object>values = newHashMapinvalid input: '<'>();
values.put("id", userId);
values.put("name", username)
dbManager.insertInto("users", values);- Parameters:
tableName- Name of the table, inserting intovalues- Values to insert- Returns:
- A
CompletableFuturesupplying the return value of thePreparedStatement.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 = newHashMapinvalid input: '<'>();
values.put("id", userId);
values.put("name", username);
dbManager.insertInto("users", values);- Parameters:
tableName- Name of the table, inserting intovalues- Values to insert- Returns:
- A
CompletableFuturesupplying the return value of thePreparedStatement.executeUpdate()
-
deleteFrom
CompletableFuture<Integer> deleteFrom(@NotNull @NotNull String tableName, @Nullable @Nullable String whereClause, @NotNull @NotNull List<Object> whereParams) Delete entries with aListreplacing the question marks in thewhereClause
e.g.:
deleteFrom("users", "userId = ?",List.of(userId));- Parameters:
tableName- Name of the table, deleting fromwhereClause- Clause, narrowing the targeted columnswhereParams- Values replacing the ?'s in thewhereClause- Returns:
- A
CompletableFuturesupplying 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 fromwhereClause- Clause, narrowing the targeted columns- Returns:
- A
CompletableFuturesupplying 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 aListreplacing the question marks in thewhereClause
e.g.:
Map<String, Object>values = newHashMapinvalid input: '<'>();
values.put("name", username);
update("users", values, "id = ?",List.of(userId);- Parameters:
tableName- Name of the table, updatingvalues- Values to updatewhereClause- Clause, narrowing the targeted columnswhereParams- Values replacing the ?'s in thewhereClause- Returns:
- A
CompletableFuturesupplying 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 = newHashMapinvalid input: '<'>();
values.put("name", username);
update("users", values, "id = " + userId);- Parameters:
tableName- Name of the table, updatingvalues- Values to updatewhereClause- Clause, narrowing the targeted columns- Returns:
- A
CompletableFuturesupplying the rows affected
-
dropTable
Drop a table from the database
e.g.:
dropTable("current-weak-save");- Parameters:
tableName- Name of the table to drop- Returns:
- A
CompletableFuturesupplying the return value of thePreparedStatement.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, checkingcolumnName- Name of the column to be checked- Returns:
- A
CompletableFuturesupplying 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, checkingindexName- Name of the index to be checked- Returns:
- A
CompletableFuturesupplying true if the index exists
-
executeBatchSql(BatchSqlStatements, String)instead