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 an Update. Example usage:

    Ability.builder().action(ctx -> {db.getSet(USERS); doSomething();})

    BaseAbilityBot contains a handle on the db that the user can use inside his declared abilities.
    Author:
    Abbas Abou Daya
    • Method Detail

      • getList

        <T> List<T> getList​(String name)
        Type Parameters:
        T - the type that the List holds
        Parameters:
        name - the unique name of the List
        Returns:
        the List with the specified name
      • getMap

        <K,​V> Map<K,​V> getMap​(String name)
        Type Parameters:
        K - the type of the Map keys
        V - the type of the Map values
        Parameters:
        name - the unique name of the Map
        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 the Set
        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 the Var
        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 the backup() 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