Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public DataSource dataSource()
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery("SELECT 1");

return new DataSourceWithLogger(propertiesConfig.getDebugLogMessageDbStatement(), dataSource);
return propertiesConfig.getDebugLogMessageDbStatement() ? new DataSourceWithLogger(dataSource) : dataSource;
}

private String toString(char[] password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.IOException;
import java.util.List;

import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
import org.operaton.bpm.engine.ProcessEngine;
import org.operaton.bpm.engine.impl.jobexecutor.DefaultJobExecutor;
Expand All @@ -41,6 +43,7 @@
import dev.dsf.bpe.engine.MultiVersionSpringProcessEngineConfiguration;
import dev.dsf.bpe.listener.DebugLoggingBpmnParseListener;
import dev.dsf.bpe.listener.DefaultBpmnParseListener;
import dev.dsf.common.db.logging.DataSourceWithLogger;

@Configuration
public class OperatonConfig
Expand Down Expand Up @@ -70,7 +73,7 @@ public TransactionAwareDataSourceProxy transactionAwareDataSource()
}

@Bean
public BasicDataSource engineDataSource()
public DataSource engineDataSource()
{
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(Driver.class.getName());
Expand All @@ -80,7 +83,8 @@ public BasicDataSource engineDataSource()

dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery("SELECT 1");
return dataSource;

return propertiesConfig.getDebugLogMessageDbStatement() ? new DataSourceWithLogger(dataSource) : dataSource;
}

private String toString(char[] password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public abstract class AbstractDbTest
SLF4JBridgeHandler.install();
}

protected static final boolean LOG_DB_STATEMENTS = true;
protected static final boolean LOG_DB_STATEMENTS = false; /* enable to see SQL statements in log output */

protected static final String BPE_CHANGE_LOG_FILE = "bpe/db/db.changelog.xml";

Expand Down Expand Up @@ -81,7 +81,7 @@ public static DataSource createBpeDefaultDataSource(String host, int port, Strin
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery("SELECT 1");

return new DataSourceWithLogger(LOG_DB_STATEMENTS, dataSource);
return LOG_DB_STATEMENTS ? new DataSourceWithLogger(dataSource) : dataSource;
}

public static DataSource createBpeCamundaDataSource(String host, int port, String databaseName)
Expand All @@ -96,7 +96,7 @@ public static DataSource createBpeCamundaDataSource(String host, int port, Strin
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery("SELECT 1");

return new DataSourceWithLogger(LOG_DB_STATEMENTS, dataSource);
return LOG_DB_STATEMENTS ? new DataSourceWithLogger(dataSource) : dataSource;
}

public static DataSource createFhirDefaultDataSource(String host, int port, String databaseName)
Expand All @@ -111,7 +111,7 @@ public static DataSource createFhirDefaultDataSource(String host, int port, Stri
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery("SELECT 1");

return new DataSourceWithLogger(LOG_DB_STATEMENTS, dataSource);
return LOG_DB_STATEMENTS ? new DataSourceWithLogger(dataSource) : dataSource;
}

public static DataSource createFhirPermanentDeleteDataSource(String host, int port, String databaseName)
Expand All @@ -126,6 +126,6 @@ public static DataSource createFhirPermanentDeleteDataSource(String host, int po
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery("SELECT 1");

return new DataSourceWithLogger(LOG_DB_STATEMENTS, dataSource);
return LOG_DB_STATEMENTS ? new DataSourceWithLogger(dataSource) : dataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private static JettyServer startFhirServer(ServerSocketChannel statusConnectorCh
initParameters.put("dev.dsf.fhir.db.user.permanent.delete.group", FHIR_DATABASE_DELETE_USERS_GROUP);
initParameters.put("dev.dsf.fhir.db.user.permanent.delete.username", FHIR_DATABASE_DELETE_USER);
initParameters.put("dev.dsf.fhir.db.user.permanent.delete.password", FHIR_DATABASE_DELETE_USER_PASSWORD);
initParameters.put("dev.dsf.fhir.debug.log.message.dbStatement", String.valueOf(LOG_DB_STATEMENTS));

initParameters.put("dev.dsf.fhir.server.base.url", baseUrl);
initParameters.put("dev.dsf.fhir.server.organization.identifier.value", "Test_Organization");
Expand Down Expand Up @@ -370,6 +371,7 @@ private static JettyServer startBpeServer(ServerSocketChannel statusConnectorCha
initParameters.put("dev.dsf.bpe.db.user.password", BPE_DATABASE_USER_PASSWORD);
initParameters.put("dev.dsf.bpe.db.user.engine.username", BPE_DATABASE_ENGINE_USER);
initParameters.put("dev.dsf.bpe.db.user.engine.password", BPE_DATABASE_ENGINE_USER_PASSWORD);
initParameters.put("dev.dsf.bpe.debug.log.message.dbStatement", String.valueOf(LOG_DB_STATEMENTS));

initParameters.put("dev.dsf.bpe.fhir.client.certificate", certificates.getClientCertificateFile().toString());
initParameters.put("dev.dsf.bpe.fhir.client.certificate.private.key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@

public class ConnectionWithLogger implements Connection
{
private final boolean loggerEnabled;

private final Connection delegate;

public ConnectionWithLogger(boolean loggerEnabled, Connection delegate)
public ConnectionWithLogger(Connection delegate)
{
this.loggerEnabled = loggerEnabled;
this.delegate = delegate;
}

Expand All @@ -62,13 +59,13 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException
@Override
public Statement createStatement() throws SQLException
{
return delegate.createStatement();
return new StatementWithLogger(delegate.createStatement());
}

@Override
public PreparedStatement prepareStatement(String sql) throws SQLException
{
return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql));
return new PreparedStatementWithLogger(delegate.prepareStatement(sql));
}

@Override
Expand Down Expand Up @@ -176,15 +173,14 @@ public void clearWarnings() throws SQLException
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
{
return delegate.createStatement(resultSetType, resultSetConcurrency);
return new StatementWithLogger(delegate.createStatement(resultSetType, resultSetConcurrency));
}

@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException
{
return new PreparedStatementWithLogger(loggerEnabled,
delegate.prepareStatement(sql, resultSetType, resultSetConcurrency));
return new PreparedStatementWithLogger(delegate.prepareStatement(sql, resultSetType, resultSetConcurrency));
}

@Override
Expand Down Expand Up @@ -245,14 +241,15 @@ public void releaseSavepoint(Savepoint savepoint) throws SQLException
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException
{
return delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
return new StatementWithLogger(
delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
}

@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException
{
return new PreparedStatementWithLogger(loggerEnabled,
return new PreparedStatementWithLogger(
delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
}

Expand All @@ -266,19 +263,19 @@ public CallableStatement prepareCall(String sql, int resultSetType, int resultSe
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
{
return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, autoGeneratedKeys));
return new PreparedStatementWithLogger(delegate.prepareStatement(sql, autoGeneratedKeys));
}

@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
{
return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, columnIndexes));
return new PreparedStatementWithLogger(delegate.prepareStatement(sql, columnIndexes));
}

@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
{
return new PreparedStatementWithLogger(loggerEnabled, delegate.prepareStatement(sql, columnNames));
return new PreparedStatementWithLogger(delegate.prepareStatement(sql, columnNames));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@

public class DataSourceWithLogger implements DataSource
{
private final boolean loggerEnabled;

private final BasicDataSource delegate;

public DataSourceWithLogger(boolean loggerEnabled, BasicDataSource delegate)
public DataSourceWithLogger(BasicDataSource delegate)
{
this.loggerEnabled = loggerEnabled;
this.delegate = delegate;
}

Expand All @@ -59,13 +56,13 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException
@Override
public Connection getConnection() throws SQLException
{
return new ConnectionWithLogger(loggerEnabled, delegate.getConnection());
return new ConnectionWithLogger(delegate.getConnection());
}

@Override
public Connection getConnection(String username, String password) throws SQLException
{
return new ConnectionWithLogger(loggerEnabled, delegate.getConnection(username, password));
return new ConnectionWithLogger(delegate.getConnection(username, password));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,17 @@
public class PreparedStatementWithLogger implements PreparedStatement
{
private static final Logger logger = LoggerFactory.getLogger(PreparedStatementWithLogger.class);
private final boolean loggerEnabled;

private final PreparedStatement delegate;

public PreparedStatementWithLogger(boolean loggerEnabled, PreparedStatement delegate)
public PreparedStatementWithLogger(PreparedStatement delegate)
{
this.loggerEnabled = loggerEnabled;
this.delegate = delegate;
}

private void logStatement()
{
if (loggerEnabled)
logger.debug("Executing query '{}'", this);
}

private void logStatement(String sql)
{
if (loggerEnabled)
logger.debug("Executing query '{}'", sql);
logger.debug("{}", this);
}

@Override
Expand All @@ -76,8 +67,6 @@ public <T> T unwrap(Class<T> iface) throws SQLException
@Override
public ResultSet executeQuery(String sql) throws SQLException
{
logStatement(sql);

return delegate.executeQuery(sql);
}

Expand All @@ -98,8 +87,6 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException
@Override
public int executeUpdate(String sql) throws SQLException
{
logStatement(sql);

return delegate.executeUpdate(sql);
}

Expand Down Expand Up @@ -276,8 +263,6 @@ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws
@Override
public boolean execute(String sql) throws SQLException
{
logStatement(sql);

return delegate.execute(sql);
}

Expand Down Expand Up @@ -529,8 +514,6 @@ public void setNCharacterStream(int parameterIndex, Reader value, long length) t
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
{
logStatement(sql);

return delegate.execute(sql, autoGeneratedKeys);
}

Expand All @@ -549,8 +532,6 @@ public void setClob(int parameterIndex, Reader reader, long length) throws SQLEx
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException
{
logStatement(sql);

return delegate.execute(sql, columnIndexes);
}

Expand All @@ -569,8 +550,6 @@ public void setNClob(int parameterIndex, Reader reader, long length) throws SQLE
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException
{
logStatement(sql);

return delegate.execute(sql, columnNames);
}

Expand Down Expand Up @@ -667,6 +646,8 @@ public long getLargeMaxRows() throws SQLException
@Override
public long[] executeLargeBatch() throws SQLException
{
logStatement();

return delegate.executeLargeBatch();
}

Expand Down Expand Up @@ -751,6 +732,8 @@ public String enquoteLiteral(String val) throws SQLException
@Override
public long executeLargeUpdate() throws SQLException
{
logStatement();

return delegate.executeLargeUpdate();
}

Expand Down
Loading
Loading