Search in sources :

Example 1 with UpdateStatisticsTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.UpdateStatisticsTask in project cubrid-manager by CUBRID.

the class UpdateStatisticsAction method run.

public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    // FIXME move this logic to core module
    List<String> sqlList = new ArrayList<String>();
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < obj.length; i++) {
        ISchemaNode schemaNode = (ISchemaNode) obj[i];
        String tableName = schemaNode.getParent().getName();
        int partitionNameLoc = schemaNode.getName().lastIndexOf("__p__");
        if (partitionNameLoc == -1) {
            continue;
        }
        partitionNameLoc += 5;
        String partitionName = schemaNode.getName().substring(partitionNameLoc);
        String sql = "ALTER TABLE " + QuerySyntax.escapeKeyword(tableName) + " ANALYZE PARTITION " + QuerySyntax.escapeKeyword(partitionName);
        sqlList.add(sql);
        buffer.append(",");
        buffer.append(schemaNode.getName());
    }
    String str = buffer.toString().replaceFirst(",", "");
    if (CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmUpdateStatis, str))) {
        DefaultSchemaNode node = (DefaultSchemaNode) obj[0];
        String taskName = Messages.bind(Messages.updateStatisTaskName, node.getName());
        TaskExecutor executor = new CommonTaskExec(taskName);
        UpdateStatisticsTask task = new UpdateStatisticsTask(node.getDatabase().getDatabaseInfo());
        task.setSqlList(sqlList);
        executor.addTask(task);
        new ExecTaskWithProgress(executor).exec();
        if (executor.isSuccess()) {
            CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgSuccessUpdateStatis);
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) UpdateStatisticsTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateStatisticsTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)

Aggregations

DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 UpdateStatisticsTask (com.cubrid.cubridmanager.core.cubrid.table.task.UpdateStatisticsTask)1 ArrayList (java.util.ArrayList)1