Package com.djrapitops.plan.query
Class QuerySvc
- java.lang.Object
-
- com.djrapitops.plan.query.QuerySvc
-
- All Implemented Interfaces:
QueryService
@Singleton public class QuerySvc extends java.lang.Object implements QueryService
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.djrapitops.plan.query.QueryService
QueryService.Holder, QueryService.ThrowingConsumer<T>, QueryService.ThrowingFunction<T,R>, QueryService.VoidFunction
-
-
Constructor Summary
Constructors Constructor Description QuerySvc(PlanConfig config, DBSystem dbSystem, ServerInfo serverInfo, ErrorLogger errorLogger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dataCleared()
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.java.util.Optional<java.util.UUID>
getServerUUID()
Get the UUID of this server.void
playerRemoved(java.util.UUID playerUUID)
<T> T
query(java.lang.String sql, QueryService.ThrowingFunction<java.sql.PreparedStatement,T> performQuery)
Perform a query against Plan database.void
register()
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.
-
-
-
Constructor Detail
-
QuerySvc
@Inject public QuerySvc(PlanConfig config, DBSystem dbSystem, ServerInfo serverInfo, ErrorLogger errorLogger)
-
-
Method Detail
-
register
public void register()
-
getDBType
public java.lang.String getDBType()
Description copied from interface:QueryService
Get what kind of database is in use.- Specified by:
getDBType
in interfaceQueryService
- Returns:
- H2, SQLITE or MYSQL
-
query
public <T> T query(java.lang.String sql, QueryService.ThrowingFunction<java.sql.PreparedStatement,T> performQuery)
Description copied from interface:QueryService
Perform a query against Plan database.Blocks thread until query is complete.
- Specified by:
query
in interfaceQueryService
- 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
.
-
execute
public java.util.concurrent.Future<?> execute(java.lang.String sql, QueryService.ThrowingConsumer<java.sql.PreparedStatement> performStatement)
Description copied from interface:QueryService
Execute SQL against Plan database.Does not block thread, SQL is executed in a single transaction to the database.
Differs from
QueryService.query(String, ThrowingFunction)
in that no results are returned.- Specified by:
execute
in interfaceQueryService
- 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.
-
subscribeToPlayerRemoveEvent
public void subscribeToPlayerRemoveEvent(java.util.function.Consumer<java.util.UUID> eventListener)
Description copied from interface:QueryService
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 })
- Specified by:
subscribeToPlayerRemoveEvent
in interfaceQueryService
- Parameters:
eventListener
- Functional interface that is called on the event.
-
subscribeDataClearEvent
public void subscribeDataClearEvent(QueryService.VoidFunction eventListener)
Description copied from interface:QueryService
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 })
- Specified by:
subscribeDataClearEvent
in interfaceQueryService
- Parameters:
eventListener
- Functional interface that is called on the event.
-
playerRemoved
public void playerRemoved(java.util.UUID playerUUID)
-
dataCleared
public void dataCleared()
-
getServerUUID
public java.util.Optional<java.util.UUID> getServerUUID()
Description copied from interface:QueryService
Get the UUID of this server.- Specified by:
getServerUUID
in interfaceQueryService
- Returns:
- Optional of the server UUID, empty if server did not start properly.
-
getCommonQueries
public CommonQueries getCommonQueries()
Description copied from interface:QueryService
Perform some commonly wanted queries.- Specified by:
getCommonQueries
in interfaceQueryService
- Returns:
CommonQueries
implementation.
-
-