All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.telegram.telegrambots.abilitybots.api.db.DBContext Maven / Gradle / Ivy

There is a newer version: 7.10.0
Show newest version
package org.telegram.telegrambots.abilitybots.api.db;

import org.telegram.telegrambots.abilitybots.api.bot.BaseAbilityBot;
import org.telegram.telegrambots.meta.api.objects.Update;

import java.io.Closeable;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * This interface represents the high-level methods exposed to the user when handling an {@link Update}.
 * Example usage:
 * 

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

* {@link BaseAbilityBot} contains a handle on the db that the user can use inside his declared abilities. * * @author Abbas Abou Daya */ public interface DBContext extends Closeable { /** * @param name the unique name of the {@link List} * @param the type that the List holds * @return the List with the specified name */ List getList(String name); /** * @param name the unique name of the {@link Map} * @param the type of the Map keys * @param the type of the Map values * @return the Map with the specified name */ Map getMap(String name); /** * @param name the unique name of the {@link Set} * @param the type that the Set holds * @return the Set with the specified name */ Set getSet(String name); /** * @param name the unique name of the {@link Var} * @param the type that the variable holds * @return the variable with the specified name */ Var getVar(String name); /** * @return a high-level summary of the database structures (Sets, Lists, Maps, ...) present. */ String summary(); /** * Implementations of this method are free to return any object such as XML, JSON, etc... * * @return a backup of the DB */ Object backup(); /** * The object passed to this method need to conform to the implementation of the {@link DBContext#backup()} method. * * @param backup the backup of the database containing all the structures * @return true if the database successfully recovered */ boolean recover(Object backup); /** * @param name the name of the data structure * @return the high-level information of the structure */ String info(String name); /** * Commits the database to its persistent layer. Implementations are free to not implement this method as it is not compulsory. */ void commit(); /** * Clears the data structures present in the database. *

* This method does not delete the data-structure themselves, but leaves them empty. */ void clear(); /** * @param name the name of the data structure * @return true if this database contains the specified structure name */ boolean contains(String name); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy