Package org.nuiton.topia.framework
Class TopiaSQLQuery<O>
java.lang.Object
org.nuiton.topia.framework.TopiaSQLQuery<O>
- Type Parameters:
O- the type of result data
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidA hook to obtain the result set just after the query execute.protected voidfindMultipleResult(List<O> result, ResultSet set) Obtain a multi result given the result set and push in in the result list.Obtain a multiple results fro the builded sql query.protected voidfindSingleResult(List<O> result, ResultSet set) Obtain a single result given the result set and push in in the result list.Obtain a single result from the builded sql query.protected String[]getColumnNames(ResultSet set) Obtain the column names of a given result set using his metadata.protected longFrom a given result set, let's count his number of row.getRowAsMap(String[] columnNames, 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 PreparedStatementprepareQuery(Connection connection) Prepare the statement used to do the sql query.protected abstract OprepareResult(ResultSet set) given a result set, extract the data.
-
Constructor Details
-
TopiaSQLQuery
public TopiaSQLQuery()
-
-
Method Details
-
prepareQuery
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
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
Obtain a single result from the builded sql query.- Parameters:
tx- the transaction used to execute the query.- Returns:
- the single result or
nullif none found. - Throws:
TopiaException- for any pb
-
findMultipleResult
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
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
Obtain a single result given the result set and push in in the result list.- Parameters:
result- the result listset- the set of the executed sql query- Throws:
SQLException- if any pb- Since:
- 2.6.4
-
findMultipleResult
Obtain a multi result given the result set and push in in the result list.- Parameters:
result- the result listset- the set of the executed sql query- Throws:
SQLException- if any pb- Since:
- 2.6.4
-
getColumnNames
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
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
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 setset- the set to inspect- Returns:
- the map for the given row of the result set
- Throws:
SQLException- if any pb- Since:
- 2.6.4
-