Class MariaDBStore
- Author:
- gmt2001
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Creates a new tablevoid
AddFile
(Connection connection, String fName) boolean
Tests if the connection to the database succeedsboolean
FileExists
(String fName) Indicates if the given table already existsboolean
FileExists
(Connection connection, String fName) String[]
GetCategoryList
(String fName) Returns a list of all values in thesection
column within the tableString[]
Returns a list of tables in the database.GetKeyByValue
(String fName, String section, String value) Returns the value of thevariable
column for the given table, section, and valueString[]
GetKeyList
(String fName, String section) Returns a list of all values in thevariable
column within the table and sectionString[]
GetKeysByLikeKeys
(String fName, String section, String search) Returns a list of values in thevariable
column within the table and section, where the value of thevariable
column contains the search phraseString[]
GetKeysByLikeKeysOrder
(String fName, String section, String search, String order, String limit, String offset) Returns a list of values in thevariable
column within the table and section, where the value of thevariable
column contains the search phrase, sorted naturallyString[]
GetKeysByLikeValues
(String fName, String section, String search) Returns a list of values in thevariable
column within the table and section, where the value of thevalue
column contains the search phraseString[]
Returns a list of values in thevariable
column within the table and section, sorted naturally as integersString[]
Returns a list of values in thevariable
column within the table and section, sorted naturally by thevalue
column as integersString[]
Returns a list of values in thevariable
column within the table and section, sorted naturallyString[]
Returns a list of values in thevariable
column within the table and section, sorted naturally by thevalue
columnKeyValue[]
GetKeyValueList
(String fName, String section) Returns a list of allvariable/value
pairs within the table and sectionReturns the value of thevalue
column for the given table, section, and key as a stringboolean
Indicates if the given table contains a row matching the given section and keyvoid
IncreaseBatchString
(String fName, String section, String[] keys, String value) Increases the value of thevalue
column as an integer for all keys of the given table and sectionstatic MariaDBStore
instance()
static MariaDBStore
Executes an SQL queryvoid
RemoveFile
(String fName) Deletes the tablevoid
Deletes the row that matches the given table, section, and keyvoid
RemoveSection
(String fName, String section) Deletes all rows that match the given table and sectionvoid
RenameFile
(String fNameSource, String fNameDest) Renames the tablevoid
SetBatchString
(String fName, String section, String[] keys, String[] values) Performs a bulkDataStore.SetString(String, String, String, String)
operation, using available database features to do so more efficiently.void
Sets the value of thevalue
column for the given table, section, and key as a stringMethods inherited from class com.gmt2001.datastore.DataStore
backupDB, canBackup, CreateIndexes, decr, decr, decrD, decrD, decrF, decrF, decrL, decrL, del, dispose, DropIndexes, dsl, executeSql, exists, field, findTable, get, GetBoolean, GetBoolean, GetDouble, GetDouble, GetFloat, GetFloat, GetInteger, GetInteger, GetKeysByLikeKeysOrder, GetKeysByLikeKeysOrder, GetKeysByLikeKeysOrder, GetKeysByNumberOrder, GetKeysByNumberOrder, GetKeysByNumberOrder, GetKeysByNumberOrderValue, GetKeysByNumberOrderValue, GetKeysByNumberOrderValue, GetKeysByOrder, GetKeysByOrder, GetKeysByOrder, GetKeysByOrderValue, GetKeysByOrderValue, GetKeysByOrderValue, GetLong, GetLong, GetString, incr, incr, incrD, incrD, incrF, incrF, incrL, incrL, InsertString, OptBoolean, OptDouble, OptFloat, OptInteger, OptLong, OptRecord, OptRecord, OptString, resolveClassname, searchByKey, searchByValue, set, setbatch, SetBoolean, SetDouble, SetFloat, SetInteger, SetLong
-
Method Details
-
instance
-
instance
-
CanConnect
public boolean CanConnect()Description copied from class:DataStore
Tests if the connection to the database succeeds- Overrides:
CanConnect
in classDataStore
- Returns:
true
on success
-
AddFile
Description copied from class:DataStore
Creates a new table -
AddFile
-
RemoveKey
Description copied from class:DataStore
Deletes the row that matches the given table, section, and keyIf
section
is null, deletes all rows with a matching table and key, regardless of section -
RemoveSection
Description copied from class:DataStore
Deletes all rows that match the given table and section- Overrides:
RemoveSection
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section
-
RemoveFile
Description copied from class:DataStore
Deletes the table- Overrides:
RemoveFile
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefix
-
RenameFile
Description copied from class:DataStore
Renames the table- Overrides:
RenameFile
in classDataStore
- Parameters:
fNameSource
- a table name for an existing table, without thephantombot_
prefixfNameDest
- a new table name that does not yet exist, without thephantombot_
prefix
-
FileExists
Description copied from class:DataStore
Indicates if the given table already exists- Overrides:
FileExists
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefix- Returns:
true
if the table exists
-
FileExists
-
GetFileList
Description copied from class:DataStore
Returns a list of tables in the database.Only tables with the
phantombot_
prefix are returned. The prefix is removed- Overrides:
GetFileList
in classDataStore
- Returns:
- an array of table names
-
GetCategoryList
Description copied from class:DataStore
Returns a list of all values in thesection
column within the table- Overrides:
GetCategoryList
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefix- Returns:
- an array of sections
-
GetKeyList
Description copied from class:DataStore
Returns a list of all values in thevariable
column within the table and section- Overrides:
GetKeyList
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sections- Returns:
- an array of variables
-
GetKeyValueList
Description copied from class:DataStore
Returns a list of allvariable/value
pairs within the table and section- Overrides:
GetKeyValueList
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sections- Returns:
- an array of
KeyValue
pairs denoting the variables and values
-
GetKeysByOrder
public String[] GetKeysByOrder(String fName, String section, String order, String limit, String offset) Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, sorted naturally- Overrides:
GetKeysByOrder
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionsorder
- sort order. Valid values:"ASC"
(Ascending) or"DESC"
(Descending)limit
- the maximum number of results to return from this queryoffset
- the offset to start reading from- Returns:
- a sorted list of variables
-
GetKeysByNumberOrder
public String[] GetKeysByNumberOrder(String fName, String section, String order, String limit, String offset) Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, sorted naturally as integers- Overrides:
GetKeysByNumberOrder
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionsorder
- sort order. Valid values:"ASC"
(Ascending) or"DESC"
(Descending)limit
- the maximum number of results to return from this queryoffset
- the offset to start reading from- Returns:
- a sorted list of variables
-
GetKeysByOrderValue
public String[] GetKeysByOrderValue(String fName, String section, String order, String limit, String offset) Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, sorted naturally by thevalue
column- Overrides:
GetKeysByOrderValue
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionsorder
- sort order. Valid values:"ASC"
(Ascending) or"DESC"
(Descending)limit
- the maximum number of results to return from this queryoffset
- the offset to start reading from- Returns:
- a sorted list of variables
-
GetKeysByNumberOrderValue
public String[] GetKeysByNumberOrderValue(String fName, String section, String order, String limit, String offset) Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, sorted naturally by thevalue
column as integers- Overrides:
GetKeysByNumberOrderValue
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionsorder
- sort order. Valid values:"ASC"
(Ascending) or"DESC"
(Descending)limit
- the maximum number of results to return from this queryoffset
- the offset to start reading from- Returns:
- a sorted list of variables
-
GetKeysByLikeValues
Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, where the value of thevalue
column contains the search phrase- Overrides:
GetKeysByLikeValues
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionssearch
- the partial value of thevalue
column to match against- Returns:
- a list of variables
-
GetKeysByLikeKeys
Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, where the value of thevariable
column contains the search phrase- Overrides:
GetKeysByLikeKeys
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionssearch
- the partial value of thevariable
column to match against- Returns:
- a list of variables
-
GetKeysByLikeKeysOrder
public String[] GetKeysByLikeKeysOrder(String fName, String section, String search, String order, String limit, String offset) Description copied from class:DataStore
Returns a list of values in thevariable
column within the table and section, where the value of thevariable
column contains the search phrase, sorted naturally- Overrides:
GetKeysByLikeKeysOrder
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionssearch
- the partial value of thevariable
column to match againstorder
- sort order. Valid values:"ASC"
(Ascending) or"DESC"
(Descending)limit
- the maximum number of results to return from this queryoffset
- the offset to start reading from- Returns:
- a sorted list of variables
-
HasKey
Description copied from class:DataStore
Indicates if the given table contains a row matching the given section and key -
GetKeyByValue
Description copied from class:DataStore
Returns the value of thevariable
column for the given table, section, and value- Overrides:
GetKeyByValue
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionsvalue
- the value of thevalue
column- Returns:
- the variable;
null
if not found
-
GetString
Description copied from class:DataStore
Returns the value of thevalue
column for the given table, section, and key as a stringA return value of
null
may denote that the table/row is not found, or that the actual stored value is SQLNULL
. UseDataStore.HasKey(String, String, String)
to verify if the row exists -
SetBatchString
Description copied from class:DataStore
Performs a bulkDataStore.SetString(String, String, String, String)
operation, using available database features to do so more efficiently.The array index of the keys and value params are linked
- Overrides:
SetBatchString
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionskeys
- the values of thevariable
column to updatevalues
- the new values to set thevalue
column to
-
SetString
Description copied from class:DataStore
Sets the value of thevalue
column for the given table, section, and key as a string -
IncreaseBatchString
Description copied from class:DataStore
Increases the value of thevalue
column as an integer for all keys of the given table and section- Overrides:
IncreaseBatchString
in classDataStore
- Parameters:
fName
- a table name, without thephantombot_
prefixsection
- a section name.""
(empty string) for the default section;null
for all sectionskeys
- the values of thevariable
column to updatevalue
- the new value to increase thevalue
column by
-
query
Description copied from class:DataStore
Executes an SQL queryThe query is executed using a
PreparedStatement
with calls toPreparedStatement.setString(int, String)
For example:
executeSql("SELECT * FROM foo WHERE bar = ?", ["baz"])
The value
"baz"
is escaped to prevent SQL injection, then inserted in place of the?
This yields the final query of
SELECT * FROM foo WHERE bar = "baz"
You can use
?
as many times as necessary, but must provide the same number of elements in the replacements array for the replacement to workReplacements are performed in order from left to right
Exceptions from failed SQL queries are NOT returned or thrown, but are logged in the core-error log
- Overrides:
query
in classDataStore
- Parameters:
sql
- The query to executereplacements
- Replacements forPreparedStatement.setString(int, String)
- Returns:
- An List of data as strings representing the result set, if the query was a DQL statement; an empty list otherwise. The outer list represents rows; the inner array represents columns; the values of the inner list represent the value of the row-column pair at that index as a string
-