#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

@@ -30,4 +30,8 @@ public interface BatchPostExecute {
*/
void postExecute();
/**
* Add as event to the profiling.
*/
void profile(int offset, int batchSize);
}
@@ -1,5 +1,8 @@
package io.ebeaninternal.server.persist;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.api.SpiProfileTransactionEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -12,7 +15,7 @@ import java.util.ArrayList;
* This can hold CallableStatements as well.
* </p>
*/
public class BatchedPstmt {
public class BatchedPstmt implements SpiProfileTransactionEvent {
/**
* The underlying statement.
@@ -31,13 +34,18 @@ public class BatchedPstmt {
private final String sql;
private final SpiTransaction transaction;
private int profileStart;
/**
* Create with a given statement.
*/
public BatchedPstmt(PreparedStatement pstmt, boolean isGenKeys, String sql) {
public BatchedPstmt(PreparedStatement pstmt, boolean isGenKeys, String sql, SpiTransaction transaction) {
this.pstmt = pstmt;
this.isGenKeys = isGenKeys;
this.sql = sql;
this.transaction = transaction;
}
/**
@@ -74,12 +82,20 @@ public class BatchedPstmt {
*/
public void executeBatch(boolean getGeneratedKeys) throws SQLException {
this.profileStart = transaction.profileOffset();
executeAndCheckRowCounts();
if (isGenKeys && getGeneratedKeys) {
getGeneratedKeys();
}
postExecute();
close();
transaction.profileEvent(this);
}
@Override
public void profile() {
// just use the first to add the event
list.get(0).profile(profileStart, list.size());
}
/**
@@ -93,8 +109,8 @@ public class BatchedPstmt {
}
private void postExecute() {
for (BatchPostExecute aList : list) {
aList.postExecute();
for (BatchPostExecute item : list) {
item.postExecute();
}
}
@@ -54,7 +54,7 @@ public class PstmtFactory {
Connection conn = t.getInternalConnection();
stmt = conn.prepareStatement(sql);
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql);
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, t);
batch.addStmt(bs, batchExe);
return stmt;
}
@@ -78,7 +78,7 @@ public class PstmtFactory {
Connection conn = t.getInternalConnection();
stmt = conn.prepareCall(sql);
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql);
BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, t);
batch.addStmt(bs, batchExe);
return stmt;
}
@@ -283,7 +283,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
stmt = getPstmt(t, sql, genKeys);
BatchedPstmt bs = new BatchedPstmt(stmt, genKeys, sql);
BatchedPstmt bs = new BatchedPstmt(stmt, genKeys, sql, t);
batch.addStmt(bs, request);
return stmt;
}