Class TopiaSQLQuery<O>

java.lang.Object
org.nuiton.topia.framework.TopiaSQLQuery<O>
Type Parameters:
O - the type of result data

public abstract class TopiaSQLQuery<O> extends Object
An executor of sql query which permits to obtain a single result via the method findSingleResult(TopiaContextImplementor) or a multiple result with method findMultipleResult(TopiaContextImplementor).
Since:
2.5
  • Constructor Details

    • TopiaSQLQuery

      public TopiaSQLQuery()
  • Method Details

    • prepareQuery

      protected abstract PreparedStatement prepareQuery(Connection connection) throws SQLException
      Prepare the statement used to do the sql query.
      Parameters:
      connection - jdbc connection to use
      Returns:
      the statement containing the query to execute
      Throws:
      SQLException - if any problem
    • prepareResult

      protected abstract O prepareResult(ResultSet set) throws SQLException
      given a result set, extract the data.
      Parameters:
      set - the result set
      Returns:
      the data extracted from the current set, or null
      Throws:
      SQLException - if any prob
    • findSingleResult

      public O findSingleResult(TopiaContextImplementor tx) throws TopiaException
      Obtain a single result from the builded sql query.
      Parameters:
      tx - the transaction used to execute the query.
      Returns:
      the single result or null if none found.
      Throws:
      TopiaException - for any pb
    • findMultipleResult

      public List<O> findMultipleResult(TopiaContextImplementor tx) throws TopiaException
      Obtain a multiple results fro the builded sql query.
      Parameters:
      tx - the transaction used to execute the query.
      Returns:
      the list of results (the list is empty if non result is found).
      Throws:
      TopiaException - for any pb
    • afterExecuteQuery

      protected void afterExecuteQuery(ResultSet set) throws SQLException
      A hook to obtain the result set just after the query execute.
      Parameters:
      set - the result set just obtained
      Throws:
      SQLException - if any prob
      Since:
      2.6.4
    • findSingleResult

      protected void findSingleResult(List<O> result, ResultSet set) throws SQLException
      Obtain a single result given the result set and push in in the result list.
      Parameters:
      result - the result list
      set - the set of the executed sql query
      Throws:
      SQLException - if any pb
      Since:
      2.6.4
    • findMultipleResult

      protected void findMultipleResult(List<O> result, ResultSet set) throws SQLException
      Obtain a multi result given the result set and push in in the result list.
      Parameters:
      result - the result list
      set - the set of the executed sql query
      Throws:
      SQLException - if any pb
      Since:
      2.6.4
    • getColumnNames

      protected String[] getColumnNames(ResultSet set) throws SQLException
      Obtain the column names of a given result set using his metadata.
      Parameters:
      set - the result set to inspect
      Returns:
      the column names of the result set
      Throws:
      SQLException - if any pb
      Since:
      2.6.4
    • getNbRows

      protected long getNbRows(ResultSet set) throws SQLException
      From a given result set, let's count his number of row. Note: the result set must be scrollable to go back to before first row.
      Parameters:
      set - the result set to inspect
      Returns:
      the number of row of the given result set
      Throws:
      SQLException - if any pb
      Since:
      2.6.4
    • getRowAsMap

      protected Map<String,Object> getRowAsMap(String[] columnNames, ResultSet set) throws SQLException
      Given the column names of the result set, transform the row of the result set to a map with column name as key.
      Parameters:
      columnNames - column names of the result set
      set - the set to inspect
      Returns:
      the map for the given row of the result set
      Throws:
      SQLException - if any pb
      Since:
      2.6.4