Class SQLDialect
java.lang.Object
xyz.srnyx.annoyingapi.storage.dialects.Dialect
xyz.srnyx.annoyingapi.storage.dialects.SQLDialect
SQL dialect for a specific type of database
-
Nested Class Summary
Nested classes/interfaces inherited from class xyz.srnyx.annoyingapi.storage.dialects.Dialect
Dialect.MigrationData, Dialect.Stats -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal @NotNull ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, CachedValue>>> [ Table name: [ Target: [ Data key: Data value ] ] ]Map<Table name, Map<Target, Map<Data key, Data value>>>final @NotNull com.zaxxer.hikari.HikariDataSourcefinal @NotNull org.jooq.DSLContextFields inherited from class xyz.srnyx.annoyingapi.storage.dialects.Dialect
dataManager -
Constructor Summary
ConstructorsConstructorDescriptionSQLDialect(@NotNull DataManager dataManager, org.jooq.SQLDialect jooqDialect) Construct a newSQLDialectwith the givenDataManager -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateTablesKeys(@NotNull Map<String, Set<String>> tablesKeys) Create the given tables and keys in the database@Nullable CachedValuegetFromCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the cachegetFromDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the database@NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabaseImpl(@NotNull DataManager newManager) Get migration data from the database@NotNull Dialect.StatsgetStats()voidmarkRemovedInCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key) Mark a value as removed in the cacheprotected booleanremoveFromDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull String key) Remove a value from the databasevoidSave all cache data to the databasevoidsaveCacheImpl(@NotNull String table, @NotNull String target) Save a specific target in a table to the cachevoidsetToCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key, @NotNull CachedValue value) Set a value to the cacheprotected @Nullable FailedSetsetToDatabaseImpl(@NotNull String table, @NotNull String target, @NotNull String key, @NotNull String value) Set a value to the databaseSet multiple values to the databasevoidWarms up jOOQ's SELECT/UPDATE/INSERT code paths for the given table so the classloading/JIT cost of first use doesn't impact realget/set/removecall
Uses a sentinel target that can never match a real row, so nothing is ever written or needs cleaning upMethods inherited from class xyz.srnyx.annoyingapi.storage.dialects.Dialect
getFromCache, getFromDatabase, getMigrationDataFromDatabase, markRemovedInCache, removeValueFromDatabase, saveCache, saveCache, setToCache, setToDatabase, setToDatabase, setToDatabase
-
Field Details
-
dataSource
@NotNull public final @NotNull com.zaxxer.hikari.HikariDataSource dataSource -
dsl
@NotNull public final @NotNull org.jooq.DSLContext dsl -
cache
@NotNull public final @NotNull ConcurrentHashMap<String,ConcurrentHashMap<String, cacheConcurrentHashMap<String, CachedValue>>> [ Table name: [ Target: [ Data key: Data value ] ] ]Map<Table name, Map<Target, Map<Data key, Data value>>>
-
-
Constructor Details
-
SQLDialect
public SQLDialect(@NotNull @NotNull DataManager dataManager, @NotNull org.jooq.SQLDialect jooqDialect) throws ConnectionException Construct a newSQLDialectwith the givenDataManager- Parameters:
dataManager-Dialect.dataManager- Throws:
ConnectionException- if a database connection error occurs
-
-
Method Details
-
getStats
-
getFromCacheImpl
@Nullable public @Nullable CachedValue getFromCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key) Description copied from class:DialectGet a value from the cache- Specified by:
getFromCacheImplin classDialect- Parameters:
table- the tabletarget- the targetkey- the key- Returns:
- the value inside a
CachedValue, null if it isn't cached
-
setToCacheImpl
public void setToCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @NotNull @NotNull CachedValue value) Description copied from class:DialectSet a value to the cache- Specified by:
setToCacheImplin classDialect- Parameters:
table- the tabletarget- the targetkey- the keyvalue- the value inside aCachedValue
-
markRemovedInCacheImpl
public void markRemovedInCacheImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key) Description copied from class:DialectMark a value as removed in the cache- Specified by:
markRemovedInCacheImplin classDialect- Parameters:
table- the tabletarget- the targetkey- the key
-
saveCacheImpl
public void saveCacheImpl()Description copied from class:DialectSave all cache data to the database- Specified by:
saveCacheImplin classDialect
-
saveCacheImpl
Description copied from class:DialectSave a specific target in a table to the cache- Specified by:
saveCacheImplin classDialect- Parameters:
table- the table to save intarget- the target to save
-
getMigrationDataFromDatabaseImpl
@NotNull public @NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabaseImpl(@NotNull @NotNull DataManager newManager) Description copied from class:DialectGet migration data from the database- Specified by:
getMigrationDataFromDatabaseImplin classDialect- Parameters:
newManager- the newDataManagerto migrate to- Returns:
- the migration data, empty if something went wrong
-
getFromDatabaseImpl
@NotNull protected @NotNull Optional<String> getFromDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key) Description copied from class:DialectGet a value from the database- Specified by:
getFromDatabaseImplin classDialect- 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 @Nullable FailedSet setToDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key, @NotNull @NotNull String value) Description copied from class:DialectSet a value to the database- Specified by:
setToDatabaseImplin classDialect- 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 @NotNull List<FailedSet> setToDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull Map<String, String> data) Description copied from class:DialectSet multiple values to the database- Specified by:
setToDatabaseImplin classDialect- Parameters:
table- the table to set totarget- the target to set todata- the data to set- Returns:
- failed values as
FailedSets
-
removeFromDatabaseImpl
protected boolean removeFromDatabaseImpl(@NotNull @NotNull String table, @NotNull @NotNull String target, @NotNull @NotNull String key) Description copied from class:DialectRemove a value from the database- Specified by:
removeFromDatabaseImplin classDialect- 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
-
createTablesKeys
Create the given tables and keys in the database- Parameters:
tablesKeys- the tables and keys to create
-
warmup
Warms up jOOQ's SELECT/UPDATE/INSERT code paths for the given table so the classloading/JIT cost of first use doesn't impact realget/set/removecall
Uses a sentinel target that can never match a real row, so nothing is ever written or needs cleaning up- Parameters:
rawTable- the (unprefixed) table to warm up against
-