#1183 - ENH: Add support for transaction profiling

This commit is contained in:
rob bygrave committed 2017-10-25 01:07:00 +13:00
1 parent 093f82a87f
commit 7ebef51859
46 files changed
+1063 -68

No files matched your search

@@ -9,7 +9,9 @@ import io.ebean.config.dbplatform.DatabasePlatform.OnQueryOnly;
import io.ebean.event.changelog.BeanChange;
import io.ebean.event.changelog.ChangeSet;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.api.SpiProfileTransactionEvent;
import io.ebeaninternal.api.TransactionEvent;
import io.ebeaninternal.api.TxnProfileEventCodes;
import io.ebeaninternal.server.core.PersistDeferredRelationship;
import io.ebeaninternal.server.core.PersistRequest;
import io.ebeaninternal.server.core.PersistRequestBean;
@@ -34,7 +36,7 @@ import java.util.Map;
/**
* JDBC Connection based transaction.
*/
public class JdbcTransaction implements SpiTransaction {
public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
private static final Logger logger = LoggerFactory.getLogger(JdbcTransaction.class);
@@ -169,11 +171,21 @@ public class JdbcTransaction implements SpiTransaction {
protected DocStoreTransaction docStoreTxn;
private final ProfileStream profileStream;
/**
* Create without ProfileStream option (no profiling).
*/
public JdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) {
this(null, id, explicit, connection, manager);
}
/**
* Create a new JdbcTransaction.
*/
public JdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) {
public JdbcTransaction(ProfileStream profileStream, String id, boolean explicit, Connection connection, TransactionManager manager) {
try {
this.profileStream = profileStream;
this.active = true;
this.id = id;
this.logPrefix = deriveLogPrefix(id);
@@ -201,6 +213,23 @@ public class JdbcTransaction implements SpiTransaction {
}
}
@Override
public int profileOffset() {
return (profileStream == null) ? 0 : profileStream.offset();
}
@Override
public void profileEvent(SpiProfileTransactionEvent event) {
if (profileStream != null) {
event.profile();
}
}
@Override
public ProfileStream profileStream() {
return profileStream;
}
/**
* Overridden in AutoCommitJdbcTransaction as that expects to run/operate with autocommit true.
*/
@@ -884,6 +913,7 @@ public class JdbcTransaction implements SpiTransaction {
}
connection = null;
active = false;
profileEnd();
}
/**
@@ -918,14 +948,28 @@ public class JdbcTransaction implements SpiTransaction {
* Perform the actual rollback on the connection.
*/
protected void performRollback() throws SQLException {
int offset = profileOffset();
connection.rollback();
if (profileStream != null) {
profileStream.addEvent(EVT_ROLLBACK, offset);
}
}
/**
* Perform the actual commit on the connection.
*/
protected void performCommit() throws SQLException {
int offset = profileOffset();
connection.commit();
if (profileStream != null) {
profileStream.addEvent(EVT_COMMIT, offset);
}
}
private void profileEnd() {
if (profileStream != null) {
profileStream.end(manager);
}
}
/**