Search in sources :

Example 1 with GetAllClassListTask

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

the class GetSchemaDDLTask method execute.

/**
	 * Execute the tasks
	 */
public void execute() {
    try {
        if (CompatibleUtil.isAfter900(databaseInfo)) {
            String sql = QueryUtil.getShowCreateSQL(schemaName, isTable);
            sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql);
            StringBuilder sb = new StringBuilder();
            if (errorMsg != null && errorMsg.trim().length() > 0) {
                return;
            }
            if (connection == null || connection.isClosed()) {
                errorMsg = Messages.error_getConnection;
                return;
            }
            String viewName = null;
            stmt = connection.createStatement();
            rs = (CUBRIDResultSetProxy) stmt.executeQuery(sql);
            while (rs.next()) {
                if (isTable) {
                    sb.append(rs.getString(2));
                } else {
                    viewName = QuerySyntax.escapeKeyword(rs.getString(1));
                    if (sb.length() > 0) {
                        sb.append(" UNION ALL ");
                    }
                    sb.append(" ").append(rs.getString(2)).append(" ");
                }
            }
            if (isTable) {
                ddl = sb.toString();
            } else {
                ddl = "CREATE OR REPLACE VIEW " + viewName + " AS " + sb.toString() + ";";
            }
        } else {
            StringBuilder sqlScript = new StringBuilder();
            if (!isTable) {
                // Get class info
                GetAllClassListTask getAllClassListTask = new GetAllClassListTask(databaseInfo, connection);
                getAllClassListTask.setTableName(schemaName);
                getAllClassListTask.getClassInfoTaskExcute();
                // If failed
                if (getAllClassListTask.getErrorMsg() != null || getAllClassListTask.isCancel()) {
                    errorMsg = getAllClassListTask.getErrorMsg();
                    LOGGER.error(errorMsg);
                    return;
                }
                /*Check user cancel*/
                if (monitor != null && monitor.isCanceled()) {
                    errorMsg = "The user canceled.";
                    return;
                }
                ClassInfo classInfo = getAllClassListTask.getClassInfo();
                // Get view column
                GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(databaseInfo, connection);
                getAllDBVclassTask.setClassName(schemaName);
                getAllDBVclassTask.getAllVclassListTaskExcute();
                // If failed
                if (getAllDBVclassTask.getErrorMsg() != null || getAllDBVclassTask.isCancel()) {
                    errorMsg = getAllDBVclassTask.getErrorMsg();
                    LOGGER.error(errorMsg);
                    return;
                }
                /*Check user cancel*/
                if (monitor != null && monitor.isCanceled()) {
                    errorMsg = "The user canceled.";
                    return;
                }
                // Get query list
                List<String> vclassList = getAllDBVclassTask.getAllVclassList();
                List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
                for (String sql : vclassList) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("0", sql);
                    queryListData.add(map);
                }
                /*Check user cancel*/
                if (monitor != null && monitor.isCanceled()) {
                    errorMsg = "The user canceled.";
                    return;
                }
                // Get all attribute
                GetAllAttrTask getAllAttrTask = new GetAllAttrTask(databaseInfo, connection);
                getAllAttrTask.setClassName(schemaName);
                getAllAttrTask.getAttrList();
                // If failed
                if (getAllAttrTask.getErrorMsg() != null) {
                    errorMsg = getAllAttrTask.getErrorMsg();
                    LOGGER.error(errorMsg);
                    return;
                }
                List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
                List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
                sqlScript.append(GetInfoDataUtil.getViewCreateSQLScript(false, databaseInfo, classInfo, schemaName, viewColListData, queryListData));
            } else {
                String ddl = SQLGenerateUtils.getCreateSQL(databaseInfo, schemaName);
                sqlScript.append(ddl == null ? "" : ddl);
            }
            ddl = sqlScript.toString();
        }
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
        errorMsg = e.getMessage();
    } finally {
        finish();
        if (StringUtil.isNotEmpty(ddl)) {
            SqlFormattingStrategy formator = new SqlFormattingStrategy();
            String formated = formator.format(ddl);
            ddl = formated;
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) HashMap(java.util.HashMap) Map(java.util.Map) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 2 with GetAllClassListTask

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

the class TableSchemaCompareComposite method getTableSchema.

private String getTableSchema(CubridDatabase db, Map<String, SchemaInfo> schemas, String tableName) {
    // FIXME logic code move to core module
    String tableSchemaInfo = "";
    try {
        SchemaInfo schemaInfo = schemas.get(tableName);
        if (schemaInfo == null) {
            return "";
        }
        if (schemaInfo.getVirtual().equals(ClassType.VIEW.getText())) {
            GetAllClassListTask getAllClassListTask = new GetAllClassListTask(db.getDatabaseInfo());
            getAllClassListTask.setTableName(tableName);
            getAllClassListTask.getClassInfoTaskExcute();
            ClassInfo classInfo = getAllClassListTask.getClassInfo();
            GetAllAttrTask getAllAttrTask = new GetAllAttrTask(db.getDatabaseInfo());
            getAllAttrTask.setClassName(tableName);
            getAllAttrTask.getAttrList();
            List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
            List<Map<String, String>> viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
            /*Get view column*/
            GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(db.getDatabaseInfo());
            getAllDBVclassTask.setClassName(tableName);
            getAllDBVclassTask.getAllVclassListTaskExcute();
            /*Get query list*/
            List<String> vclassList = getAllDBVclassTask.getAllVclassList();
            List<Map<String, String>> queryListData = new ArrayList<Map<String, String>>();
            for (String sql : vclassList) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("0", sql);
                queryListData.add(map);
            }
            tableSchemaInfo = GetInfoDataUtil.getViewCreateSQLScript(true, db, classInfo, tableName, viewColListData, queryListData);
        } else {
            SchemaDDL schemaDDL = null;
            schemaDDL = new SchemaDDL(null, db.getDatabaseInfo());
            tableSchemaInfo = schemaDDL.getSchemaDDL(schemaInfo);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        return "";
    }
    return tableSchemaInfo;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) GetViewAllColumnsTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) HashMap(java.util.HashMap) Map(java.util.Map) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 3 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask 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 4 with GetAllClassListTask

