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 1084 transactions #2449

Merged
merged 38 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b0f921a
CB-4806 transactions api
yagudin10 Mar 4, 2024
c2e081d
CB-1084 add commit mode plugin
devnaumov Mar 5, 2024
0ebf7e9
CB-1084 rename plugin
devnaumov Mar 5, 2024
a045360
Merge branch 'devel' into CB-1084-transactions
devnaumov Mar 5, 2024
cb42abf
CB-4806 add is auto commit property to web context
yagudin10 Mar 5, 2024
b210c75
CB-1084 add gql queries
devnaumov Mar 6, 2024
a1ed2ad
Merge remote-tracking branch 'origin/devel' into CB-1084-transactions
yagudin10 Mar 6, 2024
fa09481
CB-1084 add loaders
devnaumov Mar 6, 2024
a052b1a
Merge branch 'CB-1084-transactions' of https://github.com/dbeaver/clo…
devnaumov Mar 6, 2024
9ef63b0
CB-4806 transactions for update results
yagudin10 Mar 6, 2024
85c072e
Merge remote-tracking branch 'origin/CB-1084-transactions' into CB-10…
yagudin10 Mar 6, 2024
a8e6696
CB-4806 fix text
yagudin10 Mar 6, 2024
2e32dd6
CB-1084 pass execution context via extensions
devnaumov Mar 7, 2024
86ea375
CB-1084 handle errors
devnaumov Mar 7, 2024
d21fbfd
CB-1084 get connection before the task execution
devnaumov Mar 7, 2024
0069a3d
CB-1084 grab connection from transaction context
devnaumov Mar 7, 2024
ad9dc5c
Merge branch 'devel' into CB-1084-transactions
devnaumov Mar 8, 2024
03ed2f0
CB-1084 support execution context provider for the object viewer
devnaumov Mar 11, 2024
a71c8e5
CB-1084 refresh context manually
devnaumov Mar 11, 2024
6430617
CB-1084 check options panel status
devnaumov Mar 11, 2024
2404c46
CB-1084 move transaction logic to the ConnectionExecutionContext
devnaumov Mar 11, 2024
08c308e
CB-4806 make project id required
yagudin10 Mar 12, 2024
46d3fb0
Merge branch 'devel' into CB-1084-transactions
devnaumov Mar 12, 2024
2f2e35f
CB-1084 make actions naming more unique
devnaumov Mar 12, 2024
d5708f1
CB-1084 remove success flag
devnaumov Mar 12, 2024
c2fc994
CB-1084 add plugin to default product
devnaumov Mar 12, 2024
cbdd9f4
Merge branch 'devel' into CB-1084-transactions
EvgeniaBzzz Mar 13, 2024
97d194c
Merge branch 'devel' into CB-1084-transactions
EvgeniaBzzz Mar 14, 2024
9e1d384
CB-1084 show confirm dialog
devnaumov Mar 14, 2024
687c67a
Merge branch 'devel' into CB-1084-transactions
EvgeniaBzzz Mar 14, 2024
e4ab4f5
CB-1084 always fire disconnect through executor
devnaumov Mar 14, 2024
80423e7
Merge branch 'CB-1084-transactions' of https://github.com/dbeaver/clo…
devnaumov Mar 14, 2024
1c6beab
CB-1084 adjust behaviour
devnaumov Mar 14, 2024
ecfffce
Merge branch 'devel' into CB-1084-transactions
EvgeniaBzzz Mar 15, 2024
0dd614c
CB-1084 add more explicit check
devnaumov Mar 15, 2024
52281f5
Merge branch 'CB-1084-transactions' of https://github.com/dbeaver/clo…
devnaumov Mar 15, 2024
be12770
CB-1084 interrupt disconnect if commit fails
devnaumov Mar 15, 2024
e440e32
Merge branch 'devel' into CB-1084-transactions
EvgeniaBzzz Mar 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import { computed, makeObservable, observable } from 'mobx';

import type { ITask, TaskScheduler } from '@cloudbeaver/core-executor';
import type { AsyncTaskInfoService, GraphQLService } from '@cloudbeaver/core-sdk';
import { ASYNC_TASK_STATUS_FINISHED, AsyncTaskInfo, type AsyncTaskInfoService, type GraphQLService } from '@cloudbeaver/core-sdk';

