Search in sources :

Example 21 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class CommonSqlExcuteTaskTest method testCommonSqlExcuteTask.

public void testCommonSqlExcuteTask() {
    String tableName = "assdfafa";
    GetAllClassListTask classTask = new GetAllClassListTask(databaseInfo);
    classTask.setTableName(tableName);
    classTask.getClassInfoTaskExcute();
    ClassInfo classInfo = classTask.getClassInfo();
    CommonSQLExcuterTask task1 = new CommonSQLExcuterTask(databaseInfo);
    if (classInfo == null) {
        task1.addSqls("create table " + tableName);
        task1.addCallSqls("call change_owner ('" + tableName + "','public') on class db_authorizations");
    } else {
        task1.addCallSqls("call change_owner ('" + tableName + "','public') on class db_authorizations");
    }
    task1.addSqls("create table " + "tableName");
    task1.addCallSqls("call change_owner ('" + "tableName" + "','public') on class db_authorizations");
    task1.execute();
    //assertEquals(null, task1.getErrorMsg());
    task1 = new CommonSQLExcuterTask(databaseInfo);
    task1.addSqls("drop table assdfafa");
    task1.addSqls("drop table tableName");
    task1.execute();
    System.out.println(task1.getErrorMsg());
    assertEquals(null, task1.getErrorMsg());
    task1.setErrorMsg("err");
    task1.execute();
    final CommonSQLExcuterTask task3 = new CommonSQLExcuterTask(databaseInfo);
    task3.cancel();
    task3.execute();
}
Also used : GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CommonSQLExcuterTask(com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 22 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo 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 23 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class GetInfoDataTask method initDDLText.

/**
	 * Initial DDL text
	 */
private void initDDLText() {
    final StringBuffer sqlScript = new StringBuffer();
    if (!isTable) {
        /*Get class info*/
        GetAllClassListTask getAllClassListTask = new GetAllClassListTask(schemaNode.getDatabase().getDatabaseInfo());
        getAllClassListTask.setTableName(schemaNode.getName());
        getAllClassListTask.getClassInfoTaskExcute();
        /*If failed*/
        if (getAllClassListTask.getErrorMsg() != null || getAllClassListTask.isCancel()) {
            LOGGER.error(getAllClassListTask.getErrorMsg());
            openError(Messages.bind(Messages.titleGetMetaDataErr, schemaNode.getName()), Messages.bind(Messages.msgGetMetaDataErr, schemaNode.getName(), getAllClassListTask.getErrorMsg()));
            return;
        }
        ClassInfo classInfo = getAllClassListTask.getClassInfo();
        /*Get view column*/
        GetViewAllColumnsTask getAllDBVclassTask = new GetViewAllColumnsTask(schemaNode.getDatabase().getDatabaseInfo());
        getAllDBVclassTask.setClassName(schemaNode.getName());
        getAllDBVclassTask.getAllVclassListTaskExcute();
        /*If failed*/
        if (getAllDBVclassTask.getErrorMsg() != null || getAllDBVclassTask.isCancel()) {
            LOGGER.error(getAllDBVclassTask.getErrorMsg());
            openError(Messages.bind(Messages.titleGetMetaDataErr, schemaNode.getName()), Messages.bind(Messages.msgGetMetaDataErr, schemaNode.getName(), getAllClassListTask.getErrorMsg()));
            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);
        }
        /*Get all attribute*/
        GetAllAttrTask getAllAttrTask = new GetAllAttrTask(schemaNode.getDatabase().getDatabaseInfo());
        getAllAttrTask.setClassName(schemaNode.getName());
        getAllAttrTask.getAttrList();
        /*If failed*/
        if (getAllAttrTask.getErrorMsg() != null) {
            LOGGER.error(getAllAttrTask.getErrorMsg());
            openError(Messages.bind(Messages.titleGetMetaDataErr, schemaNode.getName()), Messages.bind(Messages.msgGetMetaDataErr, schemaNode.getName(), getAllClassListTask.getErrorMsg()));
            return;
        }
        List<DBAttribute> attrList = getAllAttrTask.getAllAttrList();
        viewColListData = GetInfoDataUtil.getViewColMapList(attrList);
        sqlScript.append(GetInfoDataUtil.getViewCreateSQLScript(false, schemaNode.getDatabase(), classInfo, schemaNode.getName(), viewColListData, queryListData));
    } else {
        String ddl = SQLGenerateUtils.getCreateSQL(schemaNode);
        sqlScript.append(ddl == null ? "" : ddl);
    }
    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            objectInfoComposite.getSqlText().setText(sqlScript.toString());
        }
    });
}
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) 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 24 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class TableModelTest method testModelClassInfo.

