Interface Database
- All Known Implementing Classes:
AbstractDatabase
,MySQLDB
,SQLDB
,SQLiteDB
public interface Database
Interface for interacting with a Plan SQL database.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
Possible State changes: CLOSED to PATCHING (Database init), PATCHING to OPEN (Database initialized), OPEN to CLOSING (Database closing), CLOSING to CLOSED (Database closed), PATCHING to CLOSED (Database closed prematurely) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
executeTransaction
(Transaction transaction) Execute an SQL Transaction.default Sql
getSql()
getState()
getType()
Used to get theDBType
of the Databasevoid
init()
Initializes the Database.<T> T
Execute an SQL Query statement to get a result.default <C extends Collection<T>,
T>
CqueryCollection
(String sql, RowExtractor<T> rowExtractor, Supplier<C> collectionConstructor, Object... parameters) default <T> List<T>
queryList
(String sql, RowExtractor<T> rowExtractor, Object... parameters) default <K,
V> Map<K, V> queryMap
(String sql, MapRowExtractor<K, V> rowExtractor, Object... parameters) default <M extends Map<K,
V>, K, V>
MqueryMap
(String sql, MapRowExtractor<K, V> rowExtractor, Supplier<M> mapConstructor, Object... parameters) default <T> Optional<T>
queryOptional
(String sql, RowExtractor<T> rowExtractor, Object... parameters) default <T> Set<T>
querySet
(String sql, RowExtractor<T> rowExtractor, Object... parameters)
-
Method Details
-
init
void init()Initializes the Database.Queries can be performed after this request has completed all required transactions for the database operations.
- Throws:
DBInitException
- if Database fails to initiate.
-
close
void close() -
query
Execute an SQL Query statement to get a result.This method should only be called from an asynchronous thread.
- Type Parameters:
T
- Type of the object to be returned.- Parameters:
query
- QueryStatement to execute.- Returns:
- Result of the query.
-
queryOptional
default <T> Optional<T> queryOptional(String sql, RowExtractor<T> rowExtractor, Object... parameters) -
queryList
-
querySet
-
queryCollection
default <C extends Collection<T>,T> C queryCollection(String sql, RowExtractor<T> rowExtractor, Supplier<C> collectionConstructor, Object... parameters) -
queryMap
default <K,V> Map<K,V> queryMap(String sql, MapRowExtractor<K, V> rowExtractor, Object... parameters) -
queryMap
default <M extends Map<K,V>, M queryMapK, V> (String sql, MapRowExtractor<K, V> rowExtractor, Supplier<M> mapConstructor, Object... parameters) -
executeTransaction
Execute an SQL Transaction.- Parameters:
transaction
- Transaction to execute.- Returns:
- Future that is finished when the transaction has been executed.
-
getType
DBType getType()Used to get theDBType
of the Database- Returns:
- the
DBType
- See Also:
-
getSql
-
getState
Database.State getState()
-