import type { ConnectionExecutionContextResource, IConnectionExecutionContextInfo } from './ConnectionExecutionContextResource';
import type { IConnectionExecutionContext } from './IConnectionExecutionContext';

const DEFAULT_AUTO_COMMIT = true;
export interface IConnectionExecutionContextUpdateTaskInfo {
success: boolean;
name?: string;
result?: string | boolean;
}

export class ConnectionExecutionContext implements IConnectionExecutionContext {
get context(): IConnectionExecutionContextInfo | undefined {
Expand All @@ -28,12 +32,12 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
return this.currentTask?.cancellable || false;
}

get currentCommitMode() {
if (this.context) {
return this.context.autoCommit ?? DEFAULT_AUTO_COMMIT;
get autoCommit() {
if (!this.context) {
return;
}

return DEFAULT_AUTO_COMMIT;
return this.context.autoCommit;
}

private currentTask: ITask<any> | null;
Expand All @@ -51,7 +55,7 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
context: computed,
executing: computed,
cancellable: computed,
currentCommitMode: computed,
autoCommit: computed,
});
}

Expand Down Expand Up @@ -91,10 +95,11 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
return await this.connectionExecutionContextResource.update(this.contextId, defaultCatalog, defaultSchema);
}

async setAutoCommit(auto: boolean) {
async setAutoCommit(auto: boolean): Promise<IConnectionExecutionContextUpdateTaskInfo> {
const result = await this.withContext(async context => {
const task = this.asyncTaskInfoService.create(async () => {
const { taskInfo } = await this.graphQLService.sdk.asyncSqlSetAutoCommit({
projectId: context.projectId,
connectionId: context.connectionId,
contextId: context.id,
autoCommit: auto,
Expand All @@ -110,13 +115,14 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
);
});

return result;
return mapAsyncTaskInfo(result);
}

async commit() {
async commit(): Promise<IConnectionExecutionContextUpdateTaskInfo> {
const result = await this.withContext(async context => {
const task = this.asyncTaskInfoService.create(async () => {
const { taskInfo } = await this.graphQLService.sdk.asyncSqlCommitTransaction({
projectId: context.projectId,
connectionId: context.connectionId,
contextId: context.id,
});
Expand All @@ -131,13 +137,14 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
);
});

return result;
return mapAsyncTaskInfo(result);
}

async rollback() {
async rollback(): Promise<IConnectionExecutionContextUpdateTaskInfo> {
const result = await this.withContext(async context => {
const task = this.asyncTaskInfoService.create(async () => {
const { taskInfo } = await this.graphQLService.sdk.asyncSqlRollbackTransaction({
projectId: context.projectId,
connectionId: context.connectionId,
contextId: context.id,
});
Expand All @@ -152,7 +159,7 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
);
});

return result;
return mapAsyncTaskInfo(result);
}

private withContext<R>(callback: (context: IConnectionExecutionContextInfo) => Promise<R>): Promise<R> {
Expand All @@ -163,3 +170,11 @@ export class ConnectionExecutionContext implements IConnectionExecutionContext {
return callback(this.context);
}
}

function mapAsyncTaskInfo(info: AsyncTaskInfo): IConnectionExecutionContextUpdateTaskInfo {
return {
success: info.status === ASYNC_TASK_STATUS_FINISHED && !info.error,
Wroud marked this conversation as resolved.
Show resolved Hide resolved
name: info.name,
result: info.taskResult,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
export const ASYNC_TASK_STATUS_FINISHED = 'Finished';
1 change: 1 addition & 0 deletions webapp/packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './AsyncTask/AsyncTask';
export * from './AsyncTask/AsyncTaskInfoService';
export * from './AsyncTask/ASYNC_TASK_STATUS_FINISHED';
export * from './Extensions/uploadBlobResultSetExtension';
export * from './CustomGraphQLClient';
export * from './DetailsError';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation asyncSqlCommitTransaction($projectId: ID, $connectionId: ID!, $contextId: ID!) {
mutation asyncSqlCommitTransaction($projectId: ID!, $connectionId: ID!, $contextId: ID!) {
taskInfo: asyncSqlCommitTransaction(projectId: $projectId, connectionId: $connectionId, contextId: $contextId) {
...AsyncTaskInfo
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation asyncSqlRollbackTransaction($projectId: ID, $connectionId: ID!, $contextId: ID!) {
mutation asyncSqlRollbackTransaction($projectId: ID!, $connectionId: ID!, $contextId: ID!) {
taskInfo: asyncSqlRollbackTransaction(projectId: $projectId, connectionId: $connectionId, contextId: $contextId) {
...AsyncTaskInfo
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mutation asyncSqlSetAutoCommit($projectId: ID, $connectionId: ID!, $contextId: ID!, $autoCommit: Boolean!) {
mutation asyncSqlSetAutoCommit($projectId: ID!, $connectionId: ID!, $contextId: ID!, $autoCommit: Boolean!) {
taskInfo: asyncSqlSetAutoCommit(projectId: $projectId, connectionId: $connectionId, contextId: $contextId, autoCommit: $autoCommit) {
...AsyncTaskInfo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import {
ConnectionExecutionContextService,
ConnectionInfoResource,
createConnectionParam,
IConnectionExecutionContextUpdateTaskInfo,
} from '@cloudbeaver/core-connections';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import type { AsyncTaskInfo } from '@cloudbeaver/core-sdk';
import { OptionsPanelService } from '@cloudbeaver/core-ui';
import { ActionService, MenuService } from '@cloudbeaver/core-view';
import { ConnectionSchemaManagerService } from '@cloudbeaver/plugin-datasource-context-switch';
import { MENU_APP_ACTIONS } from '@cloudbeaver/plugin-top-app-bar';

import { ACTION_COMMIT } from './actions/ACTION_COMMIT';
import { ACTION_COMMIT_MODE_TOGGLE } from './actions/ACTION_COMMIT_MODE_TOGGLE';
import { ACTION_ROLLBACK } from './actions/ACTION_ROLLBACK';
import { ACTION_DATASOURCE_TRANSACTION_COMMIT } from './actions/ACTION_DATASOURCE_TRANSACTION_COMMIT';
import { ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE } from './actions/ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE';
import { ACTION_DATASOURCE_TRANSACTION_ROLLBACK } from './actions/ACTION_DATASOURCE_TRANSACTION_ROLLBACK';

@injectable()
export class TransactionManagerBootstrap extends Bootstrap {
Expand All @@ -42,26 +42,40 @@ export class TransactionManagerBootstrap extends Bootstrap {
register() {
this.menuService.addCreator({
menus: [MENU_APP_ACTIONS],
isApplicable: () =>
!this.optionsPanelService.active &&
this.connectionSchemaManagerService.currentConnection?.connected === true &&
this.connectionSchemaManagerService.activeExecutionContext !== undefined,
getItems: (_, items) => [...items, ACTION_COMMIT, ACTION_ROLLBACK, ACTION_COMMIT_MODE_TOGGLE],
isApplicable: () => {
const transaction = this.getContextTransaction();

return (
!this.optionsPanelService.active &&
this.connectionSchemaManagerService.currentConnection?.connected === true &&
transaction?.context !== undefined &&
transaction.autoCommit !== undefined
);
},
getItems: (_, items) => [
...items,
ACTION_DATASOURCE_TRANSACTION_COMMIT,
ACTION_DATASOURCE_TRANSACTION_ROLLBACK,
ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE,
],
});

this.actionService.addHandler({
id: 'commit-mode-base',
isActionApplicable: (_, action) => [ACTION_COMMIT, ACTION_ROLLBACK, ACTION_COMMIT_MODE_TOGGLE].includes(action),
isLabelVisible: (_, action) => action === ACTION_COMMIT || action === ACTION_ROLLBACK,
isActionApplicable: (_, action) =>
[ACTION_DATASOURCE_TRANSACTION_COMMIT, ACTION_DATASOURCE_TRANSACTION_ROLLBACK, ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE].includes(
action,
),
isLabelVisible: (_, action) => action === ACTION_DATASOURCE_TRANSACTION_COMMIT || action === ACTION_DATASOURCE_TRANSACTION_ROLLBACK,
getActionInfo: (_, action) => {
const transaction = this.getContextTransaction();

if (!transaction) {
return action.info;
}

if (action === ACTION_COMMIT_MODE_TOGGLE) {
const auto = transaction.currentCommitMode;
if (action === ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE) {
const auto = transaction.autoCommit;
const icon = `/icons/commit_mode_${auto ? 'auto' : 'manual'}_m.svg`;
const label = `plugin_datasource_transaction_manager_commit_mode_switch_to_${auto ? 'manual' : 'auto'}`;
sergeyteleshev marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -81,8 +95,8 @@ export class TransactionManagerBootstrap extends Bootstrap {
return true;
}

if (action === ACTION_COMMIT || action === ACTION_ROLLBACK) {
return transaction.currentCommitMode;
if (action === ACTION_DATASOURCE_TRANSACTION_COMMIT || action === ACTION_DATASOURCE_TRANSACTION_ROLLBACK) {
return transaction.autoCommit === true;
}

return false;
Expand All @@ -95,7 +109,7 @@ export class TransactionManagerBootstrap extends Bootstrap {
}

switch (action) {
case ACTION_COMMIT: {
case ACTION_DATASOURCE_TRANSACTION_COMMIT: {
try {
const result = await transaction.commit();
this.showTransactionResult(transaction, result);
Expand All @@ -105,7 +119,7 @@ export class TransactionManagerBootstrap extends Bootstrap {

break;
}
case ACTION_ROLLBACK: {
case ACTION_DATASOURCE_TRANSACTION_ROLLBACK: {
try {
const result = await transaction.rollback();
this.showTransactionResult(transaction, result);
Expand All @@ -115,34 +129,30 @@ export class TransactionManagerBootstrap extends Bootstrap {

break;
}
case ACTION_COMMIT_MODE_TOGGLE:
case ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE:
try {
await transaction.setAutoCommit(!transaction.currentCommitMode);
await transaction.setAutoCommit(!transaction.autoCommit);
await this.connectionExecutionContextResource.refresh();
} catch (exception: any) {
this.notificationService.logException(exception, 'plugin_datasource_transaction_manager_commit_mode_fail');
}

break;
default:
break;
sergeyteleshev marked this conversation as resolved.
Show resolved Hide resolved
}
},
});
}

load() {}

private showTransactionResult(transaction: ConnectionExecutionContext, taskInfo: AsyncTaskInfo) {
private showTransactionResult(transaction: ConnectionExecutionContext, info: IConnectionExecutionContextUpdateTaskInfo) {
if (!transaction.context) {
return;
}

const connectionParam = createConnectionParam(transaction.context.projectId, transaction.context.connectionId);
const connection = this.connectionInfoResource.get(connectionParam);
const message = typeof taskInfo.taskResult === 'string' ? taskInfo.taskResult : '';
const message = typeof info.result === 'string' ? info.result : '';

this.notificationService.logInfo({ title: connection?.name ?? taskInfo.name ?? '', message });
this.notificationService.logInfo({ title: connection?.name ?? info.name ?? '', message });
}

private getContextTransaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { createAction } from '@cloudbeaver/core-view';

export const ACTION_COMMIT = createAction('commit', {
export const ACTION_DATASOURCE_TRANSACTION_COMMIT = createAction('datasource-transaction-commit', {
label: 'plugin_datasource_transaction_manager_commit',
tooltip: 'plugin_datasource_transaction_manager_commit',
icon: '/icons/commit_m.svg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { createAction } from '@cloudbeaver/core-view';

export const ACTION_COMMIT_MODE_TOGGLE = createAction('commit-mode-toggle', {
export const ACTION_DATASOURCE_TRANSACTION_COMMIT_MODE_TOGGLE = createAction('datasource-transaction-commit-mode-toggle', {
label: 'plugin_datasource_transaction_manager_commit_mode_switch_to_manual',
tooltip: 'plugin_datasource_transaction_manager_commit_mode_switch_to_manual',
icon: '/icons/commit_mode_auto_m.svg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { createAction } from '@cloudbeaver/core-view';

export const ACTION_ROLLBACK = createAction('rollback', {
export const ACTION_DATASOURCE_TRANSACTION_ROLLBACK = createAction('datasource-transaction-rollback', {
label: 'plugin_datasource_transaction_manager_rollback',
tooltip: 'plugin_datasource_transaction_manager_rollback',
icon: '/icons/rollback_m.svg',
Expand Down
Loading