Package com.djrapitops.plan.query
Interface QueryService
public interface QueryService
Service for Query API.
Requires Capability QUERY_API
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
static interface
static interface
static interface
-
Method Summary
Modifier and TypeMethodDescriptionFuture
<?> execute
(String sql, QueryService.ThrowingConsumer<PreparedStatement> performStatement) Execute SQL against Plan database.Perform some commonly wanted queries.Get what kind of database is in use.static QueryService
Obtain instance of QueryService.Get the UUID of this server.<T> T
query
(String sql, QueryService.ThrowingFunction<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
(Consumer<UUID> eventListener) Used for getting notified about removal of player data.
-
Method Details
-
getInstance
Obtain instance of QueryService.- Returns:
- QueryService implementation.
- Throws:
NoClassDefFoundError
- If Plan is not installed and this class can not be found or if older Plan version is installed.IllegalStateException
- If Plan is installed, but not enabled.
-
getDBType
String getDBType()Get what kind of database is in use.- Returns:
- SQLITE or MYSQL
- Throws:
IllegalStateException
- If database has not been initialized (Plugin failed to enable)
-
query
<T> T query(String sql, QueryService.ThrowingFunction<PreparedStatement, T> performQuery) throws IllegalStateExceptionPerform a query against Plan database.Blocks thread until query is complete.
- Type Parameters:
T
- Type of results.- Parameters:
sql
- SQL String to execute, can contain parameterized queries (?
).performQuery
- set your parameters to the PreparedStatement and execute the query, return results.- Returns:
- The object returned by
results
. - Throws:
IllegalStateException
- If something goes wrong with the query. SQLException might be as cause.
-
execute
Future<?> execute(String sql, QueryService.ThrowingConsumer<PreparedStatement> performStatement) throws IllegalStateException Execute SQL against Plan database.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.- Parameters:
sql
- SQL String to execute, can contain parameterized queries (?
).performStatement
- set your parameters to the PreparedStatement and execute the statement.- Returns:
- A Future that tells when the transaction has completed. Blocks thread if Future#get is called.
- Throws:
IllegalStateException
- If something goes wrong with the query. SQLException might be as cause.
-
subscribeToPlayerRemoveEvent
Used for getting notified about removal of player data.SQL for removing this player's data should be executed when this occurs.
Example usage:
subscribeToPlayerRemoveEvent(playerUUID -> { do stuff })
- Parameters:
eventListener
- Functional interface that is called on the event.
-
subscribeDataClearEvent
Used for getting notified about removal of ALL data.SQL for removing all extra tables (and data) should be performed
Example usage:
subscribeDataClearEvent(() -> { do stuff })
- Parameters:
eventListener
- Functional interface that is called on the event.
-
getServerUUID
Get the UUID of this server.- Returns:
- Optional of the server UUID, empty if server did not start properly.
-
getCommonQueries
CommonQueries getCommonQueries()Perform some commonly wanted queries.- Returns:
CommonQueries
implementation.- Throws:
IllegalStateException
- If database has not been initialized (Plugin failed to enable)
-