use of com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask 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 5 with GetAllClassListTask

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

the class CubridViewsFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        CubridDatabase database = ((ISchemaNode) parent).getDatabase();
        if (!database.isLogined() || database.getRunningType() == DbRunningType.STANDALONE) {
            database.getDatabaseInfo().setUserViewInfoList(null);
            database.getDatabaseInfo().setSysViewInfoList(null);
            database.getDatabaseInfo().clearSchemas();
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        DatabaseInfo databaseInfo = database.getDatabaseInfo();
        final GetAllClassListTask task = new GetAllClassListTask(databaseInfo);
        monitorCancel(monitor, new ITask[] { task });
        List<ClassInfo> allClassInfoList = task.getSchema(true, false);
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        // add system view folder
        String systemViewFolderId = parent.getId() + NODE_SEPARATOR + SYSTEM_VIEW_FOLDER_ID;
        ICubridNode systemViewFolder = parent.getChild(systemViewFolderId);
        parent.removeAllChild();
        if (systemViewFolder == null) {
            systemViewFolder = new DefaultSchemaNode(systemViewFolderId, SYSTEM_VIEW_FOLDER_NAME, "icons/navigator/folder_sys.png");
            systemViewFolder.setType(NodeType.SYSTEM_VIEW_FOLDER);
            systemViewFolder.setContainer(true);
            ICubridNodeLoader loader = new CubridSystemViewFolderLoader();
            loader.setLevel(getLevel());
            systemViewFolder.setLoader(loader);
            parent.addChild(systemViewFolder);
            if (getLevel() == DEFINITE_LEVEL) {
                systemViewFolder.getChildren(monitor);
            }
        } else {
            parent.addChild(systemViewFolder);
            if (systemViewFolder.getLoader() != null && systemViewFolder.getLoader().isLoaded()) {
                systemViewFolder.getLoader().setLoaded(false);
                systemViewFolder.getChildren(monitor);
            }
        }
        if (allClassInfoList != null) {
            for (ClassInfo classInfo : allClassInfoList) {
                String id = parent.getId() + NODE_SEPARATOR + classInfo.getClassName();
                ICubridNode classNode = createUserViewNode(id, classInfo);
                parent.addChild(classNode);
            }
        }
        database.getDatabaseInfo().setUserViewInfoList(allClassInfoList);
        database.getDatabaseInfo().clearSchemas();
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Aggregations

GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)17 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)7 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)7 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)6 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)5 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)5 GetAllPartitionClassTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)5 ITask (com.cubrid.common.core.task.ITask)4 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 GetUserListTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)3 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)3 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)3 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)3 GetUserAuthorizationsTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask)3