Interface SyncDBManager
- All Known Implementing Classes:
MariaDBManager,SqliteManager
Parent interface of all sync database managers
-
Method Summary
Modifier and TypeMethodDescriptionbooleancolumnExists(@NotNull String tableName, @NotNull String columnName) Show if a column exists in a tablevoidcreateOrAlter(@NotNull DBTable dbTable) Create a database table using aDBTableobject, suitable for the DBManager (MariaDBManager:MariaDBTableSqliteManager:SqliteTable)intdeleteFrom(@NotNull String tableName, @Nullable String whereClause) Delete entries e.g.:
deleteFrom("users", "userId = " + userId);intdeleteFrom(@NotNull String tableName, @Nullable String whereClause, @NotNull List<Object> whereParams) Delete entries with aListreplacing the question marks in thewhereClausee.g.:
deleteFrom("users", "userId = ?"intDrop a table from the database e.g.:
dropTable("current-weak-save");default int[]executeBatchSql(@NotNull BatchSqlStatements sqlStatements, @NotNull String tableName) Executes multiple SQL statements with the same structure in batch mode for better performance
e.gdefault 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 List<Object> sqlParams, @NotNull String tableName) intexecuteSql(@NotNull String sql, String tableName, String type) Execute a SQL query
e.g.:
executeSql("UPDATE users SET name = " + username + " WHERE id = " + userId, "users", "update username");intexecuteSql(@NotNull String sql, @NotNull List<Object> sqlParams, @NotNull String tableName, @Nullable String type) Execute a SQL query with aListreplacing the question marks in thesql
e.g.:
executeSql("UPDATE users SET name = ?booleanindexExists(@NotNull String tableName, @NotNull String indexName) Show if an index exists in a tableintinsertIgnore(@NotNull String tableName, @NotNull Map<String, Object> values) intinsertInto(@NotNull String tableName, @NotNull Map<String, Object> values) intintMethods 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
Create a database table using aDBTableobject, suitable for the DBManager (MariaDBManager:MariaDBTableSqliteManager:SqliteTable)- Parameters:
dbTable- Table that is created or altered- Throws:
IllegalArgumentException- when thedbTableparam is not the suitable type for the DBManager
-
executeSql
int executeSql(@NotNull @NotNull String sql, @NotNull @NotNull List<Object> sqlParams, @NotNull @NotNull String tableName, @Nullable @Nullable String type) Execute a SQL query with aListreplacing the question marks in thesql
e.g.:
executeSql("UPDATE users SET name = ? WHERE id = ?",List.of(username, userId), "users", "update username");- Parameters:
sql- Query that should be executedsqlParams- Values replacing the ?'s in thesqlquerytableName- Name of the table, querying totype- Type of execution- Returns:
- Return value of the
PreparedStatement.executeUpdate()
-
executeSql
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 execution- Returns:
- Return value of
PreparedStatement.executeUpdate()
-
executeBatchSql
@Deprecated default int[] executeBatchSql(@NotNull @NotNull List<BatchSqlStatement> sqlStatements, @NotNull @NotNull String tableName) throws IllegalArgumentException Deprecated.useexecuteBatchSql(BatchSqlStatements, String)insteadExecutes multiple SQL statements with the same structure 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:
- Return value of
Statement.executeBatch() - Throws:
IllegalArgumentException- if the SQL statements are not the same structure
-
executeBatchSql
default int[] executeBatchSql(@NotNull @NotNull BatchSqlStatements sqlStatements, @NotNull @NotNull String tableName) Executes multiple SQL statements with the same structure 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:
- Return value of
Statement.executeBatch()
-
executeSelect
SelectionResults executeSelect(@NotNull @NotNull String sql, @NotNull @NotNull List<Object> sqlParams, @NotNull @NotNull String tableName) 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 querysqlParams- Values replacing the ?'s in thesqlquerytableName- Name of the table, to select from- Returns:
SelectionResultsobject representing the result
-
executeSelect
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:
SelectionResultsobject representing the result
-
insertInto
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:
- Return value of
PreparedStatement.executeUpdate()
-
insertIgnore
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:
- Return value of
PreparedStatement.executeUpdate()
-
deleteFrom
int deleteFrom(@NotNull @NotNull String tableName, @Nullable @Nullable String whereClause, @NotNull @NotNull List<Object> whereParams) Delete entries with aListreplacing the question marks in thewhereClausee.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:
- Number of rows affected
-
deleteFrom
-
update
int 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:
- Number of rows affected
-
update
int 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:
- Number of rows affected
-
dropTable
Drop a table from the database e.g.:
dropTable("current-weak-save");- Parameters:
tableName- Name of the table to drop- Returns:
- Return value of
PreparedStatement.executeUpdate()
-
columnExists
-
indexExists
-
executeBatchSql(BatchSqlStatements, String)instead