Class Dialect
java.lang.Object
xyz.srnyx.annoyingapi.storage.dialects.Dialect
- Direct Known Subclasses:
JSONDialect,SQLDialect,YAMLDialect
Dialect for a specific type of database
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classData for a database migration -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @NotNull DataManagerTheDataManagerto use for database operations -
Constructor Summary
ConstructorsConstructorDescriptionDialect(@NotNull DataManager dataManager) Construct a newDialectwith the givenDataManager -
Method Summary
Modifier and TypeMethodDescription@Nullable ValuegetFromCache(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the cacheprotected abstract @Nullable ValuegetFromCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the cachegetFromDatabase(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the databasegetFromDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the databasefinal @NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabase(@NotNull DataManager newManager) Get migration data from the databaseprotected abstract @NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabaseImpl(@NotNull DataManager newManager) Get migration data from the databasevoidmarkRemovedInCache(@NotNull String table, @NotNull String target, @NotNull String key) Mark a value as removed in the cacheprotected abstract voidmarkRemovedInCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key) Mark a value as removed in the cacheprotected abstract booleanremoveFromDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull String key) Remove a value from the databasefinal booleanremoveValueFromDatabase(@NotNull String table, @NotNull String target, @NotNull String key) Remove a value from the databasevoidSave all cache data to the databasevoidSave a specific target in a table to the cacheprotected abstract voidSave all cache data to the databaseprotected abstract voidsaveCacheImpl(@NotNull String table, @NotNull String target) Save a specific target in a table to the cachevoidsetToCache(@NotNull String table, @NotNull String target, @NotNull String key, @Nullable Value value) Set a value to the cacheprotected abstract voidsetToCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key, @NotNull Value value) Set a value to the cachefinal @Nullable FailedSetsetToDatabase(@NotNull String table, @NotNull String target, @NotNull String key, @NotNull String value) Set a value to the databasesetToDatabase(@NotNull String table, @NotNull String target, @NotNull ConcurrentHashMap<String, Value> data) Set a value to the databasesetToDatabase(@NotNull ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, Value>>> data) Set multiple values to the databaseprotected abstract @Nullable FailedSetsetToDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull String key, @NotNull String value) Set a value to the databasesetToDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull ConcurrentHashMap<String, Value> data) Set multiple values to the database
-
Field Details
-
dataManager
TheDataManagerto use for database operations
-
-
Constructor Details
-
Dialect
Construct a newDialectwith the givenDataManager- Parameters:
dataManager-dataManager
-
-
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 fromtarget- the target to get fromkey- 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 tabletarget- the targetkey- the keyvalue- 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 tabletarget- the targetkey- the key
-
saveCache
public void saveCache()Save all cache data to the database -
saveCache
Save a specific target in a table to the cache- Parameters:
table- the table to save intarget- 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 newDataManagerto 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 tabletarget- the targetkey- 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 tabletarget- the targetkey- the keyvalue- 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 tabletarget- the targetdata- 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 tabletarget- the targetkey- 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 tabletarget- the targetkey- 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 tabletarget- the targetkey- the keyvalue- the value inside aValue
-
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 tabletarget- the targetkey- 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 intarget- 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 newDataManagerto 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 fromtarget- the target to get fromkey- 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 totarget- the target to set tokey- the key to setvalue- 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 totarget- the target to set todata- 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 fromtarget- the target to remove fromkey- the key to remove- Returns:
- true if the value was successfully removed, false otherwise
-