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
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal @NotNull ConcurrentHashMap<String, ConcurrentHashMap<String, ConcurrentHashMap<String, Value>>> Key: table name Value: Key: target Value: Key: data key Value: data valuefinal @NotNull ConnectionTheconnectionto the databaseFields inherited from class xyz.srnyx.annoyingapi.storage.dialects.Dialect
dataManager -
Constructor Summary
ConstructorsConstructorDescriptionSQLDialect(@NotNull DataManager dataManager) Construct a newSQLDialectwith the givenDataManager -
Method Summary
Modifier and TypeMethodDescriptionfinal @Nullable PreparedStatementCreate a key in the given table (converts the key to lowercase)protected abstract @Nullable PreparedStatementcreateKeyImpl(@NotNull String table, @NotNull String key) Create a key in the given tablefinal @NotNull PreparedStatementcreateTable(@NotNull String table) Create a table in the databaseprotected abstract @NotNull PreparedStatementcreateTableImpl(@NotNull String table) Create a table in the databasevoidcreateTablesKeys(@NotNull Map<String, Set<String>> tablesKeys) Create the given tables and keys in the databasefinal @NotNull PreparedStatementgetAllValuesFromDatabase(@NotNull String table) Get all values from the databaseprotected abstract @NotNull PreparedStatementgetAllValuesFromDatabaseImpl(@NotNull String table) Get all values from the database@Nullable ValuegetFromCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key) Get a value from the cache@NotNull Optional<Dialect.MigrationData> getMigrationDataFromDatabaseImpl(@NotNull DataManager newManager) Get migration data from the databasefinal @NotNull PreparedStatementGet all tables from the databaseprotected abstract @NotNull PreparedStatementGet all tables from the databasevoidmarkRemovedInCacheImpl(@NotNull String table, @NotNull String target, @NotNull String key) Mark a value as removed in the cachevoidSave 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 Value value) Set a value to the cacheprotected @NotNull PreparedStatementsetValuesParameters(@NotNull String target, @NotNull List<Value> values, @NotNull StringBuilder insertBuilder, @NotNull StringBuilder valuesBuilder, @Nullable StringBuilder updateBuilder) Used forDialect.setToDatabaseImpl(String, String, String, String)to set the parameters of thePreparedStatementMethods inherited from class xyz.srnyx.annoyingapi.storage.dialects.Dialect
getFromCache, getFromDatabase, getFromDatabaseImpl, getMigrationDataFromDatabase, markRemovedInCache, removeFromDatabaseImpl, removeValueFromDatabase, saveCache, saveCache, setToCache, setToDatabase, setToDatabase, setToDatabase, setToDatabaseImpl, setToDatabaseImpl
-
Field Details
-
connection
Theconnectionto the database -
cache
@NotNull public final @NotNull ConcurrentHashMap<String,ConcurrentHashMap<String, cacheConcurrentHashMap<String, Value>>> - Key: table name
- Value:
- Key: target
- Value:
- Key: data key
- Value: data value
-
-
Constructor Details
-
SQLDialect
Construct a newSQLDialectwith the givenDataManager- Parameters:
dataManager-Dialect.dataManager- Throws:
ConnectionException- if a database connection error occurs
-
-
Method Details
-
getFromCacheImpl
@Nullable public @Nullable Value 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
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:DialectSet a value to the cache- Specified by:
setToCacheImplin classDialect- Parameters:
table- the tabletarget- the targetkey- the keyvalue- the value inside aValue
-
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
-
createTablesKeys
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 Used forDialect.setToDatabaseImpl(String, String, String, String)to set the parameters of thePreparedStatement- Parameters:
target- the target to set the value tovalues- the values to set asValuesinsertBuilder- the insert query buildervaluesBuilder- the values query builderupdateBuilder- the update query builder- Returns:
- the
PreparedStatementwith the set parameters - Throws:
SQLException- if a database access error occurs
-
getTables
Get all tables from the database- Returns:
- the
PreparedStatementwith 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
PreparedStatementwith 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 inkey- the key to create- Returns:
- the
PreparedStatementwith 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
PreparedStatementwith the set parameters - Throws:
SQLException- if a database error occurs
-
getTablesImpl
Get all tables from the database- Returns:
- the
PreparedStatementwith 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
PreparedStatementwith 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 inkey- the key to create- Returns:
- the
PreparedStatementwith 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
PreparedStatementwith the set parameters - Throws:
SQLException- if a database error occurs
-