java.lang.Object
xyz.srnyx.annoyingapi.storage.dialects.Dialect
Direct Known Subclasses:
JSONDialect, SQLDialect, YAMLDialect

public abstract class Dialect extends Object
Dialect for a specific type of database
  • Field Details

    • dataManager

      @NotNull protected final @NotNull DataManager dataManager
      The DataManager to use for database operations
  • Constructor Details

  • Method Details

    • getFromCache

      @Nullable public @Nullable Value getFromCache(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Get a value from the cache
      Parameters:
      table - the table to get from
      target - the target to get from
      key - the key to get
      Returns:
      the value, empty if not found
    • setToCache

      public void setToCache(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @Nullable @Nullable Value value)
      Set a value to the cache
      Parameters:
      table - the table
      target - the target
      key - the key
      value - the value
    • markRemovedInCache

      public void markRemovedInCache(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Mark a value as removed in the cache
      Parameters:
      table - the table
      target - the target
      key - the key
    • saveCache

      public void saveCache()
      Save all cache data to the database
    • saveCache

      public void saveCache(@NotNull @NotNull String table, @NotNull @NotNull String target)
      Save a specific target in a table to the cache
      Parameters:
      table - the table to save in
      target - the target to save
    • getMigrationDataFromDatabase

      @NotNull public final @NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabase(@NotNull @NotNull DataManager newManager)
      Get migration data from the database
      Parameters:
      newManager - the new DataManager to migrate to
      Returns:
      the migration data, empty if something went wrong
    • getFromDatabase

      @NotNull public final @NotNull Optional<String> getFromDatabase(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Get a value from the database
      Parameters:
      table - the table
      target - the target
      key - the key
      Returns:
      the value, empty if not found
    • setToDatabase

      @Nullable public final @Nullable FailedSet setToDatabase(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @NotNull @NotNull String value)
      Set a value to the database
      Parameters:
      table - the table
      target - the target
      key - the key
      value - the value
      Returns:
      the failed value information, null if successful
    • setToDatabase

      @NotNull public final @NotNull Set<FailedSet> setToDatabase(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull ConcurrentHashMap<String,Value> data)
      Set a value to the database
      Parameters:
      table - the table
      target - the target
      data - the data to set
      Returns:
      set of failed values as FailedSets
    • setToDatabase

      @NotNull public final @NotNull Set<FailedSet> setToDatabase(@NotNull @NotNull ConcurrentHashMap<String,ConcurrentHashMap<String,ConcurrentHashMap<String,Value>>> data)
      Set multiple values to the database
      Parameters:
      data - the data to set
      Returns:
      set of failed values as FailedSets
    • removeValueFromDatabase

      public final boolean removeValueFromDatabase(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Remove a value from the database
      Parameters:
      table - the table
      target - the target
      key - the key
      Returns:
      true if the value was successfully removed, false otherwise
    • getFromCacheImpl

      @Nullable protected abstract @Nullable Value getFromCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Get a value from the cache
      Parameters:
      table - the table
      target - the target
      key - the key
      Returns:
      the value inside a Value, null if it isn't cached
    • setToCacheImpl

      protected abstract void setToCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @NotNull @NotNull Value value)
      Set a value to the cache
      Parameters:
      table - the table
      target - the target
      key - the key
      value - the value inside a Value
    • markRemovedInCacheImpl

      protected abstract void markRemovedInCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Mark a value as removed in the cache
      Parameters:
      table - the table
      target - the target
      key - the key
    • saveCacheImpl

      protected abstract void saveCacheImpl()
      Save all cache data to the database
    • saveCacheImpl

      protected abstract void saveCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target)
      Save a specific target in a table to the cache
      Parameters:
      table - the table to save in
      target - the target to save
    • getMigrationDataFromDatabaseImpl

      @NotNull protected abstract @NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabaseImpl(@NotNull @NotNull DataManager newManager)
      Get migration data from the database
      Parameters:
      newManager - the new DataManager to migrate to
      Returns:
      the migration data, empty if something went wrong
    • getFromDatabaseImpl

      @NotNull protected abstract @NotNull Optional<String> getFromDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Get a value from the database
      Parameters:
      table - the table to get from
      target - the target to get from
      key - the key to get
      Returns:
      the value, empty if not found
    • setToDatabaseImpl

      @Nullable protected abstract @Nullable FailedSet setToDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @NotNull @NotNull String value)
      Set a value to the database
      Parameters:
      table - the table to set to
      target - the target to set to
      key - the key to set
      value - the value to set
      Returns:
      the failed value information, null if successful
    • setToDatabaseImpl

      @NotNull protected abstract @NotNull Set<FailedSet> setToDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull ConcurrentHashMap<String,Value> data)
      Set multiple values to the database
      Parameters:
      table - the table to set to
      target - the target to set to
      data - the data to set
      Returns:
      set of failed values as FailedSets
    • removeFromDatabaseImpl

      protected abstract boolean removeFromDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key)
      Remove a value from the database
      Parameters:
      table - the table to remove from
      target - the target to remove from
      key - the key to remove
      Returns:
      true if the value was successfully removed, false otherwise