Interface QueryService


  • public interface QueryService
    Service for Query API.

    Requires Capability QUERY_API

    • Method Detail

      • getInstance

        static QueryService getInstance()
        Obtain instance of QueryService.
        Returns:
        QueryService implementation.
        Throws:
        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.
      • getDBType

        java.lang.String getDBType()
        Get what kind of database is in use.
        Returns:
        H2, SQLITE or MYSQL
        Throws:
        java.lang.IllegalStateException - If database has not been initialized (Plugin failed to enable)
      • query

        <T> T query​(java.lang.String sql,
                    QueryService.ThrowingFunction<java.sql.PreparedStatement,​T> performQuery)
             throws java.lang.IllegalStateException
        Perform 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:
        java.lang.IllegalStateException - If something goes wrong with the query. SQLException might be as cause.
      • execute

        java.util.concurrent.Future<?> execute​(java.lang.String sql,
                                               QueryService.ThrowingConsumer<java.sql.PreparedStatement> performStatement)
                                        throws java.lang.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:
        java.lang.IllegalStateException - If something goes wrong with the query. SQLException might be as cause.
      • subscribeToPlayerRemoveEvent

        void subscribeToPlayerRemoveEvent​(java.util.function.Consumer<java.util.UUID> eventListener)
        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

        void subscribeDataClearEvent​(QueryService.VoidFunction eventListener)
        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

        java.util.Optional<java.util.UUID> 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:
        java.lang.IllegalStateException - If database has not been initialized (Plugin failed to enable)