Package io.manebot.database
Interface Database
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Subinterfaces:
PluginDatabase
public interface Database extends java.lang.AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Database.ModelConstructor
Database model constructor.
-
Method Summary
Modifier and Type Method Description <T> SearchHandler.Builder<T>
createSearchHandler(java.lang.Class<T> entityClass)
Creates a search, which accepts certain arguments to construct results in queryable commands.default <T> SearchHandler<T>
createSearchHandler(java.lang.Class<T> entityClass, java.util.function.Function<SearchHandler.Builder<T>,SearchHandler<T>> function)
Creates a search, which accepts certain arguments to construct results in queryable commands.default <E extends java.lang.Exception>
voidexecute(ThrowingConsumer<javax.persistence.EntityManager,E> function)
Executes a function on the database, using a session and returning the session to the pool fairly.default <T,E extends java.lang.Exception>
Texecute(ThrowingFunction<javax.persistence.EntityManager,T,E> function)
Executes a function on the database, using a session and returning the session to the pool fairly.default <E extends java.lang.Exception>
voidexecuteTransaction(ThrowingConsumer<javax.persistence.EntityManager,E> function)
Executes a function on the database, using a transactional session and returning the session to the pool fairly, automatically rolling back on failure.default <T,E extends java.lang.Exception>
TexecuteTransaction(ThrowingFunction<javax.persistence.EntityManager,T,E> function)
Executes a function on the database, using a transactional session and returning the session to the pool fairly, automatically rolling back on failure.java.lang.ClassLoader
getClassLoader()
Gets the classloader used by this database to load entity model classes associated with it.DatabaseManager
getDatabaseManager()
Gets the database manager associated with creating this database.java.util.Collection<Database>
getDependentDatabases()
Gets an immutable collection of this database's dependent databases.java.util.Collection<java.lang.Class<?>>
getEntities()
Gets a list of this database's own registered entities.java.lang.String
getName()
Gets the database's name.boolean
isClosed()
Finds if this database is closed.javax.persistence.EntityManager
openSession()
Opens a session to the database.
-
-
-
Method Detail
-
getClassLoader
java.lang.ClassLoader getClassLoader()
Gets the classloader used by this database to load entity model classes associated with it.- Returns:
- ClassLoader instance.
-
getDatabaseManager
DatabaseManager getDatabaseManager()
Gets the database manager associated with creating this database.- Returns:
- DatabaseManager instance.
-
getName
java.lang.String getName()
Gets the database's name.- Returns:
- Database name.
-
getEntities
java.util.Collection<java.lang.Class<?>> getEntities()
Gets a list of this database's own registered entities.- Returns:
- Collection of Class objects.
-
getDependentDatabases
java.util.Collection<Database> getDependentDatabases()
Gets an immutable collection of this database's dependent databases.- Returns:
- Database collection.
-
isClosed
boolean isClosed()
Finds if this database is closed. A closed database does not hold open connections to a server.- Returns:
- true if the database is closed, false otherwise.
-
execute
default <T,E extends java.lang.Exception> T execute(ThrowingFunction<javax.persistence.EntityManager,T,E> function) throws E extends java.lang.Exception
Executes a function on the database, using a session and returning the session to the pool fairly.- Type Parameters:
T
- Return type of the function.- Parameters:
function
- Function to execute.- Returns:
- User-defined result.
- Throws:
E
- user-defined exceptionE extends java.lang.Exception
-
execute
default <E extends java.lang.Exception> void execute(ThrowingConsumer<javax.persistence.EntityManager,E> function) throws E extends java.lang.Exception
Executes a function on the database, using a session and returning the session to the pool fairly.- Parameters:
function
- Function to execute.- Throws:
E
- user-defined exceptionE extends java.lang.Exception
-
executeTransaction
default <E extends java.lang.Exception> void executeTransaction(ThrowingConsumer<javax.persistence.EntityManager,E> function) throws java.sql.SQLException
Executes a function on the database, using a transactional session and returning the session to the pool fairly, automatically rolling back on failure.- Parameters:
function
- Function to execute.- Throws:
java.sql.SQLException
- failure to execute function or transactional behavior.
-
executeTransaction
default <T,E extends java.lang.Exception> T executeTransaction(ThrowingFunction<javax.persistence.EntityManager,T,E> function) throws java.sql.SQLException
Executes a function on the database, using a transactional session and returning the session to the pool fairly, automatically rolling back on failure.- Parameters:
function
- Function to execute.- Returns:
- User-defined result.
- Throws:
java.sql.SQLException
- failure to execute function or transactional behavior.
-
openSession
javax.persistence.EntityManager openSession()
Opens a session to the database.- Returns:
- Session instance.
-
createSearchHandler
<T> SearchHandler.Builder<T> createSearchHandler(java.lang.Class<T> entityClass) throws java.lang.IllegalArgumentException
Creates a search, which accepts certain arguments to construct results in queryable commands.- Type Parameters:
T
- search entity type- Parameters:
entityClass
- Search entity class.- Returns:
- Search builder instance.
- Throws:
java.lang.IllegalArgumentException
- if the entity is not registered to this database.
-
createSearchHandler
default <T> SearchHandler<T> createSearchHandler(java.lang.Class<T> entityClass, java.util.function.Function<SearchHandler.Builder<T>,SearchHandler<T>> function) throws java.lang.IllegalArgumentException
Creates a search, which accepts certain arguments to construct results in queryable commands.- Type Parameters:
T
- search entity type- Parameters:
entityClass
- Search entity class.function
- Search builder function.- Returns:
- Search instance.
- Throws:
java.lang.IllegalArgumentException
- if the entity is not registered to this database.
-
-