Class SQLDialect

java.lang.Object
xyz.srnyx.annoyingapi.storage.dialects.Dialect
xyz.srnyx.annoyingapi.storage.dialects.sql.SQLDialect
Direct Known Subclasses:
H2Dialect, MariaDBDialect, MySQLDialect, PostgreSQLDialect, SQLiteDialect

public abstract class SQLDialect extends Dialect
SQL dialect for a specific type of database
  • Field Details

  • Constructor Details

  • Method Details

    • getFromCacheImpl

      @Nullable public @Nullable Value getFromCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Description copied from class: Dialect
      Get a value from the cache
      Specified by:
      getFromCacheImpl in class Dialect
      Parameters:
      table - the table
      target - the target
      key - the key
      Returns:
      the value inside a Value, null if it isn't cached
    • setToCacheImpl

      public void setToCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @NotNull @NotNull Value value)
      Description copied from class: Dialect
      Set a value to the cache
      Specified by:
      setToCacheImpl in class Dialect
      Parameters:
      table - the table
      target - the target
      key - the key
      value - the value inside a Value
    • markRemovedInCacheImpl

      public void markRemovedInCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Description copied from class: Dialect
      Mark a value as removed in the cache
      Specified by:
      markRemovedInCacheImpl in class Dialect
      Parameters:
      table - the table
      target - the target
      key - the key
    • saveCacheImpl

      public void saveCacheImpl()
      Description copied from class: Dialect
      Save all cache data to the database
      Specified by:
      saveCacheImpl in class Dialect
    • saveCacheImpl

      public void saveCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target)
      Description copied from class: Dialect
      Save a specific target in a table to the cache
      Specified by:
      saveCacheImpl in class Dialect
      Parameters:
      table - the table to save in
      target - the target to save
    • getMigrationDataFromDatabaseImpl

      @NotNull public @NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabaseImpl(@NotNull @NotNull DataManager newManager)
      Description copied from class: Dialect
      Get migration data from the database
      Specified by:
      getMigrationDataFromDatabaseImpl in class Dialect
      Parameters:
      newManager - the new DataManager to migrate to
      Returns:
      the migration data, empty if something went wrong
    • createTablesKeys

      public void createTablesKeys(@NotNull @NotNull Map<String,Set<String>> tablesKeys)
      Create the given tables and keys in the database
      Parameters:
      tablesKeys - the tables and keys to create
    • setValuesParameters

      @NotNull protected @NotNull PreparedStatement setValuesParameters(@NotNull @NotNull String target, @NotNull @NotNull List<Value> values, @NotNull @NotNull StringBuilder insertBuilder, @NotNull @NotNull StringBuilder valuesBuilder, @Nullable @Nullable StringBuilder updateBuilder) throws SQLException
      Parameters:
      target - the target to set the value to
      values - the values to set as Values
      insertBuilder - the insert query builder
      valuesBuilder - the values query builder
      updateBuilder - the update query builder
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database access error occurs
    • getTables

      @NotNull public final @NotNull PreparedStatement getTables() throws SQLException
      Get all tables from the database
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • createTable

      @NotNull public final @NotNull PreparedStatement createTable(@NotNull @NotNull String table) throws SQLException
      Create a table in the database
      Parameters:
      table - the table to create
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • createKey

      @Nullable public final @Nullable PreparedStatement createKey(@NotNull @NotNull String table, @NotNull @NotNull String key) throws SQLException
      Create a key in the given table (converts the key to lowercase)
      Parameters:
      table - the table to create the key in
      key - the key to create
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • getAllValuesFromDatabase

      @NotNull public final @NotNull PreparedStatement getAllValuesFromDatabase(@NotNull @NotNull String table) throws SQLException
      Get all values from the database
      Parameters:
      table - the table to get the values from
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • getTablesImpl

      @NotNull protected abstract @NotNull PreparedStatement getTablesImpl() throws SQLException
      Get all tables from the database
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • createTableImpl

      @NotNull protected abstract @NotNull PreparedStatement createTableImpl(@NotNull @NotNull String table) throws SQLException
      Create a table in the database
      Parameters:
      table - the table to create
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • createKeyImpl

      @Nullable protected abstract @Nullable PreparedStatement createKeyImpl(@NotNull @NotNull String table, @NotNull @NotNull String key) throws SQLException
      Create a key in the given table
      Parameters:
      table - the table to create the key in
      key - the key to create
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs
    • getAllValuesFromDatabaseImpl

      @NotNull protected abstract @NotNull PreparedStatement getAllValuesFromDatabaseImpl(@NotNull @NotNull String table) throws SQLException
      Get all values from the database
      Parameters:
      table - the table to get the values from
      Returns:
      the PreparedStatement with the set parameters
      Throws:
      SQLException - if a database error occurs