Class QuerySvc

  • All Implemented Interfaces:
    QueryService

    @Singleton
    public class QuerySvc
    extends java.lang.Object
    implements QueryService
    • 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 interface QueryService
        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 interface QueryService
        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 interface QueryService
        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 interface QueryService
        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 interface QueryService
        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 interface QueryService
        Returns:
        Optinal of the server UUID, empty if server did not start properly.