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 java.lang.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 Summary

    Constructors 
    Constructor Description
    TopiaSQLQuery()  
  • Method Summary

    Modifier and Type Method Description
    protected void afterExecuteQuery​(java.sql.ResultSet set)
    A hook to obtain the result set just after the query execute.
    protected void findMultipleResult​(java.util.List<O> result, java.sql.ResultSet set)
    Obtain a multi result given the result set and push in in the result list.
    java.util.List<O> findMultipleResult​(TopiaContextImplementor tx)
    Obtain a multiple results fro the builded sql query.
    protected void findSingleResult​(java.util.List<O> result, java.sql.ResultSet set)
    Obtain a single result given the result set and push in in the result list.
    O findSingleResult​(TopiaContextImplementor tx)
    Obtain a single result from the builded sql query.
    protected java.lang.String[] getColumnNames​(java.sql.ResultSet set)
    Obtain the column names of a given result set using his metadata.
    protected long getNbRows​(java.sql.ResultSet set)
    From a given result set, let's count his number of row.
    protected java.util.Map<java.lang.String,​java.lang.Object> getRowAsMap​(java.lang.String[] columnNames, java.sql.ResultSet set)
    Given the column names of the result set, transform the row of the result set to a map with column name as key.
    protected abstract java.sql.PreparedStatement prepareQuery​(java.sql.Connection connection)
    Prepare the statement used to do the sql query.
    protected abstract O prepareResult​(java.sql.ResultSet set)
    given a result set, extract the data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • prepareQuery

      protected abstract java.sql.PreparedStatement prepareQuery​(java.sql.Connection connection) throws java.sql.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:
      java.sql.SQLException - if any problem
    • prepareResult

      protected abstract O prepareResult​(java.sql.ResultSet set) throws java.sql.SQLException
      given a result set, extract the data.
      Parameters:
      set - the result set
      Returns:
      the data extracted from the current set, or null
      Throws:
      java.sql.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 java.util.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​(java.sql.ResultSet set) throws java.sql.SQLException
      A hook to obtain the result set just after the query execute.
      Parameters:
      set - the result set just obtained
      Throws:
      java.sql.SQLException - if any prob
      Since:
      2.6.4
    • findSingleResult

      protected void findSingleResult​(java.util.List<O> result, java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - if any pb
      Since:
      2.6.4
    • findMultipleResult

      protected void findMultipleResult​(java.util.List<O> result, java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - if any pb
      Since:
      2.6.4
    • getColumnNames

      protected java.lang.String[] getColumnNames​(java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - if any pb
      Since:
      2.6.4
    • getNbRows

      protected long getNbRows​(java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - if any pb
      Since:
      2.6.4
    • getRowAsMap

      protected java.util.Map<java.lang.String,​java.lang.Object> getRowAsMap​(java.lang.String[] columnNames, java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - if any pb
      Since:
      2.6.4