Good night,
I override some classes of QueryDSL SQL because I needed log queries with parameters. How I work with JBOSS my code stay so:
if (AbstractSQLQuery.logger.isDebugEnabled()) {
if(stmt instanceof WrappedPreparedStatementJDK6){
AbstractSQLQuery.logger.debug("query : {}", ((WrappedPreparedStatementJDK6)stmt).getUnderlyingStatement());
}else{
AbstractSQLQuery.logger.debug("query : {}", stmt);
}
}
The toString of PreparedStatement of Postgres returns the SQL with configured parameters, in another words, the exactly query that will be send to database.
This is not elegant solution, then, I propose that is created something like "LogHandler". A simple interface with method that receive a PreparedStatement and query string.
public void logStatement(PreparedStatement stmt, String queryString) throws SQLException;
And a default implementation:
public void logStatement(PreparedStatement stmt, String queryString) throws SQLException {
logger.debug("query : {}", queryString);
}
This way, case developer need a different log then creates your own implementation like my case.