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,52 @@
|
||||
package io.ebeaninternal.server.query;
|
||||
|
||||
import io.ebeaninternal.server.type.bindcapture.BindCapture;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
* A QueryPlanlogger for sqlserver. It will return the plan as XML, which can be opened in
|
||||
* Microsoft SQL Server Management Studio.
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
public class QueryPlanLoggerSqlServer extends QueryPlanLogger {
|
||||
|
||||
@Override
|
||||
public DQueryPlanOutput logQueryPlan(Connection conn, CQueryPlan plan, BindCapture bind) {
|
||||
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("SET STATISTICS XML ON");
|
||||
try (PreparedStatement explainStmt = conn.prepareStatement(plan.getSql())) {
|
||||
bind.prepare(explainStmt, conn);
|
||||
|
||||
try (ResultSet rset = explainStmt.executeQuery()) {
|
||||
// unfortunately, this will execute the
|
||||
}
|
||||
if (explainStmt.getMoreResults()) {
|
||||
try (ResultSet rset = explainStmt.getResultSet()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (rset.next()) {
|
||||
sb.append("XML: ").append(rset.getString(1));
|
||||
}
|
||||
return createPlan(plan, bind.toString(), sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
queryPlanLog.error("Could not log query plan", e);
|
||||
|
||||
} finally {
|
||||
stmt.execute("SET STATISTICS XML OFF");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
queryPlanLog.error("Could not log query plan", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user