mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Add overload of executeStatement, that takes the SQL string, for including in an explicit LOG.warn upon SQLException. Add similar catch(SQLException) { LOG; throw } blocks to other execute methods.
This commit is contained in:
@ -116,7 +116,7 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
|
|||||||
actionTimeoutHelper = new ActionTimeoutHelper(aggregateInput.getTimeoutSeconds(), TimeUnit.SECONDS, new StatementTimeoutCanceller(statement, sql));
|
actionTimeoutHelper = new ActionTimeoutHelper(aggregateInput.getTimeoutSeconds(), TimeUnit.SECONDS, new StatementTimeoutCanceller(statement, sql));
|
||||||
actionTimeoutHelper.start();
|
actionTimeoutHelper.start();
|
||||||
|
|
||||||
QueryManager.executeStatement(statement, ((ResultSet resultSet) ->
|
QueryManager.executeStatement(statement, sql, ((ResultSet resultSet) ->
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// once we've started getting results, go ahead and cancel the timeout //
|
// once we've started getting results, go ahead and cancel the timeout //
|
||||||
|
@ -96,7 +96,7 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
|||||||
actionTimeoutHelper = new ActionTimeoutHelper(countInput.getTimeoutSeconds(), TimeUnit.SECONDS, new StatementTimeoutCanceller(statement, sql));
|
actionTimeoutHelper = new ActionTimeoutHelper(countInput.getTimeoutSeconds(), TimeUnit.SECONDS, new StatementTimeoutCanceller(statement, sql));
|
||||||
actionTimeoutHelper.start();
|
actionTimeoutHelper.start();
|
||||||
|
|
||||||
QueryManager.executeStatement(statement, ((ResultSet resultSet) ->
|
QueryManager.executeStatement(statement, sql, ((ResultSet resultSet) ->
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// once we've started getting results, go ahead and cancel the timeout //
|
// once we've started getting results, go ahead and cancel the timeout //
|
||||||
|
@ -170,7 +170,7 @@ public class RDBMSQueryAction extends AbstractRDBMSAction implements QueryInterf
|
|||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
QueryOutput queryOutput = new QueryOutput(queryInput);
|
QueryOutput queryOutput = new QueryOutput(queryInput);
|
||||||
|
|
||||||
QueryManager.executeStatement(statement, ((ResultSet resultSet) ->
|
QueryManager.executeStatement(statement, sql, ((ResultSet resultSet) ->
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// once we've started getting results, go ahead and cancel the timeout //
|
// once we've started getting results, go ahead and cancel the timeout //
|
||||||
|
@ -32,6 +32,7 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.sql.Time;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -56,6 +57,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.PossibleValu
|
|||||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
import org.apache.commons.lang.NotImplementedException;
|
import org.apache.commons.lang.NotImplementedException;
|
||||||
|
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -121,6 +123,17 @@ public class QueryManager
|
|||||||
** customized settings/optimizations).
|
** customized settings/optimizations).
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public static void executeStatement(PreparedStatement statement, ResultSetProcessor processor, Object... params) throws SQLException, QException
|
public static void executeStatement(PreparedStatement statement, ResultSetProcessor processor, Object... params) throws SQLException, QException
|
||||||
|
{
|
||||||
|
executeStatement(statement, null, processor, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Let the caller provide their own prepared statement (e.g., possibly with some
|
||||||
|
** customized settings/optimizations).
|
||||||
|
*******************************************************************************/
|
||||||
|
public static void executeStatement(PreparedStatement statement, CharSequence sql, ResultSetProcessor processor, Object... params) throws SQLException, QException
|
||||||
{
|
{
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
@ -136,6 +149,14 @@ public class QueryManager
|
|||||||
processor.processResultSet(resultSet);
|
processor.processResultSet(resultSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(SQLException e)
|
||||||
|
{
|
||||||
|
if(sql != null)
|
||||||
|
{
|
||||||
|
LOG.warn("SQLException", e, logPair("sql", sql));
|
||||||
|
}
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if(resultSet != null)
|
if(resultSet != null)
|
||||||
@ -372,10 +393,17 @@ public class QueryManager
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public static PreparedStatement executeUpdate(Connection connection, String sql, Object... params) throws SQLException
|
public static PreparedStatement executeUpdate(Connection connection, String sql, Object... params) throws SQLException
|
||||||
{
|
{
|
||||||
PreparedStatement statement = prepareStatementAndBindParams(connection, sql, params);
|
try(PreparedStatement statement = prepareStatementAndBindParams(connection, sql, params))
|
||||||
incrementStatistic(STAT_QUERIES_RAN);
|
{
|
||||||
statement.executeUpdate();
|
incrementStatistic(STAT_QUERIES_RAN);
|
||||||
return (statement);
|
statement.executeUpdate();
|
||||||
|
return (statement);
|
||||||
|
}
|
||||||
|
catch(SQLException e)
|
||||||
|
{
|
||||||
|
LOG.warn("SQLException", e, logPair("sql", sql));
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -385,10 +413,17 @@ public class QueryManager
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public static PreparedStatement executeUpdate(Connection connection, String sql, List<Object> params) throws SQLException
|
public static PreparedStatement executeUpdate(Connection connection, String sql, List<Object> params) throws SQLException
|
||||||
{
|
{
|
||||||
PreparedStatement statement = prepareStatementAndBindParams(connection, sql, params);
|
try(PreparedStatement statement = prepareStatementAndBindParams(connection, sql, params))
|
||||||
incrementStatistic(STAT_QUERIES_RAN);
|
{
|
||||||
statement.executeUpdate();
|
incrementStatistic(STAT_QUERIES_RAN);
|
||||||
return (statement);
|
statement.executeUpdate();
|
||||||
|
return (statement);
|
||||||
|
}
|
||||||
|
catch(SQLException e)
|
||||||
|
{
|
||||||
|
LOG.warn("SQLException", e, logPair("sql", sql));
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -436,6 +471,11 @@ public class QueryManager
|
|||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
return (statement.getUpdateCount());
|
return (statement.getUpdateCount());
|
||||||
}
|
}
|
||||||
|
catch(SQLException e)
|
||||||
|
{
|
||||||
|
LOG.warn("SQLException", e, logPair("sql", sql));
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -488,19 +528,24 @@ public class QueryManager
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public static List<Integer> executeInsertForGeneratedIds(Connection connection, String sql, List<Object> params) throws SQLException
|
public static List<Integer> executeInsertForGeneratedIds(Connection connection, String sql, List<Object> params) throws SQLException
|
||||||
{
|
{
|
||||||
List<Integer> rs = new ArrayList<>();
|
|
||||||
try(PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS))
|
try(PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS))
|
||||||
{
|
{
|
||||||
bindParams(params.toArray(), statement);
|
bindParams(params.toArray(), statement);
|
||||||
incrementStatistic(STAT_QUERIES_RAN);
|
incrementStatistic(STAT_QUERIES_RAN);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
ResultSet generatedKeys = statement.getGeneratedKeys();
|
ResultSet generatedKeys = statement.getGeneratedKeys();
|
||||||
|
List<Integer> rs = new ArrayList<>();
|
||||||
while(generatedKeys.next())
|
while(generatedKeys.next())
|
||||||
{
|
{
|
||||||
rs.add(getInteger(generatedKeys, 1));
|
rs.add(getInteger(generatedKeys, 1));
|
||||||
}
|
}
|
||||||
|
return (rs);
|
||||||
|
}
|
||||||
|
catch(SQLException e)
|
||||||
|
{
|
||||||
|
LOG.warn("SQLException", e, logPair("sql", sql));
|
||||||
|
throw (e);
|
||||||
}
|
}
|
||||||
return (rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -747,14 +792,14 @@ public class QueryManager
|
|||||||
else if(value instanceof LocalDate ld)
|
else if(value instanceof LocalDate ld)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
java.sql.Date date = new java.sql.Date(ld.getYear() - 1900, ld.getMonthValue() - 1, ld.getDayOfMonth());
|
Date date = new Date(ld.getYear() - 1900, ld.getMonthValue() - 1, ld.getDayOfMonth());
|
||||||
statement.setDate(index, date);
|
statement.setDate(index, date);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
else if(value instanceof LocalTime lt)
|
else if(value instanceof LocalTime lt)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
java.sql.Time time = new java.sql.Time(lt.getHour(), lt.getMinute(), lt.getSecond());
|
Time time = new Time(lt.getHour(), lt.getMinute(), lt.getSecond());
|
||||||
statement.setTime(index, time);
|
statement.setTime(index, time);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@ -943,7 +988,7 @@ public class QueryManager
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
statement.setDate(index, new java.sql.Date(value.getTime()));
|
statement.setDate(index, new Date(value.getTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user