From 8a8680848b963cd894320a571f8632bc6f16d80b Mon Sep 17 00:00:00 2001 From: "denis.sinelnikov" Date: Wed, 14 Aug 2024 15:25:28 +0200 Subject: [PATCH] CB-5458. Create GQL for log commits, implement logic --- .../schema/service.core.graphqls | 14 ++++++++++++++ .../schema/service.sql.graphqls | 6 ++++++ .../io/cloudbeaver/service/sql/DBWServiceSQL.java | 7 +++++++ .../cloudbeaver/service/sql/WebSQLContextInfo.java | 6 ++++++ .../service/sql/WebServiceBindingSQL.java | 5 +++++ .../service/sql/impl/WebServiceSQL.java | 6 ++++++ 6 files changed, 44 insertions(+) diff --git a/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls b/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls index e89cd4bbfa..67958da590 100644 --- a/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls +++ b/server/bundles/io.cloudbeaver.server/schema/service.core.graphqls @@ -71,6 +71,20 @@ type AsyncTaskInfo { taskResult: Object } +type TransactionLogInfos { + count: Int + transactionLogInfos: [ TransactionLogInfoItem ] +} + +type TransactionLogInfoItem { + time: DateTime + type: String + queryString: String + durationMs: Int + rows: Int + result: String +} + # Various server errors descriptor type ServerError { diff --git a/server/bundles/io.cloudbeaver.server/schema/service.sql.graphqls b/server/bundles/io.cloudbeaver.server/schema/service.sql.graphqls index db942decd4..525cee2ca0 100644 --- a/server/bundles/io.cloudbeaver.server/schema/service.sql.graphqls +++ b/server/bundles/io.cloudbeaver.server/schema/service.sql.graphqls @@ -330,6 +330,12 @@ extend type Mutation { dataFormat: ResultDataFormat ): AsyncTaskInfo! + getTransactionLogInfo( + projectId: ID!, + connectionId: ID!, + contextId: ID! + ): TransactionLogInfos + # Close results (free resources) sqlResultClose(projectId: ID, connectionId: ID!, contextId: ID!, resultId: ID!): Boolean! diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java index a7d5a95fc1..bea1288917 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/DBWServiceSQL.java @@ -27,6 +27,7 @@ import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.model.exec.DBCLogicalOperator; import org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty; +import org.jkiss.dbeaver.model.qm.QMTransactionLogInfo; import org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor; import java.util.List; @@ -202,4 +203,10 @@ WebAsyncTaskInfo asyncSqlRollbackTransaction( WebAsyncTaskInfo asyncSqlCommitTransaction( @NotNull WebSession webSession, @NotNull WebSQLContextInfo sqlContext); + + @WebAction + QMTransactionLogInfo getTransactionLogInfo( + @NotNull WebSession webSession, + @NotNull WebSQLContextInfo sqlContext + ); } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java index 1dc81cbad9..1368dfd340 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLContextInfo.java @@ -31,6 +31,7 @@ import org.jkiss.dbeaver.model.exec.*; import org.jkiss.dbeaver.model.exec.trace.DBCTrace; import org.jkiss.dbeaver.model.meta.Property; +import org.jkiss.dbeaver.model.qm.QMTransactionLogInfo; import org.jkiss.dbeaver.model.qm.QMTransactionState; import org.jkiss.dbeaver.model.qm.QMUtils; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; @@ -216,6 +217,11 @@ public void run(DBRProgressMonitor monitor) throws InvocationTargetException, In } + public QMTransactionLogInfo getTransactionLogInfo() { + DBCExecutionContext context = processor.getExecutionContext(); + return QMUtils.getTransactionLogInfo(context); + } + public WebAsyncTaskInfo commitTransaction() { DBCExecutionContext context = processor.getExecutionContext(); DBCTransactionManager txnManager = DBUtils.getTransactionManager(context); diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebServiceBindingSQL.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebServiceBindingSQL.java index 7c5ddcd015..60c471f348 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebServiceBindingSQL.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebServiceBindingSQL.java @@ -229,6 +229,11 @@ public void bindWiring(DBWBindingContext model) throws DBWebException { getService(env).asyncSqlRollbackTransaction( getWebSession(env), getSQLContext(env) + )) + .dataFetcher("getTransactionLogInfo", env -> + getService(env).getTransactionLogInfo( + getWebSession(env), + getSQLContext(env) )); } diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java index cc52563e20..45bad1c55d 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/impl/WebServiceSQL.java @@ -41,6 +41,7 @@ import org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty; import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect; import org.jkiss.dbeaver.model.navigator.DBNNode; +import org.jkiss.dbeaver.model.qm.QMTransactionLogInfo; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.sql.*; import org.jkiss.dbeaver.model.sql.completion.SQLCompletionAnalyzer; @@ -613,4 +614,9 @@ public WebAsyncTaskInfo asyncSqlCommitTransaction(@NotNull WebSession webSession return contextInfo.commitTransaction(); } + @Override + public QMTransactionLogInfo getTransactionLogInfo(@NotNull WebSession webSession, @NotNull WebSQLContextInfo sqlContext) { + return sqlContext.getTransactionLogInfo(); + } + }