public interface QueryService
Requires Capability QUERY_API
Modifier and Type | Interface and Description |
---|---|
static class |
QueryService.Holder |
static interface |
QueryService.ThrowingConsumer<T>
See https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
|
static interface |
QueryService.ThrowingFunction<T,R>
See https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
|
static interface |
QueryService.VoidFunction
See https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
|
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.Future<?> |
execute(java.lang.String sql,
QueryService.ThrowingConsumer<java.sql.PreparedStatement> performStatement)
Execute SQL against Plan database.
|
CommonQueries |
getCommonQueries()
Perform some commonly wanted queries.
|
java.lang.String |
getDBType()
Get what kind of database is in use.
|
static QueryService |
getInstance()
Obtain instance of QueryService.
|
java.util.Optional<java.util.UUID> |
getServerUUID()
Get the UUID of this server.
|
<T> T |
query(java.lang.String sql,
QueryService.ThrowingFunction<java.sql.PreparedStatement,T> performQuery)
Perform a query against Plan database.
|
void |
subscribeDataClearEvent(QueryService.VoidFunction eventListener)
Used for getting notified about removal of ALL data.
|
void |
subscribeToPlayerRemoveEvent(java.util.function.Consumer<java.util.UUID> eventListener)
Used for getting notified about removal of player data.
|
static QueryService getInstance()
java.lang.NoClassDefFoundError
- If Plan is not installed and this class can not be found or if older Plan version is installed.java.lang.IllegalStateException
- If Plan is installed, but not enabled.java.lang.String getDBType()
java.lang.IllegalStateException
- If database has not been initialized (Plugin failed to enable)<T> T query(java.lang.String sql, QueryService.ThrowingFunction<java.sql.PreparedStatement,T> performQuery) throws java.lang.IllegalStateException
Blocks thread until query is complete.
T
- Type of results.sql
- SQL String to execute, can contain parameterized queries (?
).performQuery
- set your parameters to the PreparedStatement and execute the query, return results.results
.java.lang.IllegalStateException
- If something goes wrong with the query. SQLException might be as cause.java.util.concurrent.Future<?> execute(java.lang.String sql, QueryService.ThrowingConsumer<java.sql.PreparedStatement> performStatement) throws java.lang.IllegalStateException
Does not block thread, SQL is executed in a single transaction to the database.
Differs from query(String, ThrowingFunction)
in that no results are returned.
sql
- SQL String to execute, can contain parameterized queries (?
).performStatement
- set your parameters to the PreparedStatement and execute the statement.java.lang.IllegalStateException
- If something goes wrong with the query. SQLException might be as cause.void subscribeToPlayerRemoveEvent(java.util.function.Consumer<java.util.UUID> eventListener)
SQL for removing this player's data should be executed when this occurs.
Example usage:
subscribeToPlayerRemoveEvent(playerUUID -> { do stuff })
eventListener
- Functional interface that is called on the event.void subscribeDataClearEvent(QueryService.VoidFunction eventListener)
SQL for removing all extra tables (and data) should be performed
Example usage:
subscribeDataClearEvent(() -> { do stuff })
eventListener
- Functional interface that is called on the event.java.util.Optional<java.util.UUID> getServerUUID()
CommonQueries getCommonQueries()
CommonQueries
implementation.java.lang.IllegalStateException
- If database has not been initialized (Plugin failed to enable)