Package org.telegram.abilitybots.api.db
Interface DBContext
-
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
MapDBContext
public interface DBContext extends Closeable
This interface represents the high-level methods exposed to the user when handling anUpdate. Example usage:Ability.builder().action(ctx -> {db.getSet(USERS); doSomething();})BaseAbilityBotcontains a handle on thedbthat the user can use inside his declared abilities.- Author:
- Abbas Abou Daya
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Objectbackup()Implementations of this method are free to return any object such as XML, JSON, etc...voidclear()Clears the data structures present in the database.voidcommit()Commits the database to its persistent layer.booleancontains(String name)<T> List<T>getList(String name)<K,V>
Map<K,V>getMap(String name)<T> Set<T>getSet(String name)<T> Var<T>getVar(String name)Stringinfo(String name)booleanrecover(Object backup)The object passed to this method need to conform to the implementation of thebackup()method.Stringsummary()
-
-
-
Method Detail
-
getList
<T> List<T> getList(String name)
- Type Parameters:
T- the type that the List holds- Parameters:
name- the unique name of theList- Returns:
- the List with the specified name
-
getMap
<K,V> Map<K,V> getMap(String name)
- Type Parameters:
K- the type of the Map keysV- the type of the Map values- Parameters:
name- the unique name of theMap- Returns:
- the Map with the specified name
-
getSet
<T> Set<T> getSet(String name)
- Type Parameters:
T- the type that the Set holds- Parameters:
name- the unique name of theSet- Returns:
- the Set with the specified name
-
getVar
<T> Var<T> getVar(String name)
- Type Parameters:
T- the type that the variable holds- Parameters:
name- the unique name of theVar- Returns:
- the variable with the specified name
-
summary
String summary()
- Returns:
- a high-level summary of the database structures (Sets, Lists, Maps, ...) present.
-
backup
Object backup()
Implementations of this method are free to return any object such as XML, JSON, etc...- Returns:
- a backup of the DB
-
recover
boolean recover(Object backup)
The object passed to this method need to conform to the implementation of thebackup()method.- Parameters:
backup- the backup of the database containing all the structures- Returns:
- true if the database successfully recovered
-
info
String info(String name)
- Parameters:
name- the name of the data structure- Returns:
- the high-level information of the structure
-
commit
void commit()
Commits the database to its persistent layer. Implementations are free to not implement this method as it is not compulsory.
-
clear
void clear()
Clears the data structures present in the database.This method does not delete the data-structure themselves, but leaves them empty.
-
contains
boolean contains(String name)
- Parameters:
name- the name of the data structure- Returns:
- true if this database contains the specified structure name
-
-