public abstract class AbstractDatabase extends Object implements Database
Database. This already contains all the
heavy lifting, the only thing that is still left is the actual database
connection. This is done by overriding getConnection() to return a
new connection to a database.| Constructor and Description |
|---|
AbstractDatabase() |
| Modifier and Type | Method and Description |
|---|---|
static Database |
fromDataSource(DataSource dataSource)
Creates a database from a
DataSource. |
protected abstract Connection |
getConnection()
Creates a new connection to the database.
|
<T> List<T> |
getMultiple(Query query,
ObjectCreator<T> objectCreator)
Returns multiple query results.
|
<T> T |
getSingle(Query query,
ObjectCreator<T> objectCreator)
Returns a single object from a database.
|
long |
insert(Query query)
Inserts an object into the database and returns the automatically
generated ID, if any.
|
void |
process(Query query,
ResultProcessor resultProcessor)
Processes the results of the given query with the given result processor.
|
protected abstract void |
returnConnection(Connection connection)
Returns the connection after it has been used.
|
int |
update(Query query)
Updates objects in the database.
|
public <T> T getSingle(Query query, ObjectCreator<T> objectCreator) throws DatabaseException
DatabasegetSingle in interface DatabaseT - The type of the objectquery - The query to executeobjectCreator - The object creatornull if the query did not
yield any resultsDatabaseException - if a database error occursDatabase.getSingle(net.pterodactylus.util.database.Query,
net.pterodactylus.util.database.ObjectCreator)public <T> List<T> getMultiple(Query query, ObjectCreator<T> objectCreator) throws DatabaseException
DatabasegetMultiple in interface DatabaseT - The type of the resultsquery - The query to executeobjectCreator - The object creatorDatabaseException - if a database error occursDatabase.getMultiple(net.pterodactylus.util.database.Query,
net.pterodactylus.util.database.ObjectCreator)public long insert(Query query) throws DatabaseException
Databaseinsert in interface Databasequery - The query to execute-1 if no ID was
generatedDatabaseException - if a database error occursDatabase.insert(net.pterodactylus.util.database.Query)public int update(Query query) throws DatabaseException
Databaseupdate in interface Databasequery - The query to executeDatabaseException - if a database error occursDatabase.update(net.pterodactylus.util.database.Query)public void process(Query query, ResultProcessor resultProcessor) throws DatabaseException
process in interface Databasequery - The query to executeresultProcessor - The result processor used to process the result setDatabaseException - if a database error occursDatabase.process(Query, ResultProcessor)public static Database fromDataSource(DataSource dataSource)
DataSource.dataSource - The data source to create a database fromprotected abstract Connection getConnection() throws SQLException
SQLException - if a database error occursprotected abstract void returnConnection(Connection connection)
connection - The connection to returnCopyright © 2026. All rights reserved.