Class SqliteManager

java.lang.Object
All Implemented Interfaces:
DBManager, SyncDBManager, Copyable<DBManager>

public class SqliteManager extends AbstractSqliteManager implements SyncDBManager
  • Constructor Details

    • SqliteManager

      public SqliteManager(@Nullable @Nullable String path, @NotNull @NotNull String name, @Nullable @Nullable com.zaxxer.hikari.HikariDataSource dataSource, @Nullable @Nullable String projectName)
  • Method Details

    • createOrAlter

      public void createOrAlter(@NotNull @NotNull DBTable dbTable) throws IllegalArgumentException
      Description copied from interface: SyncDBManager
      Create a database table using a DBTable object, suitable for the DBManager (MariaDBManager: MariaDBTable SqliteManager: SqliteTable)
      Specified by:
      createOrAlter in interface SyncDBManager
      Parameters:
      dbTable - Table that is created or altered
      Throws:
      IllegalArgumentException - when the dbTable param is not the suitable type for the DBManager
    • executeSql

      public int executeSql(@NotNull @NotNull String sql, @NotNull @NotNull List<Object> sqlParams, @NotNull @NotNull String tableName, @Nullable @Nullable String type)
      Description copied from interface: SyncDBManager
      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");
      Specified by:
      executeSql in interface SyncDBManager
      Parameters:
      sql - Query that should be executed
      sqlParams - Values replacing the ?'s in the sql query
      tableName - Name of the table, querying to
      type - Type of execution
      Returns:
      Return value of the PreparedStatement.executeUpdate()
    • executeSql

      public int executeSql(@NotNull @NotNull String sql, @NotNull @NotNull String tableName, @Nullable @Nullable String type)
      Description copied from interface: SyncDBManager
      Execute a SQL query
      e.g.:
      executeSql("UPDATE users SET name = " + username + " WHERE id = " + userId, "users", "update username");
      Specified by:
      executeSql in interface SyncDBManager
      Parameters:
      sql - Query that should be executed
      tableName - Name of the table, querying to
      type - Type of execution
      Returns:
      Return value of PreparedStatement.executeUpdate()
    • executeBatchSql

      @Deprecated public int[] executeBatchSql(@NotNull @NotNull List<BatchSqlStatement> sqlStatements, @NotNull @NotNull String tableName)
      Deprecated.
      Description copied from interface: SyncDBManager
      Executes multiple SQL statements with the same structure in batch mode for better performance
      e.g.:
      executeBatchSql(batchStatementList, "users", "batch update");
      Specified by:
      executeBatchSql in interface SyncDBManager
      Parameters:
      sqlStatements - List of SQL statements with their parameters
      tableName - Name of the table, querying to
      Returns:
      Return value of Statement.executeBatch()
    • executeBatchSql

      public int[] executeBatchSql(@NotNull @NotNull BatchSqlStatements sqlStatements, @NotNull @NotNull String tableName)
      Description copied from interface: SyncDBManager
      Executes multiple SQL statements with the same structure in batch mode for better performance
      e.g.:
      executeBatchSql(batchStatementList, "users", "batch update");
      Specified by:
      executeBatchSql in interface SyncDBManager
      Parameters:
      sqlStatements - List of SQL statements with their parameters
      tableName - Name of the table, querying to
      Returns:
      Return value of Statement.executeBatch()
    • executeSelect

      public SelectionResults executeSelect(@NotNull @NotNull String sql, @NotNull @NotNull List<Object> sqlParams, @NotNull @NotNull String tableName)
      Description copied from interface: SyncDBManager
      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");
      Specified by:
      executeSelect in interface SyncDBManager
      Parameters:
      sql - Sql query
      sqlParams - Values replacing the ?'s in the sql query
      tableName - Name of the table, to select from
      Returns:
      SelectionResults object representing the result
    • executeSelect

      public SelectionResults executeSelect(@NotNull @NotNull String sql, @NotNull @NotNull String tableName)
      Description copied from interface: SyncDBManager
      Execute a selection query
      e.g.
      executeSelect("SELECT email, number FROM users WHERE username = Mr_Tesz", "users");
      Specified by:
      executeSelect in interface SyncDBManager
      Parameters:
      sql - Sql query
      tableName - Name of the table, to select from
      Returns:
      SelectionResults object representing the result
    • insertInto

      public int insertInto(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values)
      Description copied from interface: SyncDBManager
      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);
      Specified by:
      insertInto in interface SyncDBManager
      Parameters:
      tableName - Name of the table, inserting into
      values - Values to insert
      Returns:
      Return value of PreparedStatement.executeUpdate()
    • insertIgnore

      public int insertIgnore(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values)
      Description copied from interface: SyncDBManager
      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);
      Specified by:
      insertIgnore in interface SyncDBManager
      Parameters:
      tableName - Name of the table, inserting into
      values - Values to insert
      Returns:
      Return value of PreparedStatement.executeUpdate()
    • deleteFrom

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

      public int deleteFrom(@NotNull @NotNull String tableName, String whereClause)
      Description copied from interface: SyncDBManager
      Delete entries e.g.:
      deleteFrom("users", "userId = " + userId);
      Specified by:
      deleteFrom in interface SyncDBManager
      Parameters:
      tableName - Table name
      whereClause - WHERE clause
      Returns:
      Number of rows affected
    • update

      public int update(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values, @Nullable @Nullable String whereClause, @NotNull @NotNull List<Object> whereParams)
      Description copied from interface: SyncDBManager
      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);
      Specified by:
      update in interface SyncDBManager
      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:
      Number of rows affected
    • update

      public int update(@NotNull @NotNull String tableName, @NotNull @NotNull Map<String,Object> values, @Nullable @Nullable String whereClause)
      Description copied from interface: SyncDBManager
      Update a table
      e.g.:
      Map<String, Object> values = new HashMapinvalid input: '<'>();
      values.put("name", username);
      update("users", values, "id = " + userId);
      Specified by:
      update in interface SyncDBManager
      Parameters:
      tableName - Name of the table, updating
      values - Values to update
      whereClause - Clause, narrowing the targeted columns
      Returns:
      Number of rows affected
    • dropTable

      public int dropTable(@NotNull @NotNull String tableName)
      Description copied from interface: SyncDBManager
      Drop a table from the database e.g.:
      dropTable("current-weak-save");
      Specified by:
      dropTable in interface SyncDBManager
      Parameters:
      tableName - Name of the table to drop
      Returns:
      Return value of PreparedStatement.executeUpdate()
    • columnExists

      public boolean columnExists(@NotNull @NotNull String tableName, @NotNull @NotNull String columnName)
      Description copied from interface: SyncDBManager
      Show if a column exists in a table
      Specified by:
      columnExists in interface SyncDBManager
      Parameters:
      tableName - Name of the table, checking
      columnName - Name of the column to be checked
      Returns:
      true if the column exists
    • indexExists

      public boolean indexExists(@NotNull @NotNull String tableName, @NotNull @NotNull String indexName)
      Description copied from interface: SyncDBManager
      Show if an index exists in a table
      Specified by:
      indexExists in interface SyncDBManager
      Parameters:
      tableName - Name of the table, checking
      indexName - Name of the index to be checked
      Returns:
      true if the index exists
    • copy

      public SqliteManager copy()
      Description copied from interface: Copyable
      Copy the executing class
      Specified by:
      copy in interface Copyable<DBManager>
      Returns:
      a copy of the class executed in