Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-5369. Added API for transaction log for commits #3183

Merged
merged 27 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
02baaf3
CB-5369. Added API for transaction log for commits
DenisSinelnikov Jan 9, 2025
d352e50
Merge branch 'devel' into CB-5369-transaction-log-for-commits
DenisSinelnikov Jan 9, 2025
8d47710
CB-5369. Refactor after review
DenisSinelnikov Jan 9, 2025
1f04b43
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 9, 2025
89e0ff4
CB-5369 add transaction logs table
devnaumov Jan 9, 2025
d0c621b
Merge branches 'CB-5369-transaction-log-for-commits' and 'CB-5369-tra…
devnaumov Jan 9, 2025
854f830
CB-5369. Added id for data
DenisSinelnikov Jan 10, 2025
0848dbf
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 10, 2025
5f44a3b
CB-5369 fix typo
devnaumov Jan 10, 2025
b9fd5fb
CB-5369. Added event for get count
DenisSinelnikov Jan 10, 2025
a171da8
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 10, 2025
024c671
CB-5369. Refactor event
DenisSinelnikov Jan 12, 2025
6659111
CB-5369. Refactor event
DenisSinelnikov Jan 12, 2025
bc54897
CB-5369. Refactor after review
DenisSinelnikov Jan 12, 2025
5622605
CB-5369. Refactor after review
DenisSinelnikov Jan 12, 2025
4e7b62f
CB-5369. Added connectionId to event
DenisSinelnikov Jan 12, 2025
3314f75
CB-5369 support count event
devnaumov Jan 12, 2025
c1f5834
CB-5369. Rename eventId
DenisSinelnikov Jan 13, 2025
96954ff
Merge remote-tracking branch 'origin/CB-5369-transaction-log-for-comm…
DenisSinelnikov Jan 13, 2025
0647177
CB-5369 adjust count styles
devnaumov Jan 13, 2025
6bea6b0
CB-5369 format time
devnaumov Jan 13, 2025
41c60fa
CB-5369 add missing deps
devnaumov Jan 13, 2025
abad3a0
CB-5369 remove extra important flags
devnaumov Jan 13, 2025
3c5332a
CB-5369 review fixes
devnaumov Jan 13, 2025
8f6e63e
CB-5369 remove extra import
devnaumov Jan 13, 2025
e0e5f82
Merge branch 'devel' into CB-5369-transaction-log-for-commits
dariamarutkina Jan 14, 2025
691ae67
Merge branch 'devel' into CB-5369-transaction-log-for-commits
dariamarutkina Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
CB-5369. Added event for get count
  • Loading branch information
DenisSinelnikov committed Jan 10, 2025
commit b9fd5fb234e86780ff11291cd322dbc6f6e43185
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,12 +41,14 @@
import org.jkiss.dbeaver.model.impl.DefaultServerOutputReader;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseItem;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.*;
import org.jkiss.dbeaver.model.sql.parser.SQLParserContext;
import org.jkiss.dbeaver.model.sql.parser.SQLRuleManager;
import org.jkiss.dbeaver.model.sql.parser.SQLScriptParser;
import org.jkiss.dbeaver.model.struct.*;
import org.jkiss.dbeaver.model.websocket.event.WSTransactionalCountEvent;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
Expand Down Expand Up @@ -164,7 +166,7 @@ public WebSQLExecuteInfo processQuery(
@Nullable WebSQLDataFilter filter,
@Nullable WebDataFormat dataFormat,
@NotNull WebSession webSession,
boolean readLogs) throws DBWebException {
boolean readLogs) throws DBWebException, DBCException {
if (filter == null) {
// Use default filter
filter = new WebSQLDataFilter();
Expand Down Expand Up @@ -270,6 +272,9 @@ public WebSQLExecuteInfo processQuery(
} catch (DBException e) {
throw new DBWebException("Error executing query", e);
}
if (!DBUtils.getTransactionManager(context).isAutoCommit()) {
DenisSinelnikov marked this conversation as resolved.
Show resolved Hide resolved
sendTransactionalEvent(contextInfo);
}
executeInfo.setDuration(System.currentTimeMillis() - startTime);
if (executeInfo.getResults().length == 0) {
executeInfo.setStatusMessage("No Data");
Expand Down Expand Up @@ -354,17 +359,17 @@ public WebSQLExecuteInfo updateResultsDataBatch(

WebSQLExecuteInfo result = new WebSQLExecuteInfo();
List<WebSQLQueryResults> queryResults = new ArrayList<>();
boolean isAutoCommitEnabled = true;

for (var rowIdentifier : rowIdentifierList) {
Map<DBSDataManipulator.ExecuteBatch, Object[]> resultBatches = new LinkedHashMap<>();
DBSDataManipulator dataManipulator = generateUpdateResultsDataBatch(
monitor, resultsInfo, rowIdentifier, updatedRows, deletedRows, addedRows, dataFormat, resultBatches, keyReceiver);


DBCExecutionContext executionContext = getExecutionContext(dataManipulator);
try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.USER, "Update data in container")) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(executionContext);
boolean revertToAutoCommit = false;
boolean isAutoCommitEnabled = true;
DBCSavepoint savepoint = null;
if (txnManager != null) {
isAutoCommitEnabled = txnManager.isAutoCommit();
Expand Down Expand Up @@ -421,6 +426,10 @@ public WebSQLExecuteInfo updateResultsDataBatch(
}
getUpdatedRowsInfo(resultsInfo, newResultSetRows, dataFormat, monitor);

if (!isAutoCommitEnabled) {
sendTransactionalEvent(contextInfo);
}

WebSQLQueryResultSet updatedResultSet = new WebSQLQueryResultSet();
updatedResultSet.setResultsInfo(resultsInfo);
updatedResultSet.setColumns(resultsInfo.getAttributes());
Expand All @@ -437,6 +446,17 @@ public WebSQLExecuteInfo updateResultsDataBatch(
return result;
}

private void sendTransactionalEvent(WebSQLContextInfo contextInfo) {
int count = QMUtils.getTransactionState(getExecutionContext()).getUpdateCount();
webSession.addSessionEvent(
new WSTransactionalCountEvent(
contextInfo.getProjectId(),
contextInfo.getConnectionId(),
count
)
);
}

private void getUpdatedRowsInfo(
@NotNull WebSQLResultsInfo resultsInfo,
@NotNull Set<WebSQLQueryResultSetRow> newResultSetRows,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ public WebSQLExecuteInfo updateResultsDataBatch(
}
}
);
// do event
return result[0];
} catch (DBException e) {
throw new DBWebException("Error updating resultset data", e);
Expand Down