public synchronized TableModel queryData(final String query, final DataRow parameters)
throws ReportDataFactoryException
{
try
{
final Query pstmt = getSession().createQuery(query);
final String[] params = pstmt.getNamedParameters();
for (int i = 0; i < params.length; i++)
{
final String param = params[i];
final Object pvalue = parameters.get(param);
if (pvalue == null)
{
// this should work, but some driver are known to die here.
// they should be fed with setNull(..) instead; something
// we cant do as JDK1.2's JDBC does not define it.
pstmt.setParameter(param, null);
}
else
{
pstmt.setParameter(param, pvalue);
}
}
final Object queryLimit = parameters.get(DataFactory.QUERY_LIMIT);
if (queryLimit instanceof Number)
{
final Number i = (Number) queryLimit;
if (i.intValue() >= 0)
{
pstmt.setMaxResults(i.intValue());
}
}
final Object queryTimeout = parameters.get(DataFactory.QUERY_TIMEOUT);
if (queryTimeout instanceof Number)
{
final Number i = (Number) queryLimit;
if (i.intValue() >= 0)
{
pstmt.setTimeout(i.intValue());
}
}
final ScrollableResults res = pstmt.scroll(ScrollMode.FORWARD_ONLY);
return generateDefaultTableModel(res, pstmt.getReturnAliases());
}
catch (Exception e)
{
throw new ReportDataFactoryException("Failed at query: " + query, e);
}