mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
1476 - Query plan capture, initial wip capturing bind params (#1477)
* 1476 - Query plan capture, initial wip capturing bind params * No effective change - Reset test default db to H2 * #1476 - Query plan capture, initial wip capturing bind params #1477 Update with consumer * #1476 - Query plan capture, initial wip capturing bind params #1477 Update with query plan request * #1476 - Query plan capture, initial wip capturing bind params #1477 Extract interface * #1476 - Query plan capture, initial wip capturing bind params #1477 Extract interface
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package io.ebeaninternal.server.query;
|
||||
|
||||
import io.ebeaninternal.server.type.bindcapture.BindCapture;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class QueryPlanLogger {
|
||||
|
||||
static final Logger queryPlanLog = LoggerFactory.getLogger(QueryPlanLogger.class);
|
||||
|
||||
public abstract DQueryPlanOutput logQueryPlan(Connection conn, CQueryPlan plan, BindCapture bind);
|
||||
|
||||
DQueryPlanOutput readQueryPlan(CQueryPlan plan, BindCapture bind, ResultSet rset) throws SQLException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i <= rset.getMetaData().getColumnCount(); i++) {
|
||||
sb.append(rset.getMetaData().getColumnLabel(i)).append("\t");
|
||||
}
|
||||
sb.setLength(sb.length() - 1);
|
||||
readPlanData(sb, rset);
|
||||
|
||||
return createPlan(plan, bind.toString(), sb.toString());
|
||||
}
|
||||
|
||||
protected DQueryPlanOutput createPlan(CQueryPlan plan, String bind, String planString) {
|
||||
return new DQueryPlanOutput(plan.getBeanType(), plan.getLabel(), plan.getSql(), bind, planString);
|
||||
}
|
||||
|
||||
DQueryPlanOutput readQueryPlanBasic(CQueryPlan plan, BindCapture bind, ResultSet rset) throws SQLException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
readPlanData(sb, rset);
|
||||
return createPlan(plan, bind.toString(), sb.toString().trim());
|
||||
}
|
||||
|
||||
private void readPlanData(StringBuilder sb, ResultSet rset) throws SQLException {
|
||||
while (rset.next()) {
|
||||
sb.append('\n');
|
||||
for (int i = 1; i <= rset.getMetaData().getColumnCount(); i++) {
|
||||
sb.append(rset.getString(i)).append("\t");
|
||||
}
|
||||
sb.setLength(sb.length()-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user