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
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 voidafterExecuteQuery(java.sql.ResultSet set)A hook to obtain the result set just after the query execute.protected voidfindMultipleResult(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 voidfindSingleResult(java.util.List<O> result, java.sql.ResultSet set)Obtain a single result given the result set and push in in the result list.OfindSingleResult(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 longgetNbRows(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.PreparedStatementprepareQuery(java.sql.Connection connection)Prepare the statement used to do the sql query.protected abstract OprepareResult(java.sql.ResultSet set)given a result set, extract the data.
-
Constructor Details
-
TopiaSQLQuery
public TopiaSQLQuery()
-
-
Method Details
-
prepareQuery
protected abstract java.sql.PreparedStatement prepareQuery(java.sql.Connection connection) throws java.sql.SQLExceptionPrepare 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
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
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
protected void afterExecuteQuery(java.sql.ResultSet set) throws java.sql.SQLExceptionA 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.SQLExceptionObtain 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:
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.SQLExceptionObtain 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:
java.sql.SQLException- if any pb- Since:
- 2.6.4
-
getColumnNames
protected java.lang.String[] getColumnNames(java.sql.ResultSet set) throws java.sql.SQLExceptionObtain 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.SQLExceptionFrom 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.SQLExceptionGiven 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:
java.sql.SQLException- if any pb- Since:
- 2.6.4
-