Class Query<ResultType>

java.lang.Object
com.github.tadukoo.database.mysql.transaction.query.Query<ResultType>
Type Parameters:
ResultType - The type of result returned from the query
All Implemented Interfaces:
SQLTransaction<ResultType>

public abstract class Query<ResultType> extends Object implements SQLTransaction<ResultType>
Represents a single statement query in MySQL, to be executed as a transaction.
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Constructor Details

    • Query

      public Query()
  • Method Details

    • getSQL

      public abstract String getSQL()
      Returns:
      The SQL statement to be used for the query
    • execute

      public ResultType execute(Connection conn, com.github.tadukoo.util.logger.EasyLogger logger) throws SQLException
      Executes the transaction using the given connection, and will log messages as needed to the given EasyLogger
      Specified by:
      execute in interface SQLTransaction<ResultType>
      Parameters:
      conn - The Connection to use for the transaction
      logger - The EasyLogger to use for logging messages as needed
      Returns:
      The result of the transaction
      Throws:
      SQLException - If anything goes wrong
    • convertFromResultSet

      public abstract ResultType convertFromResultSet(ResultSet resultSet) throws SQLException
      Converts the given ResultSet to the proper Query to be returned from the query.
      Parameters:
      resultSet - The ResultSet to be converted
      Returns:
      The result converted from the ResultSet
      Throws:
      SQLException - If something goes wrong during conversion
    • createQuery

      public static <ResultType> Query<ResultType> createQuery(String name, String sql, com.github.tadukoo.util.functional.function.ThrowingFunction<ResultSet,ResultType,SQLException> convertFromResultSet)
      Creates a new Query using the given transaction name, MySQL query statement, and ResultSet conversion function.
      Type Parameters:
      ResultType - The type of result to be returned from the Query
      Parameters:
      name - The MySQL transaction name
      sql - The MySQL query statement to be executed
      convertFromResultSet - A method to convert the ResultSet to the proper Query
      Returns:
      A Query object