Skip to content

Commit

Permalink
Merge branch 'devel' into CB-4686-migrate-from-scheduled-touch-sessio…
Browse files Browse the repository at this point in the history
…n-api-call-to-a-websocket-event
  • Loading branch information
yagudin10 authored Mar 19, 2024
2 parents 9b57c04 + d4543ef commit 3204665
Show file tree
Hide file tree
Showing 216 changed files with 3,890 additions and 1,995 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ public void updateAuthProfile(@NotNull DBAAuthProfile profile) {
}

@Override
public void removeAuthProfile(@NotNull DBAAuthProfile profile) {
public void setAuthProfiles(@NotNull Collection<DBAAuthProfile> profiles) {
dataSourceRegistry.setAuthProfiles(profiles);
}

@Override
public void removeAuthProfile(DBAAuthProfile profile) {
dataSourceRegistry.removeAuthProfile(profile);
}

Expand Down
23 changes: 23 additions & 0 deletions server/bundles/io.cloudbeaver.server/schema/service.sql.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SQLContextInfo {
id: ID!
projectId: ID!
connectionId: ID!
autoCommit: Boolean
defaultCatalog: String
defaultSchema: String

Expand Down Expand Up @@ -401,4 +402,26 @@ extend type Mutation {

asyncSqlRowDataCountResult(taskId: ID!): Int!

@since(version: "24.0.1")
asyncSqlSetAutoCommit(
projectId: ID!,
connectionId: ID!,
contextId: ID!,
autoCommit: Boolean!
): AsyncTaskInfo!

@since(version: "24.0.1")
asyncSqlCommitTransaction(
projectId: ID!,
connectionId: ID!,
contextId: ID!
): AsyncTaskInfo!

@since(version: "24.0.1")
asyncSqlRollbackTransaction(
projectId: ID!,
connectionId: ID!,
contextId: ID!
): AsyncTaskInfo!

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.jkiss.dbeaver.model.net.DBWHandlerType;
import org.jkiss.dbeaver.model.net.DBWNetworkHandler;
import org.jkiss.dbeaver.model.net.DBWTunnel;
import org.jkiss.dbeaver.model.net.ssh.SSHImplementation;
import org.jkiss.dbeaver.model.net.ssh.SSHSession;
import org.jkiss.dbeaver.model.rm.RMProjectType;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.secret.DBSSecretController;
Expand Down Expand Up @@ -767,12 +767,11 @@ public WebNetworkEndpointInfo testNetworkHandler(@NotNull WebSession webSession,
tunnel.initializeHandler(monitor, configuration, connectionConfig);
monitor.worked(1);
// Get info
Object implementation = tunnel.getImplementation();
if (implementation instanceof SSHImplementation) {
if (tunnel.getImplementation() instanceof SSHSession session) {
return new WebNetworkEndpointInfo(
"Connected",
((SSHImplementation) implementation).getClientVersion(),
((SSHImplementation) implementation).getServerVersion());
session.getClientVersion(),
session.getServerVersion());
} else {
return new WebNetworkEndpointInfo("Connected");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,22 @@ String generateGroupByQuery(@NotNull WebSQLContextInfo contextInfo,
@Nullable
@WebAction
Long getRowDataCountResult(@NotNull WebSession webSession, @NotNull String taskId) throws DBWebException;

@WebAction
WebAsyncTaskInfo asyncSqlSetAutoCommit(
@NotNull WebSession webSession,
@NotNull WebSQLContextInfo contextInfo,
boolean autoCommit
) throws DBWebException;

@WebAction
WebAsyncTaskInfo asyncSqlRollbackTransaction(
@NotNull WebSession webSession,
@NotNull WebSQLContextInfo contextInfo
) throws DBWebException;

@WebAction
WebAsyncTaskInfo asyncSqlCommitTransaction(
@NotNull WebSession webSession,
@NotNull WebSQLContextInfo sqlContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,27 @@
import io.cloudbeaver.DBWebException;
import io.cloudbeaver.WebAction;
import io.cloudbeaver.WebProjectImpl;
import io.cloudbeaver.model.WebAsyncTaskInfo;
import io.cloudbeaver.model.session.WebAsyncTaskProcessor;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.model.session.WebSessionProvider;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.model.exec.DBCExecutionContextDefaults;
import org.jkiss.dbeaver.model.exec.DBExecUtils;
import org.jkiss.dbeaver.model.exec.*;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.qm.QMTransactionState;
import org.jkiss.dbeaver.model.qm.QMUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
import org.jkiss.dbeaver.model.struct.rdb.DBSSchema;
import org.jkiss.dbeaver.utils.RuntimeUtils;
import org.jkiss.utils.CommonUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -170,4 +177,103 @@ void dispose() {
public WebSession getWebSession() {
return processor.getWebSession();
}


///////////////////////////////////////////////////////
// Transactions

public WebAsyncTaskInfo setAutoCommit(boolean autoCommit) {
DBCExecutionContext context = processor.getExecutionContext();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
WebAsyncTaskProcessor<Boolean> runnable = new WebAsyncTaskProcessor<>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (txnManager != null) {
monitor.beginTask("Change connection auto-commit to " + autoCommit, 1);
try {
monitor.subTask("Change context '" + context.getContextName() + "' auto-commit state");
txnManager.setAutoCommit(monitor, autoCommit);
result = true;
} catch (DBException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}

}
};
return getWebSession().createAndRunAsyncTask("Set auto-commit", runnable);

}

public WebAsyncTaskInfo commitTransaction() {
DBCExecutionContext context = processor.getExecutionContext();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
WebAsyncTaskProcessor<String> runnable = new WebAsyncTaskProcessor<>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (txnManager != null) {
QMTransactionState txnInfo = QMUtils.getTransactionState(context);
try (DBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Commit transaction")) {
txnManager.commit(session);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
result = """
Transaction has been committed
Query count: %s
Duration: %s
""".formatted(
txnInfo.getUpdateCount(),
RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime())
);
}
}
};
return getWebSession().createAndRunAsyncTask("Commit transaction", runnable);
}


public WebAsyncTaskInfo rollbackTransaction() {
DBCExecutionContext context = processor.getExecutionContext();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
WebAsyncTaskProcessor<String> runnable = new WebAsyncTaskProcessor<>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (txnManager != null) {
QMTransactionState txnInfo = QMUtils.getTransactionState(context);
try (DBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Rollback transaction")) {
txnManager.rollback(session, null);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
result = """
Transaction has been rolled back
Query count: %s
Duration: %s
""".formatted(
txnInfo.getUpdateCount(),
RuntimeUtils.formatExecutionTime(System.currentTimeMillis() - txnInfo.getTransactionStartTime())
);
}
}
};

return getWebSession().createAndRunAsyncTask("Rollback transaction", runnable);
}

@Property
public Boolean isAutoCommit() throws DBWebException {
DBCExecutionContext context = processor.getExecutionContext();
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager == null) {
return null;
}
try {
return txnManager.isAutoCommit();
} catch (DBException e) {
throw new DBWebException("Error getting auto-commit parameter from context", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,15 @@ public WebSQLExecuteInfo updateResultsDataBatch(
try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.USER, "Update data in container")) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(executionContext);
boolean revertToAutoCommit = false;
if (txnManager != null && txnManager.isSupportsTransactions() && txnManager.isAutoCommit()) {
txnManager.setAutoCommit(monitor, false);
revertToAutoCommit = true;
boolean isAutoCommitEnabled = true;
DBCSavepoint savepoint = null;
if (txnManager != null) {
isAutoCommitEnabled = txnManager.isAutoCommit();
if (txnManager.isSupportsTransactions() && isAutoCommitEnabled) {
txnManager.setAutoCommit(monitor, false);
savepoint = txnManager.setSavepoint(monitor, null);
revertToAutoCommit = true;
}
}
try {
Map<String, Object> options = Collections.emptyMap();
Expand All @@ -375,17 +381,27 @@ public WebSQLExecuteInfo updateResultsDataBatch(
newResultSetRows.add(new WebSQLQueryResultSetRow(rowValues, null));
}

if (txnManager != null && txnManager.isSupportsTransactions()) {
if (txnManager != null && txnManager.isSupportsTransactions() && isAutoCommitEnabled) {
txnManager.commit(session);
}
} catch (Exception e) {
if (txnManager != null && txnManager.isSupportsTransactions()) {
txnManager.rollback(session, null);
txnManager.rollback(session, savepoint);
}
throw new DBCException("Error persisting data changes", e);
} finally {
if (revertToAutoCommit) {
txnManager.setAutoCommit(monitor, true);
if (txnManager != null) {
if (revertToAutoCommit) {
txnManager.setAutoCommit(monitor, true);
}
try {
if (savepoint != null) {
txnManager.releaseSavepoint(monitor, savepoint);
}
} catch (Throwable e) {
// Maybe savepoints not supported
log.debug("Can't release savepoint", e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,23 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
getService(env).getRowDataCountResult(
getWebSession(env),
env.getArgument("taskId")
)
);
))
.dataFetcher("asyncSqlSetAutoCommit", env ->
getService(env).asyncSqlSetAutoCommit(
getWebSession(env),
getSQLContext(env),
env.getArgument("autoCommit")
))
.dataFetcher("asyncSqlCommitTransaction", env ->
getService(env).asyncSqlCommitTransaction(
getWebSession(env),
getSQLContext(env)
))
.dataFetcher("asyncSqlRollbackTransaction", env ->
getService(env).asyncSqlRollbackTransaction(
getWebSession(env),
getSQLContext(env)
));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.jkiss.dbeaver.model.sql.registry.SQLGeneratorConfigurationRegistry;
import org.jkiss.dbeaver.model.sql.registry.SQLGeneratorDescriptor;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSWrapper;
import org.jkiss.dbeaver.utils.RuntimeUtils;
Expand Down Expand Up @@ -579,4 +578,19 @@ public Long getRowDataCountResult(@NotNull WebSession webSession, @NotNull Strin
return null;
}

@Override
public WebAsyncTaskInfo asyncSqlSetAutoCommit(@NotNull WebSession webSession, @NotNull WebSQLContextInfo contextInfo, boolean autoCommit) throws DBWebException {
return contextInfo.setAutoCommit(autoCommit);
}

@Override
public WebAsyncTaskInfo asyncSqlRollbackTransaction(@NotNull WebSession webSession, @NotNull WebSQLContextInfo contextInfo) throws DBWebException {
return contextInfo.rollbackTransaction();
}

@Override
public WebAsyncTaskInfo asyncSqlCommitTransaction(@NotNull WebSession webSession, @NotNull WebSQLContextInfo contextInfo) {
return contextInfo.commitTransaction();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { ComponentStyle } from '@cloudbeaver/core-theming';

import type { IRouteParams } from './IRouteParams';

export enum AdministrationItemType {
Expand All @@ -24,7 +22,6 @@ export interface AdministrationItemDrawerProps {
item: IAdministrationItem;
configurationWizard: boolean;
onSelect: (id: string) => void;
style: ComponentStyle;
disabled?: boolean;
}
export type AdministrationItemDrawerComponent = React.FunctionComponent<AdministrationItemDrawerProps>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.treeNodeNestedMessage {
composes: theme-typography--caption from global;
padding: 4px 12px;
padding: 1px 12px;
}
1 change: 1 addition & 0 deletions webapp/packages/core-blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export * from './useActivationDelay';
export * from './useAdministrationSettings';
export * from './useInterval';
export * from './useStyles';
export * from './useSuspense';
export * from './BlocksLocaleService';
export * from './Snackbars/NotificationMark';
export * from './Snackbars/SnackbarMarkups/SnackbarWrapper';
Expand Down
Loading

0 comments on commit 3204665

Please sign in to comment.