mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Move logSQL calls into finally blocks, to happen upon success or exception.
This commit is contained in:
@ -168,8 +168,10 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
|
||||
|
||||
}), params);
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
}
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
@ -84,10 +84,10 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
||||
setSqlAndJoinsInQueryStat(sql, joinsContext);
|
||||
|
||||
CountOutput rs = new CountOutput();
|
||||
try(Connection connection = getConnection(countInput))
|
||||
{
|
||||
long mark = System.currentTimeMillis();
|
||||
|
||||
try(Connection connection = getConnection(countInput))
|
||||
{
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -116,7 +116,9 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
||||
setQueryStatFirstResultTime();
|
||||
|
||||
}), params);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
}
|
||||
|
||||
|
@ -212,13 +212,16 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
// LOG.debug("rowCount 0 trying to delete [" + tableName + "][" + primaryKey + "]");
|
||||
// deleteOutput.addRecordWithError(new QRecord(table, primaryKey).withError("Record was not deleted (but no error was given from the database)"));
|
||||
// }
|
||||
logSQL(sql, List.of(primaryKey), mark);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.debug("Exception trying to delete [" + tableName + "][" + primaryKey + "]", e);
|
||||
deleteOutput.addRecordWithError(new QRecord(table, primaryKey).withError(new SystemErrorStatusMessage("Record was not deleted: " + e.getMessage())));
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, List.of(primaryKey), mark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -228,13 +231,14 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
*******************************************************************************/
|
||||
public void doDeleteList(Connection connection, QTableMetaData table, List<Serializable> primaryKeys, DeleteOutput deleteOutput) throws QException
|
||||
{
|
||||
long mark = System.currentTimeMillis();
|
||||
String sql = null;
|
||||
|
||||
try
|
||||
{
|
||||
long mark = System.currentTimeMillis();
|
||||
|
||||
String tableName = getTableName(table);
|
||||
String primaryKeyName = getColumnName(table.getField(table.getPrimaryKeyField()));
|
||||
String sql = "DELETE FROM "
|
||||
sql = "DELETE FROM "
|
||||
+ escapeIdentifier(tableName)
|
||||
+ " WHERE "
|
||||
+ escapeIdentifier(primaryKeyName)
|
||||
@ -246,13 +250,15 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
|
||||
Integer rowCount = QueryManager.executeUpdateForRowCount(connection, sql, primaryKeys);
|
||||
deleteOutput.addToDeletedRecordCount(rowCount);
|
||||
|
||||
logSQL(sql, primaryKeys, mark);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new QException("Error executing delete: " + e.getMessage(), e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, primaryKeys, mark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -282,12 +288,14 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
{
|
||||
int rowCount = QueryManager.executeUpdateForRowCount(connection, sql, params);
|
||||
deleteOutput.setDeletedRecordCount(rowCount);
|
||||
|
||||
logSQL(sql, params, mark);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new QException("Error executing delete with filter: " + e.getMessage(), e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,10 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
||||
Connection connection = null;
|
||||
boolean needToCloseConnection = false;
|
||||
|
||||
StringBuilder sql = null;
|
||||
List<Object> params = null;
|
||||
Long mark = null;
|
||||
|
||||
try
|
||||
{
|
||||
List<QFieldMetaData> insertableFields = table.getFields().values().stream()
|
||||
@ -89,8 +93,8 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
||||
for(List<QRecord> page : CollectionUtils.getPages(insertInput.getRecords(), QueryManager.PAGE_SIZE))
|
||||
{
|
||||
String tableName = escapeIdentifier(getTableName(table));
|
||||
StringBuilder sql = new StringBuilder("INSERT INTO ").append(tableName).append("(").append(columns).append(") VALUES");
|
||||
List<Object> params = new ArrayList<>();
|
||||
sql = new StringBuilder("INSERT INTO ").append(tableName).append("(").append(columns).append(") VALUES");
|
||||
params = new ArrayList<>();
|
||||
int recordIndex = 0;
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
@ -133,7 +137,7 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
||||
continue;
|
||||
}
|
||||
|
||||
Long mark = System.currentTimeMillis();
|
||||
mark = System.currentTimeMillis();
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// execute the insert, then foreach record in the input, //
|
||||
@ -163,6 +167,7 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
throw new QException("Error executing insert: " + e.getMessage(), e);
|
||||
}
|
||||
finally
|
||||
|
@ -223,17 +223,12 @@ public class RDBMSQueryAction extends AbstractRDBMSAction implements QueryInterf
|
||||
|
||||
}), params);
|
||||
|
||||
logSQL(sql, params, mark);
|
||||
|
||||
return queryOutput;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
throw (e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
|
||||
if(actionTimeoutHelper != null)
|
||||
{
|
||||
/////////////////////////////////////////
|
||||
|
@ -179,11 +179,16 @@ public class RDBMSUpdateAction extends AbstractRDBMSAction implements UpdateInte
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// let query manager do the batch updates - note that it will internally page //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
try
|
||||
{
|
||||
QueryManager.executeBatchUpdate(connection, sql, values);
|
||||
incrementStatus(updateInput, recordList.size());
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, values, mark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -249,12 +254,17 @@ public class RDBMSUpdateAction extends AbstractRDBMSAction implements UpdateInte
|
||||
/////////////////////////////////////
|
||||
// let query manager do the update //
|
||||
/////////////////////////////////////
|
||||
try
|
||||
{
|
||||
QueryManager.executeUpdate(connection, sql, params);
|
||||
incrementStatus(updateInput, page.size());
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSQL(sql, params, mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user