}
else
{
if (callableStatementUsed)
{
final CallableStatement pstmt = getConnection(parameters).prepareCall
(translatedQuery, getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY);
if (isCallableStatementQuery(translatedQuery))
{
pstmt.registerOutParameter(1, Types.OTHER);
parametrize(parameters, preparedParameterNames, pstmt, false, 1);
}
else
{
parametrize(parameters, preparedParameterNames, pstmt, false, 0);
}
statement = pstmt;
}
else
{
final PreparedStatement pstmt = getConnection(parameters).prepareStatement
(translatedQuery, getBestResultSetType(parameters), ResultSet.CONCUR_READ_ONLY);
parametrize(parameters, preparedParameterNames, pstmt, isExpandArrays(), 0);
statement = pstmt;
}
}
final Object queryLimit = parameters.get(DataFactory.QUERY_LIMIT);
try
{
if (queryLimit instanceof Number)
{
final Number i = (Number) queryLimit;
final int max = i.intValue();
if (max > 0)
{
statement.setMaxRows(max);
}
}
}
catch (SQLException sqle)
{
// this fails for MySQL as their driver is buggy. We will not add workarounds here, as
// all drivers are buggy and this is a race we cannot win. Put pressure on the driver
// manufacturer instead.
logger.warn("Driver indicated error: Failed to set query-limit: " + queryLimit, sqle);
}
final Object queryTimeout = parameters.get(DataFactory.QUERY_TIMEOUT);
try
{
if (queryTimeout instanceof Number)
{
final Number i = (Number) queryTimeout;
final int seconds = i.intValue();
if (seconds > 0)
{
statement.setQueryTimeout(seconds);
}
}
}
catch (SQLException sqle)
{
logger.warn("Driver indicated error: Failed to set query-timeout: " + queryTimeout, sqle);
}
// Track the currently running statement - just in case someone needs to cancel it
final ResultSet res;
try
{
currentRunningStatement = statement;
if (preparedParameterNames.length == 0)
{
res = statement.executeQuery(translatedQuery);
}
else
{
final PreparedStatement pstmt = (PreparedStatement) statement;
res = pstmt.executeQuery();
}
}
finally
{
currentRunningStatement = null;