mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Make debug-logging SQL controlled by system property
This commit is contained in:
@ -39,6 +39,7 @@ import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||
import com.kingsrook.qqq.backend.core.actions.interfaces.QActionInterface;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QValueException;
|
||||
import com.kingsrook.qqq.backend.core.logging.LogPair;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.aggregate.Aggregate;
|
||||
@ -68,6 +69,7 @@ import com.kingsrook.qqq.backend.module.rdbms.jdbc.ConnectionManager;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.jdbc.QueryManager;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.model.metadata.RDBMSBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.module.rdbms.model.metadata.RDBMSTableBackendDetails;
|
||||
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -938,4 +940,29 @@ public abstract class AbstractRDBMSAction implements QActionInterface
|
||||
return (String.format(groupBy.getFormatString(), fullFieldName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
protected void logSQL(CharSequence sql, List<?> params)
|
||||
{
|
||||
if(System.getProperty("qqq.rdbms.logSQL", "false").equals("true"))
|
||||
{
|
||||
try
|
||||
{
|
||||
LogPair paramsLogPair = params == null ? null :
|
||||
params.size() <= 100 ? logPair("params", params) :
|
||||
logPair("first100Params", params.subList(0, 99));
|
||||
|
||||
LOG.debug("Running SQL", logPair("sql", sql), paramsLogPair);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.debug("Error logging sql...", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -86,7 +86,8 @@ public class RDBMSAggregateAction extends AbstractRDBMSAction implements Aggrega
|
||||
}
|
||||
|
||||
// todo sql customization - can edit sql and/or param list
|
||||
LOG.debug(sql); // todo not commit - downgrade to trace
|
||||
|
||||
logSQL(sql, params);
|
||||
|
||||
AggregateOutput rs = new AggregateOutput();
|
||||
List<AggregateResult> results = new ArrayList<>();
|
||||
|
@ -64,9 +64,10 @@ public class RDBMSCountAction extends AbstractRDBMSAction implements CountInterf
|
||||
QQueryFilter filter = countInput.getFilter();
|
||||
List<Serializable> params = new ArrayList<>();
|
||||
sql += " WHERE " + makeWhereClause(countInput.getInstance(), countInput.getSession(), table, joinsContext, filter, params);
|
||||
|
||||
// todo sql customization - can edit sql and/or param list
|
||||
|
||||
logSQL(sql, params);
|
||||
|
||||
CountOutput rs = new CountOutput();
|
||||
|
||||
try(Connection connection = getConnection(countInput))
|
||||
|
@ -190,6 +190,8 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
+ " WHERE "
|
||||
+ escapeIdentifier(primaryKeyName) + " = ?";
|
||||
|
||||
logSQL(sql, List.of(primaryKey));
|
||||
|
||||
try
|
||||
{
|
||||
int rowCount = QueryManager.executeUpdateForRowCount(connection, sql, primaryKey);
|
||||
@ -237,6 +239,7 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
+ ")";
|
||||
|
||||
// todo sql customization - can edit sql and/or param list
|
||||
logSQL(sql, primaryKeys);
|
||||
|
||||
Integer rowCount = QueryManager.executeUpdateForRowCount(connection, sql, primaryKeys);
|
||||
deleteOutput.addToDeletedRecordCount(rowCount);
|
||||
@ -267,6 +270,7 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
+ escapeIdentifier(tableName) + " AS " + escapeIdentifier(table.getName())
|
||||
+ " WHERE "
|
||||
+ whereClause;
|
||||
logSQL(sql, params);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -153,6 +153,8 @@ public class RDBMSInsertAction extends AbstractRDBMSAction implements InsertInte
|
||||
continue;
|
||||
}
|
||||
|
||||
logSQL(sql, params);
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// execute the insert, then foreach record in the input, //
|
||||
// add it to the output, and set its generated id too. //
|
||||
|
@ -137,7 +137,8 @@ public class RDBMSQueryAction extends AbstractRDBMSAction implements QueryInterf
|
||||
// execute the query - iterate over results //
|
||||
//////////////////////////////////////////////
|
||||
QueryOutput queryOutput = new QueryOutput(queryInput);
|
||||
// System.out.println(sql);
|
||||
logSQL(sql, params);
|
||||
|
||||
PreparedStatement statement = createStatement(connection, sql.toString(), queryInput);
|
||||
QueryManager.executeStatement(statement, ((ResultSet resultSet) ->
|
||||
{
|
||||
|
@ -72,13 +72,13 @@ public class RDBMSTransaction extends QBackendTransaction
|
||||
{
|
||||
try
|
||||
{
|
||||
RDBMSTransaction.LOG.debug("Committing transaction");
|
||||
LOG.debug("Committing transaction");
|
||||
connection.commit();
|
||||
RDBMSTransaction.LOG.debug("Commit complete");
|
||||
LOG.debug("Commit complete");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
RDBMSTransaction.LOG.error("Error committing transaction", e);
|
||||
LOG.error("Error committing transaction", e);
|
||||
throw new QException("Error committing transaction: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
@ -93,13 +93,13 @@ public class RDBMSTransaction extends QBackendTransaction
|
||||
{
|
||||
try
|
||||
{
|
||||
RDBMSTransaction.LOG.info("Rolling back transaction");
|
||||
LOG.info("Rolling back transaction");
|
||||
connection.rollback();
|
||||
RDBMSTransaction.LOG.info("Rollback complete");
|
||||
LOG.info("Rollback complete");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
RDBMSTransaction.LOG.error("Error rolling back transaction", e);
|
||||
LOG.error("Error rolling back transaction", e);
|
||||
throw new QException("Error rolling back transaction: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +204,8 @@ public class RDBMSUpdateAction extends AbstractRDBMSAction implements UpdateInte
|
||||
rowValues.add(record.getValue(table.getPrimaryKeyField()));
|
||||
}
|
||||
|
||||
logSQL(sql, values);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// let query manager do the batch updates - note that it will internally page //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -261,6 +263,8 @@ public class RDBMSUpdateAction extends AbstractRDBMSAction implements UpdateInte
|
||||
params.add(record.getValue(table.getPrimaryKeyField()));
|
||||
}
|
||||
|
||||
logSQL(sql, params);
|
||||
|
||||
/////////////////////////////////////
|
||||
// let query manager do the update //
|
||||
/////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user