mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +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);
|
}), params);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
logSQL(sql, params, mark);
|
{
|
||||||
|
logSQL(sql, params, mark);
|
||||||
|
}
|
||||||
|
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
@ -84,10 +84,10 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
|||||||
setSqlAndJoinsInQueryStat(sql, joinsContext);
|
setSqlAndJoinsInQueryStat(sql, joinsContext);
|
||||||
|
|
||||||
CountOutput rs = new CountOutput();
|
CountOutput rs = new CountOutput();
|
||||||
|
long mark = System.currentTimeMillis();
|
||||||
|
|
||||||
try(Connection connection = getConnection(countInput))
|
try(Connection connection = getConnection(countInput))
|
||||||
{
|
{
|
||||||
long mark = System.currentTimeMillis();
|
|
||||||
|
|
||||||
statement = connection.prepareStatement(sql);
|
statement = connection.prepareStatement(sql);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -116,7 +116,9 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
|||||||
setQueryStatFirstResultTime();
|
setQueryStatFirstResultTime();
|
||||||
|
|
||||||
}), params);
|
}), params);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
logSQL(sql, params, mark);
|
logSQL(sql, params, mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,13 +212,16 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
|||||||
// LOG.debug("rowCount 0 trying to delete [" + tableName + "][" + primaryKey + "]");
|
// 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)"));
|
// 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)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
LOG.debug("Exception trying to delete [" + tableName + "][" + primaryKey + "]", 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())));
|
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
|
public void doDeleteList(Connection connection, QTableMetaData table, List<Serializable> primaryKeys, DeleteOutput deleteOutput) throws QException
|
||||||
{
|
{
|
||||||
|
long mark = System.currentTimeMillis();
|
||||||
|
String sql = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long mark = System.currentTimeMillis();
|
|
||||||
|
|
||||||
String tableName = getTableName(table);
|
String tableName = getTableName(table);
|
||||||
String primaryKeyName = getColumnName(table.getField(table.getPrimaryKeyField()));
|
String primaryKeyName = getColumnName(table.getField(table.getPrimaryKeyField()));
|
||||||
String sql = "DELETE FROM "
|
sql = "DELETE FROM "
|
||||||
+ escapeIdentifier(tableName)
|
+ escapeIdentifier(tableName)
|
||||||
+ " WHERE "
|
+ " WHERE "
|
||||||
+ escapeIdentifier(primaryKeyName)
|
+ escapeIdentifier(primaryKeyName)
|
||||||
@ -246,13 +250,15 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
|||||||
|
|
||||||
Integer rowCount = QueryManager.executeUpdateForRowCount(connection, sql, primaryKeys);
|
Integer rowCount = QueryManager.executeUpdateForRowCount(connection, sql, primaryKeys);
|
||||||
deleteOutput.addToDeletedRecordCount(rowCount);
|
deleteOutput.addToDeletedRecordCount(rowCount);
|
||||||
|
|
||||||
logSQL(sql, primaryKeys, mark);
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
throw new QException("Error executing delete: " + e.getMessage(), 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);
|
int rowCount = QueryManager.executeUpdateForRowCount(connection, sql, params);
|
||||||
deleteOutput.setDeletedRecordCount(rowCount);
|
deleteOutput.setDeletedRecordCount(rowCount);
|
||||||
|
|
||||||
logSQL(sql, params, mark);
|
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
throw new QException("Error executing delete with filter: " + e.getMessage(), e);
|
throw new QException("Error executing delete with filter: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
logSQL(sql, params, mark);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,13 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
|||||||
InsertOutput rs = new InsertOutput();
|
InsertOutput rs = new InsertOutput();
|
||||||
QTableMetaData table = insertInput.getTable();
|
QTableMetaData table = insertInput.getTable();
|
||||||
|
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
boolean needToCloseConnection = false;
|
boolean needToCloseConnection = false;
|
||||||
|
|
||||||
|
StringBuilder sql = null;
|
||||||
|
List<Object> params = null;
|
||||||
|
Long mark = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<QFieldMetaData> insertableFields = table.getFields().values().stream()
|
List<QFieldMetaData> insertableFields = table.getFields().values().stream()
|
||||||
@ -88,10 +92,10 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
|||||||
|
|
||||||
for(List<QRecord> page : CollectionUtils.getPages(insertInput.getRecords(), QueryManager.PAGE_SIZE))
|
for(List<QRecord> page : CollectionUtils.getPages(insertInput.getRecords(), QueryManager.PAGE_SIZE))
|
||||||
{
|
{
|
||||||
String tableName = escapeIdentifier(getTableName(table));
|
String tableName = escapeIdentifier(getTableName(table));
|
||||||
StringBuilder sql = new StringBuilder("INSERT INTO ").append(tableName).append("(").append(columns).append(") VALUES");
|
sql = new StringBuilder("INSERT INTO ").append(tableName).append("(").append(columns).append(") VALUES");
|
||||||
List<Object> params = new ArrayList<>();
|
params = new ArrayList<>();
|
||||||
int recordIndex = 0;
|
int recordIndex = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
// for each record in the page: //
|
// for each record in the page: //
|
||||||
@ -133,7 +137,7 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long mark = System.currentTimeMillis();
|
mark = System.currentTimeMillis();
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// execute the insert, then foreach record in the input, //
|
// execute the insert, then foreach record in the input, //
|
||||||
@ -163,6 +167,7 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
|||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
|
logSQL(sql, params, mark);
|
||||||
throw new QException("Error executing insert: " + e.getMessage(), e);
|
throw new QException("Error executing insert: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -223,17 +223,12 @@ public class RDBMSQueryAction extends AbstractRDBMSAction implements QueryInterf
|
|||||||
|
|
||||||
}), params);
|
}), params);
|
||||||
|
|
||||||
logSQL(sql, params, mark);
|
|
||||||
|
|
||||||
return queryOutput;
|
return queryOutput;
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
logSQL(sql, params, mark);
|
|
||||||
throw (e);
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
logSQL(sql, params, mark);
|
||||||
|
|
||||||
if(actionTimeoutHelper != null)
|
if(actionTimeoutHelper != null)
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
@ -179,10 +179,15 @@ public class RDBMSUpdateAction extends AbstractRDBMSAction implements UpdateInte
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// let query manager do the batch updates - note that it will internally page //
|
// let query manager do the batch updates - note that it will internally page //
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
QueryManager.executeBatchUpdate(connection, sql, values);
|
try
|
||||||
incrementStatus(updateInput, recordList.size());
|
{
|
||||||
|
QueryManager.executeBatchUpdate(connection, sql, values);
|
||||||
logSQL(sql, values, mark);
|
incrementStatus(updateInput, recordList.size());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
logSQL(sql, values, mark);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -249,10 +254,15 @@ public class RDBMSUpdateAction extends AbstractRDBMSAction implements UpdateInte
|
|||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
// let query manager do the update //
|
// let query manager do the update //
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
QueryManager.executeUpdate(connection, sql, params);
|
try
|
||||||
incrementStatus(updateInput, page.size());
|
{
|
||||||
|
QueryManager.executeUpdate(connection, sql, params);
|
||||||
logSQL(sql, params, mark);
|
incrementStatus(updateInput, page.size());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
logSQL(sql, params, mark);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user