public void testModelClassInfo() {
    ClassInfo bean = new ClassInfo("className");
    bean.setClassName("className");
    assertEquals(bean.getClassName(), "className");
    bean.setOwnerName("ownerName");
    assertEquals(bean.getOwnerName(), "ownerName");
    bean.setClassType(ClassType.NORMAL);
    assertEquals(bean.getClassType(), ClassType.NORMAL);
    bean.setSystemClass(true);
    bean.setPartitionedClass(true);
    assertEquals(bean.isSystemClass(), true);
    assertEquals(bean.isPartitionedClass(), true);
}
Also used : ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 25 with ClassInfo

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo in project cubrid-manager by CUBRID.

the class GetAllClassListTask method getSchema.

/**
	 * Get schema list
	 * 
	 * @param isUserSchema boolean
	 * @param isTable boolean
	 * @return List<ClassInfo>
	 */
public List<ClassInfo> getSchema(boolean isUserSchema, boolean isTable) {
    List<ClassInfo> allClassInfoList = new ArrayList<ClassInfo>();
    try {
        if (errorMsg != null && errorMsg.trim().length() > 0) {
            return allClassInfoList;
        }
        if (connection == null || connection.isClosed()) {
            errorMsg = Messages.error_getConnection;
            return allClassInfoList;
        }
        String sql = "SELECT class_name, owner_name, class_type, is_system_class, partitioned FROM db_class AS a " + "WHERE LOWER(a.class_name) NOT IN (SELECT LOWER(partition_class_name) FROM db_partition)";
        if (isUserSchema) {
            sql += " AND is_system_class='NO'";
        } else {
            sql += " AND is_system_class='YES'";
        }
        if (isTable) {
            sql += " AND class_type='CLASS'";
        } else {
            sql += " AND class_type='VCLASS'";
        }
        if (!isUserSchema) {
            sql += " OR class_name='" + ConstantsUtil.SCHEMA_DESCRIPTION_TABLE + "'";
            sql += " OR class_name='" + ConstantsUtil.CUNITOR_HA_TABLE + "'";
        }
        sql = databaseInfo.wrapShardQuery(sql);
        boolean existSchemaCommentTable = false;
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String className = rs.getString("class_name");
            if (ConstantsUtil.SCHEMA_DESCRIPTION_TABLE.equals(className)) {
                existSchemaCommentTable = true;
            }
            if (isUserSchema && ConstantsUtil.isExtensionalSystemTable(className)) {
                continue;
            }
            String ownerName = rs.getString("owner_name");
            String classType = rs.getString("class_type");
            ClassType type = ClassType.NORMAL;
            if (classType != null && classType.trim().equalsIgnoreCase("VCLASS")) {
                type = ClassType.VIEW;
            }
            String isSystemClazz = rs.getString("is_system_class");
            boolean isSystemClass = false;
            if (isSystemClazz != null && isSystemClazz.trim().equalsIgnoreCase("YES")) {
                isSystemClass = true;
            }
            String partitioned = rs.getString("partitioned");
            boolean isPartitioned = false;
            if (partitioned != null && partitioned.equalsIgnoreCase("YES")) {
                isPartitioned = true;
            }
            ClassInfo classInfo = new ClassInfo(className, ownerName, type, isSystemClass, isPartitioned);
            allClassInfoList.add(classInfo);
        }
        databaseInfo.setSupportTableComment(existSchemaCommentTable);
    //			// for table/column description table (_db_description)
    //			if (existSchemaCommentTable && !isUserSchema && isTable) {
    //				ClassInfo classInfo = new ClassInfo(
    //						ConstantsUtil.SCHEMA_DESCRIPTION_TABLE, "PUBLIC",
    //						ClassType.NORMAL, true, false);
    //				allClassInfoList.add(classInfo);
    //			}
    } catch (SQLException e) {
        errorMsg = e.getMessage();
        LOGGER.error(e.getMessage(), e);
    } finally {
        finish();
    }
    return allClassInfoList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ClassType(com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Aggregations

ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)29 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)10 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)9 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)8 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)7 SQLException (java.sql.SQLException)6 Map (java.util.Map)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 ClassAuthorizations (com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations)5 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)5 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4 ClassType (com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType)4 CreateViewDialog (com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog)3