Search in sources :

Example 1 with RestoreDbTask

use of com.cubrid.cubridmanager.core.cubrid.database.task.RestoreDbTask in project cubrid-manager by CUBRID.

the class RestoreDatabaseDialog method restoreDb.

/**
	 * 
	 * Restore database
	 * 
	 * 
	 */
private void restoreDb() {
    if (!valid()) {
        return;
    }
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    String databaseName = databaseNameText.getText();
    ServerInfo serverInfo = database.getServer().getServerInfo();
    boolean isLocalServer = serverInfo.isLocalServer();
    RestoreDbTask restoreDbTask = new RestoreDbTask(database.getServer().getServerInfo());
    restoreDbTask.setDbName(databaseName);
    String level = "0";
    String path = "none";
    if (selectBackupButton.getSelection()) {
        if (level0Button.getSelection()) {
            level = "0";
            path = level0Text.getText();
        } else if (level1Button.getSelection()) {
            level = "1";
            path = level1Text.getText();
        } else if (level2Button.getSelection()) {
            level = "2";
            path = level2Text.getText();
        }
        if (!isLocalServer) {
            CheckFileTask checkFileTask = new CheckFileTask(serverInfo);
            checkFileTask.setFile(new String[] { path });
            checkFileTask.putData("filePath", path);
            taskExec.addTask(checkFileTask);
        }
    }
    if (selectTimeButton.getSelection()) {
        if (backupTimeButton.getSelection()) {
            restoreDbTask.setDate("backuptime");
        } else if (restoredDataTimeButton.getSelection()) {
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumIntegerDigits(2);
            String timeStr = nf.format(hourSpn.getSelection()) + ":" + nf.format(minuteSpn.getSelection()) + ":" + nf.format(secondSpn.getSelection());
            String dateStr = nf.format(daySpn.getSelection()) + "-" + nf.format(monthSpn.getSelection()) + "-" + yearSpn.getSelection();
            dateStr += ":" + timeStr;
            restoreDbTask.setDate(dateStr);
        }
    } else {
        restoreDbTask.setDate("none");
    }
    if (!CompatibleUtil.isSupportRestorePath(database.getServer().getServerInfo())) {
        path = "none";
    }
    restoreDbTask.setLevel(level);
    restoreDbTask.setPathName(path);
    if (partialButton.getSelection()) {
        restoreDbTask.setPartial(true);
    } else {
        restoreDbTask.setPartial(false);
    }
    if (dbPathButton == null || !dbPathButton.getSelection()) {
        restoreDbTask.setRecoveryPath("none");
    } else {
        restoreDbTask.setRecoveryPath(dbPathText.getText());
        if (!isLocalServer) {
            CheckDirTask checkDirTask = new CheckDirTask(serverInfo);
            checkDirTask.setDirectory(new String[] { dbPathText.getText() });
            taskExec.addTask(checkDirTask);
        }
    }
    taskExec.addTask(restoreDbTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgRestoreDBRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) RestoreDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.RestoreDbTask) NumberFormat(java.text.NumberFormat)

Aggregations

CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)1 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)1 RestoreDbTask (com.cubrid.cubridmanager.core.cubrid.database.task.RestoreDbTask)1 NumberFormat (java.text.NumberFormat)1