Search in sources :

Example 6 with GetAllAttrTask

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

the class PropertyViewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
    GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
    getAllClassListTask.setTableName(node.getName());
    GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
    getAllDBVclassTask.setClassName(node.getName());
    GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
    getAllAttrTask.setClassName(node.getName());
    JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
    dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
    if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
        return;
    }
    ClassInfo classInfo = getAllClassListTask.getClassInfo();
    List<String> vclassList = getAllDBVclassTask.getAllVclassList();
    List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
    List<String> dbUserList = getAllDbUserTask.getDbUserList();
    dialog.setAttrList(attrList);
    dialog.setClassInfo(classInfo);
    dialog.setVclassList(vclassList);
    dialog.setDbUserList(dbUserList);
    dialog.setPropertyQuery(true);
    dialog.open();
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 7 with GetAllAttrTask

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

the class CreateViewDialog method execTask.

/**
	 * execute the task.
	 *
	 * @param buttonId int
	 * @param tasks ITask[]
	 * @param cancelable boolean
	 * @param shell Shell
	 */
public void execTask(final int buttonId, final ITask[] tasks, boolean cancelable, final Shell shell) {
    if (tasks == null || tasks.length == 0) {
        return;
    }
    TaskExecutor taskExecutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : tasks) {
                if (task instanceof GetAllClassListTask) {
                    ((GetAllClassListTask) task).getClassInfoTaskExcute();
                } else if (task instanceof GetViewAllColumnsTask) {
                    ((GetViewAllColumnsTask) task).getAllVclassListTaskExcute();
                } else if (task instanceof GetAllAttrTask) {
                    ((GetAllAttrTask) task).getAttrList();
                } else {
                    task.execute();
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            return true;
        }
    };
    taskExecutor.setTask(tasks);
    new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
    if (taskExecutor.isSuccess() && buttonId > 0) {
        setReturnCode(buttonId);
        close();
    }
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 8 with GetAllAttrTask

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

the class WorkbenchContrItem method getStmtSQL.

/**
	 * Create select statement SQL
	 *
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
protected String getStmtSQL(DefaultSchemaNode schemaNode) {
    // FIXME move this logic to core module
    if (schemaNode == null) {
        return "";
    }
    CubridDatabase db = schemaNode.getDatabase();
    DatabaseInfo dbInfo = db.getDatabaseInfo();
    GetAllAttrTask task = new GetAllAttrTask(dbInfo);
    task.setClassName(schemaNode.getName());
    task.getAttrList();
    if (task.getErrorMsg() != null) {
        return "";
    }
    List<DBAttribute> allAttrList = task.getAllAttrList();
    return SQLGenerateUtils.getSelectSQLWithLimit(schemaNode.getName(), allAttrList);
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 9 with GetAllAttrTask

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

the class EditViewAction method run.

/**
	 * run edit view
	 * @param ISchemaNode viewNode
	 * @param database CubridDatabase
	 */
public int run(CubridDatabase database, ISchemaNode node) {
    CreateViewDialog dialog = new CreateViewDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), database, false);
    GetAllClassListTask getAllClassListTask = new GetAllClassListTask(database.getDatabaseInfo());
    getAllClassListTask.setTableName(node.getName());
    GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(database.getDatabaseInfo());
    getAllDBVclassTask.setClassName(node.getName());
    GetAllAttrTask getAllAttrTask = new GetAllAttrTask(database.getDatabaseInfo());
    getAllAttrTask.setClassName(node.getName());
    JDBCGetAllDbUserTask getAllDbUserTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo());
    dialog.execTask(-1, new ITask[] { getAllClassListTask, getAllDBVclassTask, getAllAttrTask, getAllDbUserTask }, true, getShell());
    if (getAllClassListTask.getErrorMsg() != null || getAllDBVclassTask.getErrorMsg() != null || getAllAttrTask.getErrorMsg() != null || getAllDbUserTask.getErrorMsg() != null || getAllClassListTask.isCancel() || getAllDBVclassTask.isCancel() || getAllAttrTask.isCancel() || getAllDbUserTask.isCancel()) {
        return IDialogConstants.CANCEL_ID;
    }
    ClassInfo classInfo = getAllClassListTask.getClassInfo();
    List<String> vclassList = getAllDBVclassTask.getAllVclassList();
    List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
    List<String> dbUserList = getAllDbUserTask.getDbUserList();
    dialog.setAttrList(attrList);
    dialog.setClassInfo(classInfo);
    dialog.setVclassList(vclassList);
    dialog.setDbUserList(dbUserList);
    if (dialog.open() == IDialogConstants.OK_ID) {
        String viewName = node.getName();
        String newViewName = dialog.getNewViewName();
        String owner = dialog.getOwner();
        node.getDatabase().getDatabaseInfo().removeSchema(viewName);
        ISelectionProvider provider = getSelectionProvider();
        TreeViewer treeViewer = (TreeViewer) provider;
        if (!viewName.equals(newViewName)) {
            ClassInfo newClassInfo = (ClassInfo) node.getAdapter(ClassInfo.class);
            newClassInfo.setClassName(newViewName);
            newClassInfo.setOwnerName(owner);
            node.setId(node.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newViewName);
            node.setLabel(newViewName);
            treeViewer.refresh(node, true);
        }
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent());
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REFRESH));
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        /*Broadcast the view changed*/
        QueryEditorUtil.fireSchemaNodeChanged(node);
        return IDialogConstants.OK_ID;
    }
    return IDialogConstants.CANCEL_ID;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CreateViewDialog(com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 10 with GetAllAttrTask

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

the class SQLGenerateUtils method getUpdateSQL.

/**
	 * Create update statement SQL
	 * 
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
public static String getUpdateSQL(DefaultSchemaNode schemaNode) {
    StringBuilder sql = new StringBuilder();
    if (schemaNode != null) {
        CubridDatabase db = schemaNode.getDatabase();
        DatabaseInfo dbInfo = db.getDatabaseInfo();
        GetAllAttrTask task = new GetAllAttrTask(dbInfo);
        task.setClassName(schemaNode.getName());
        task.getAttrList();
        if (task.getErrorMsg() != null) {
            return "";
        }
        List<DBAttribute> allAttrList = task.getAllAttrList();
        if (allAttrList == null || allAttrList.size() == 0) {
            return "";
        }
        sql.append("UPDATE ").append(QuerySyntax.escapeKeyword(schemaNode.getName())).append(StringUtil.NEWLINE).append(" SET ").append(StringUtil.NEWLINE);
        for (int i = 0; i < allAttrList.size(); i++) {
            DBAttribute attr = allAttrList.get(i);
            sql.append(" ").append(QuerySyntax.escapeKeyword(attr.getName())).append(" = ?");
            if (i + 1 < allAttrList.size()) {
                sql.append(", ");
            }
            sql.append(StringUtil.NEWLINE);
        }
        sql.append("WHERE ");
        for (int i = 0; i < allAttrList.size(); i++) {
            DBAttribute attr = allAttrList.get(i);
            sql.append(" ").append(QuerySyntax.escapeKeyword(attr.getName())).append(" = ? ");
            if (i + 1 < allAttrList.size()) {
                sql.append(StringUtil.NEWLINE).append("AND");
            }
        }
    }
    return sql.toString();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Aggregations

GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)12 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)10 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)7 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)6 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)6 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)6 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)5 SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CreateViewDialog (com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog)2 JDBCGetAllDbUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 ITask (com.cubrid.common.core.task.ITask)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)1