Class MapDBContext

java.lang.Object
org.telegram.abilitybots.api.db.MapDBContext
All Implemented Interfaces:
Closeable, AutoCloseable, DBContext

public class MapDBContext extends Object implements DBContext
An implementation of DBContext that relies on a DB.
Author:
Abbas Abou Daya
See Also:
  • Constructor Details

    • MapDBContext

      public MapDBContext(org.mapdb.DB db)
  • Method Details

    • onlineInstance

      public static DBContext onlineInstance(String name)
      This DB returned by this method does not trigger deletion on JVM shutdown.
      Parameters:
      name - name of the DB file
      Returns:
      an online instance of MapDBContext
    • offlineInstance

      public static DBContext offlineInstance(String name)
      This DB returned by this method gets deleted on JVM shutdown.
      Parameters:
      name - name of the DB file
      Returns:
      an offline instance of MapDBContext
    • getList

      public <T> List<T> getList(String name)
      Specified by:
      getList in interface DBContext
      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

      public <K, V> Map<K,V> getMap(String name)
      Specified by:
      getMap in interface DBContext
      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

      public <T> Set<T> getSet(String name)
      Specified by:
      getSet in interface DBContext
      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

      public <T> Var<T> getVar(String name)
      Specified by:
      getVar in interface DBContext
      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

      public String summary()
      Specified by:
      summary in interface DBContext
      Returns:
      a high-level summary of the database structures (Sets, Lists, Maps, ...) present.
    • backup

      public Object backup()
      Description copied from interface: DBContext
      Implementations of this method are free to return any object such as XML, JSON, etc...
      Specified by:
      backup in interface DBContext
      Returns:
      a backup of the DB
    • recover

      public boolean recover(Object backup)
      Description copied from interface: DBContext
      The object passed to this method need to conform to the implementation of the DBContext.backup() method.
      Specified by:
      recover in interface DBContext
      Parameters:
      backup - the backup of the database containing all the structures
      Returns:
      true if the database successfully recovered
    • info

      public String info(String name)
      Specified by:
      info in interface DBContext
      Parameters:
      name - the name of the data structure
      Returns:
      the high-level information of the structure
    • commit

      public void commit()
      Description copied from interface: DBContext
      Commits the database to its persistent layer. Implementations are free to not implement this method as it is not compulsory.
      Specified by:
      commit in interface DBContext
    • clear

      public void clear()
      Description copied from interface: DBContext
      Clears the data structures present in the database.

      This method does not delete the data-structure themselves, but leaves them empty.

      Specified by:
      clear in interface DBContext
    • contains

      public boolean contains(String name)
      Specified by:
      contains in interface DBContext
      Parameters:
      name - the name of the data structure
      Returns:
      true if this database contains the specified structure name
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable