com.github.lontime.extspring.impl.copper.audit.SpringTxnAuditTrail Maven / Gradle / Ivy
package com.github.lontime.extspring.impl.copper.audit;
import java.sql.Connection;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import com.github.lontime.extspring.impl.copper.SpringTransaction;
import org.copperengine.core.CopperRuntimeException;
import org.copperengine.core.audit.AbstractAuditTrail;
import org.copperengine.core.audit.AuditTrailEvent;
import org.copperengine.core.audit.BatchInsertIntoAutoTrail.Command;
import org.copperengine.core.audit.BatchInsertIntoAutoTrail.Executor;
import org.copperengine.core.batcher.BatchCommand;
import org.copperengine.core.batcher.NullCallback;
/**
* SpringTxnAuditTrail.
* @author lontime
* @since 1.0
*/
public class SpringTxnAuditTrail extends AbstractAuditTrail {
private static final Logger logger = org.slf4j.LoggerFactory.getLogger(SpringTxnAuditTrail.class);
private PlatformTransactionManager transactionManager;
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Override
public void synchLog(final AuditTrailEvent e) {
if (isEnabled(e.getLogLevel())) {
logger.debug("doLog({})", e);
e.setMessage(messagePostProcessor.serialize(e.getMessage()));
try {
new SpringTransaction() {
@Override
protected void execute(Connection con) throws Exception {
@SuppressWarnings("unchecked")
BatchCommand cmd = createBatchCommand(e, true, NullCallback.instance);
List> cmdList = Arrays.asList(cmd);
cmd.executor().doExec(cmdList, con);
}
}.run(transactionManager, getDataSource(), createTransactionDefinition());
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new CopperRuntimeException(ex);
}
}
}
protected TransactionDefinition createTransactionDefinition() {
return new DefaultTransactionDefinition();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy