Class Dialect
- java.lang.Object
-
- xyz.srnyx.annoyingapi.storage.dialects.Dialect
-
- Direct Known Subclasses:
JSONDialect,SQLDialect,YAMLDialect
public abstract class Dialect extends java.lang.ObjectDialect for a specific type of database
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDialect.MigrationDataData for a database migration
-
Field Summary
Fields Modifier and Type Field Description protected @NotNull DataManagerdataManagerTheDataManagerto use for database operations
-
Constructor Summary
Constructors Constructor Description Dialect(@NotNull DataManager dataManager)Construct a newDialectwith the givenDataManager
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description @Nullable ValuegetFromCache(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Get a value from the cacheprotected abstract @Nullable ValuegetFromCacheImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Get a value from the cache@NotNull java.util.Optional<java.lang.String>getFromDatabase(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Get a value from the databaseprotected abstract @NotNull java.util.Optional<java.lang.String>getFromDatabaseImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Get a value from the database@NotNull java.util.Optional<Dialect.MigrationData>getMigrationDataFromDatabase(@NotNull DataManager newManager)Get migration data from the databaseprotected abstract @NotNull java.util.Optional<Dialect.MigrationData>getMigrationDataFromDatabaseImpl(@NotNull DataManager newManager)Get migration data from the databasevoidmarkRemovedInCache(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Mark a value as removed in the cacheprotected abstract voidmarkRemovedInCacheImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Mark a value as removed in the cacheprotected abstract booleanremoveFromDatabaseImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Remove a value from the databasebooleanremoveValueFromDatabase(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key)Remove a value from the databasevoidsaveCache()Save all cache data to the databasevoidsaveCache(@NotNull java.lang.String table, @NotNull java.lang.String target)Save a specific target in a table to the cacheprotected abstract voidsaveCacheImpl()Save all cache data to the databaseprotected abstract voidsaveCacheImpl(@NotNull java.lang.String table, @NotNull java.lang.String target)Save a specific target in a table to the cachevoidsetToCache(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key, @Nullable Value value)Set a value to the cacheprotected abstract voidsetToCacheImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key, @NotNull Value value)Set a value to the cache@Nullable FailedSetsetToDatabase(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key, @NotNull java.lang.String value)Set a value to the database@NotNull java.util.Set<FailedSet>setToDatabase(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.util.concurrent.ConcurrentHashMap<java.lang.String,Value> data)Set a value to the database@NotNull java.util.Set<FailedSet>setToDatabase(@NotNull java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.concurrent.ConcurrentHashMap<java.lang.String,Value>>> data)Set multiple values to the databaseprotected abstract @Nullable FailedSetsetToDatabaseImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.lang.String key, @NotNull java.lang.String value)Set a value to the databaseprotected abstract @NotNull java.util.Set<FailedSet>setToDatabaseImpl(@NotNull java.lang.String table, @NotNull java.lang.String target, @NotNull java.util.concurrent.ConcurrentHashMap<java.lang.String,Value> data)Set multiple values to the database
-
-
-
Field Detail
-
dataManager
@NotNull protected final @NotNull DataManager dataManager
TheDataManagerto use for database operations
-
-
Constructor Detail
-
Dialect
public Dialect(@NotNull @NotNull DataManager dataManager)Construct a newDialectwith the givenDataManager- Parameters:
dataManager-dataManager
-
-
Method Detail
-
getFromCache
@Nullable public @Nullable Value getFromCache(@NotNull @NotNull java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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
public void saveCache(@NotNull @NotNull java.lang.String table, @NotNull @NotNull java.lang.String target)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 java.util.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 java.util.Optional<java.lang.String> getFromDatabase(@NotNull @NotNull java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.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 java.util.Set<FailedSet> setToDatabase(@NotNull @NotNull java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.util.concurrent.ConcurrentHashMap<java.lang.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 java.util.Set<FailedSet> setToDatabase(@NotNull @NotNull java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.concurrent.ConcurrentHashMap<java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.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 java.util.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 java.util.Optional<java.lang.String> getFromDatabaseImpl(@NotNull @NotNull java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.String key, @NotNull @NotNull java.lang.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 java.util.Set<FailedSet> setToDatabaseImpl(@NotNull @NotNull java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.util.concurrent.ConcurrentHashMap<java.lang.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 java.lang.String table, @NotNull @NotNull java.lang.String target, @NotNull @NotNull java.lang.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
-
-