src/main/java/dev/niels/sqlbackuprestore/action/Backup.java
/**
     * Asks for a (remote) file and backs the selected database up to that file.
     * Must be called on the event thread.
     *
     * @param e the event that triggered the action (the database is retrieved from the action)
     * @param c the connection that should be used for backing up (will be taken over if a backup is being made, close it from the future as well).
     * @return a pair of the connection that should be closed and the file that was being selected. The original connection and null if no file was selected.
     */
Asks for a (remote) file and backs the selected database up to that file.
Must be called on the event thread.

@param e the event that triggered the action (the database is retrieved from the action)
@param c the connection that should be used for backing up (will be taken over if a backup is being made, close it from the future as well).
@return a pair of the connection that should be closed and the file that was being selected. The original connection and null if no file was selected.
Asks for a ( remote ) file and backs the selected database up to that file . Must be called on the event thread . @param e the event that triggered the action ( the database is retrieved from the action ) @param c the connection that should be used for backing up ( will be taken over if a backup is being made close it from the future as well ) . @return a pair of the connection that should be closed and the file that was being selected . The original connection and null if no file was selected .
protected CompletableFuture<FileDialog.RemoteFile> backup(@NotNull AnActionEvent e, Client c) {
        var database = QueryHelper.getDatabase(e);
        if (database.isEmpty()) {
            return CompletableFuture.completedFuture(null);
        }
        var target = FileDialog.chooseFile(database.get().getName() + ".bak", e.getProject(), c, "Backup to file", "Select a file to backup '" + database.get() + "' to", FileDialog.DialogType.SAVE);
        if (target == null) {
            return CompletableFuture.completedFuture(null);
        }
        c.open();
        c.setTitle("Backup " + database.get().getName());
        var future = c.execute("BACKUP DATABASE [" + database.get().getName() + "] TO  DISK = N'" + target.getPath() + "' WITH COPY_ONLY, NOFORMAT, INIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10")
                      .thenApply(c::closeAndReturn)
                      .exceptionally(c::close)
                      .thenApply(x -> target);
        c.addWarningConsumer(p -> {
            if (p.getLeft() == Auditor.MessageType.ERROR) {
                Notifications.Bus.notify(new Notification(Constants.NOTIFICATION_GROUP, "Error occurred", p.getRight(), NotificationType.ERROR));
            }
        });
        new ProgressTask(e.getProject(), "Creating Backup", false, consumer -> {
            c.addWarningConsumer(consumer);
            try {
                future.get();
            } catch (Exception ex) {
            }
        }).queue();
        return future;
    }
protected CompletableFuture < FileDialog . RemoteFile > backup ( @ NotNull AnActionEvent e , Client c ) { var database = QueryHelper . getDatabase ( e ) ; if ( database . isEmpty ( ) ) { return CompletableFuture . completedFuture ( null ) ; } var target = FileDialog . chooseFile ( database . get ( ) . getName ( ) + ".bak" , e . getProject ( ) , c , "Backup to file" , "Select a file to backup '" + database . get ( ) + "' to" , FileDialog . DialogType . SAVE ) ; if ( target == null ) { return CompletableFuture . completedFuture ( null ) ; } c . open ( ) ; c . setTitle ( "Backup " + database . get ( ) . getName ( ) ) ; var future = c . execute ( "BACKUP DATABASE [" + database . get ( ) . getName ( ) + "] TO  DISK = N'" + target . getPath ( ) + "' WITH COPY_ONLY, NOFORMAT, INIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10" ) . thenApply ( c :: closeAndReturn ) . exceptionally ( c :: close ) . thenApply ( x -> target ) ; c . addWarningConsumer ( p -> { if ( p . getLeft ( ) == Auditor . MessageType . ERROR ) { Notifications . Bus . notify ( new Notification ( Constants . NOTIFICATION_GROUP , "Error occurred" , p . getRight ( ) , NotificationType . ERROR ) ) ; } } ) ; new ProgressTask ( e . getProject ( ) , "Creating Backup" , false , consumer -> { c . addWarningConsumer ( consumer ) ; try { future . get ( ) ; } catch ( Exception ex ) { } } ) . queue ( ) ; return future ; }
Asks for a (remote) file and backs the selected database up to that file.
Asks for a ( remote ) file and backs the selected database up to that file .
// Don't really care ;)