Skip to content

Commit

Permalink
Fix 2024.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels van de Weem committed Feb 16, 2024
1 parent 8a1278c commit 15cb11c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# SQLServer Backup and Restore Changelog

## [Unreleased]
- Idea 2024.1 compatible ([pending issue](https://youtrack.jetbrains.com/issue/DBE-20026/The-Unsafe-query-Update-statement-without-where-updates-all-table-rows-at-once-message-triggers-incorrectly))

## [1.0.4]
- `Backup & Download` feature is now optional
- File dialogs now show that the files might not be local
- Fix usage of deprecated API
- `Backup & Download` feature is now optional
- File dialogs now show that the files might not be local
- Fix usage of deprecated API
- Increase since-version

## [1.0.3]
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
pluginGroup = dev.niels
pluginName = SQL Server Backup And Restore
# SemVer format -> https://semver.org
pluginVersion = 1.0.4
pluginVersion = 1.0.5

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 233
pluginSinceBuild = 241
pluginUntilBuild =

# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/niels/sqlbackuprestore/action/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications.Bus;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAwareAction;
Expand Down Expand Up @@ -35,6 +36,11 @@ public class Backup extends DumbAwareAction {
"1293598313" // Web
);

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
ApplicationManager.getApplication().invokeLater(() -> {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/niels/sqlbackuprestore/action/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications.Bus;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileChooser.FileChooserFactory;
Expand Down Expand Up @@ -39,6 +40,11 @@
* Triggers backup and then allows downloading the result
*/
public class Download extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
try (var c = QueryHelper.client(e)) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/niels/sqlbackuprestore/action/Group.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package dev.niels.sqlbackuprestore.action;

import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import dev.niels.sqlbackuprestore.query.QueryHelper;
import org.jetbrains.annotations.NotNull;

public class Group extends DefaultActionGroup {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabledAndVisible(QueryHelper.isMssql(e));
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/dev/niels/sqlbackuprestore/action/Restore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications.Bus;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAwareAction;
Expand Down Expand Up @@ -45,6 +46,11 @@
*/
@Slf4j
public class Restore extends DumbAwareAction {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
@SuppressWarnings("resource")
Expand Down Expand Up @@ -89,21 +95,22 @@ public void actionPerformed(@NotNull AnActionEvent e) {
}

private void checkDatabaseInUse(Project project, Client c, String target) throws ExecutionException, InterruptedException {
c.withRows(String.format("SELECT\n" +
" [Session ID] = s.session_id,\n" +
" [User Process] = CONVERT(CHAR(1), s.is_user_process),\n" +
" [Login] = s.login_name,\n" +
" [Application] = ISNULL(s.program_name, N''),\n" +
" [Open Transactions] = ISNULL(r.open_transaction_count,0),\n" +
" [Last Request Start Time] = s.last_request_start_time,\n" +
" [Host Name] = ISNULL(s.host_name, N''),\n" +
" [Net Address] = ISNULL(c.client_net_address, N'')\n" +
"FROM sys.dm_exec_sessions s\n" +
"LEFT OUTER JOIN sys.dm_exec_connections c ON (s.session_id = c.session_id)\n" +
"LEFT OUTER JOIN sys.dm_exec_requests r ON (s.session_id = r.session_id)\n" +
"LEFT OUTER JOIN sys.sysprocesses p ON (s.session_id = p.spid)\n" +
"where db_name(p.dbid) = '%s'\n" +
"ORDER BY s.session_id;", target), (cs, rs) -> {
c.withRows(String.format("""
SELECT
[Session ID] = s.session_id,
[User Process] = CONVERT(CHAR(1), s.is_user_process),
[Login] = s.login_name,
[Application] = ISNULL(s.program_name, N''),
[Open Transactions] = ISNULL(r.open_transaction_count,0),
[Last Request Start Time] = s.last_request_start_time,
[Host Name] = ISNULL(s.host_name, N''),
[Net Address] = ISNULL(c.client_net_address, N'')
FROM sys.dm_exec_sessions s
LEFT OUTER JOIN sys.dm_exec_connections c ON (s.session_id = c.session_id)
LEFT OUTER JOIN sys.dm_exec_requests r ON (s.session_id = r.session_id)
LEFT OUTER JOIN sys.sysprocesses p ON (s.session_id = p.spid)
where db_name(p.dbid) = '%s'
ORDER BY s.session_id;""", target), (cs, rs) -> {
})
.thenCompose(rows -> {
if (!rows.isEmpty() && Messages.YES == invokeAndWait(() -> Messages.showYesNoDialog(project,
Expand Down

0 comments on commit 15cb11c

Please sign in to comment.