Search in sources :

Example 26 with ClassInfo

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

the class GetAllClassListTask method getClassInfoTaskExcute.

/**
	 * 
	 * Get class information
	 * 
	 */
public void getClassInfoTaskExcute() {
    try {
        if (errorMsg != null && errorMsg.trim().length() > 0) {
            return;
        }
        if (connection == null || connection.isClosed()) {
            errorMsg = Messages.error_getConnection;
            return;
        }
        if (tableName == null) {
            errorMsg = Messages.error_invalidInput;
            return;
        }
        String sql = "SELECT class_name, owner_name, class_type, is_system_class," + " partitioned FROM db_class WHERE class_name=?";
        // [TOOLS-2425]Support shard broker
        if (databaseInfo != null) {
            sql = databaseInfo.wrapShardQuery(sql);
        }
        stmt = connection.prepareStatement(sql);
        ((PreparedStatement) stmt).setString(1, tableName.toLowerCase(Locale.getDefault()));
        rs = ((PreparedStatement) stmt).executeQuery();
        if (rs.next()) {
            String className = rs.getString("class_name");
            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 = new ClassInfo(className, ownerName, type, isSystemClass, isPartitioned);
        }
    } catch (SQLException e) {
        errorMsg = e.getMessage();
    } finally {
        finish();
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ClassType(com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 27 with ClassInfo

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

the class GetAllClassListTask method getAllClassInfoList.

/**
	 * 
	 * Get all class information list
	 * 
	 * @return List<ClassInfo>
	 */
public List<ClassInfo> getAllClassInfoList() {
    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" + " WHERE LOWER(class_name) NOT IN (" + "SELECT LOWER(partition_class_name) FROM db_partition)";
        // [TOOLS-2425]Support shard broker
        if (databaseInfo != null) {
            sql = databaseInfo.wrapShardQuery(sql);
        }
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String className = rs.getString("class_name");
            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);
        }
    } catch (SQLException e) {
        errorMsg = e.getMessage();
    } 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)

Example 28 with ClassInfo

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

the class GetAllClassListTaskTest method testGetAllClassListTaskTest.

public void testGetAllClassListTaskTest() {
    //test getSchema method
    //test normal case
    GetAllClassListTask task = new GetAllClassListTask(databaseInfo);
    List<ClassInfo> allClassInfoList = task.getSchema(false, true);
    boolean found = false;
    for (ClassInfo c : allClassInfoList) {
        if (c.getClassName().equals("_db_attribute")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    task = new GetAllClassListTask(databaseInfo);
    allClassInfoList = task.getSchema(false, false);
    found = false;
    for (ClassInfo c : allClassInfoList) {
        if (c.getClassName().equals("db_attribute")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    //test exception case:connection is closed
    task.getSchema(false, false);
    //test exception case: have error
    task.setErrorMsg("error");
    task.getSchema(false, false);
    //test getAllClassInfoList method
    //test normal case
    task = new GetAllClassListTask(databaseInfo);
    allClassInfoList = task.getAllClassInfoList();
    found = false;
    for (ClassInfo c : allClassInfoList) {
        if (c.getClassName().equals("db_attribute")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    //test exception case:connection is closed
    task.getAllClassInfoList();
    //test exception case: have error
    task.setErrorMsg("error");
    task.getAllClassInfoList();
    //test getClassInfoTaskExcute method
    //test normal case
    task = new GetAllClassListTask(databaseInfo);
    task.setTableName("Db_attribute");
    task.getClassInfoTaskExcute();
    ClassInfo c = task.getClassInfo();
    found = false;
    if (c.getClassName().equals("db_attribute")) {
        found = true;
    }
    assertTrue(found);
    //test exception case:connection is closed
    task.getClassInfoTaskExcute();
    //test exception case: have error
    task.setErrorMsg("error");
    task.getClassInfoTaskExcute();
    //test exception case: no table
    task = new GetAllClassListTask(databaseInfo);
    task.getClassInfoTaskExcute();
}
Also used : ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 29 with ClassInfo

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

the class UserEditor method initial.

/**
	 * 
	 * Initial the data
	 * 
	 */
private void initial() {
    if (ownerClassTableViewer == null || ownerClassTableViewer.getControl() == null || ownerClassTableViewer.getControl().isDisposed()) {
        return;
    }
    if (memberList == null) {
        memberList = new ArrayList<String>();
    }
    while (!memberList.isEmpty()) {
        memberList.remove(0);
    }
    for (DbUserInfo bean : userListInfo.getUserList()) {
        if (bean.getName().equalsIgnoreCase(userName)) {
            userInfo = bean;
        }
        List<String> groups = bean.getGroups().getGroup();
        if (groups != null) {
            for (String g : groups) {
                if (userName != null && userName.equalsIgnoreCase(g)) {
                    memberList.add(bean.getName());
                    break;
                }
            }
        }
    }
    List<String> groupList = userInfo.getGroups().getGroup();
    while (!ownerClassListData.isEmpty()) {
        ownerClassListData.remove(0);
    }
    if (allClassInfoList != null) {
        for (ClassInfo c : allClassInfoList) {
            if (c.getOwnerName().equalsIgnoreCase(userInfo.getName())) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("0", c.getClassName());
                map.put("1", c.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
                map.put("2", c.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
                ownerClassListData.add(map);
            }
        }
    }
    while (!authListData.isEmpty()) {
        authListData.remove(0);
    }
    Map<String, String> classGrantMap = userInfo.getAuthorization();
    Iterator<Map.Entry<String, String>> it = classGrantMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        String className = entry.getKey();
        if (!partitionClassMap.containsKey(className)) {
            String authNum = entry.getValue();
            authListData.add(getItemAuthMap(new ClassAuthorizations(className, CommonUITool.str2Int(authNum))));
        }
    }
    ownerClassTableViewer.refresh();
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
        authTableViewer.refresh();
    }
    for (int i = 0; i < ownerClassTableViewer.getTable().getColumnCount(); i++) {
        ownerClassTableViewer.getTable().getColumn(i).pack();
    }
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
        for (int i = 0; i < authTableViewer.getTable().getColumnCount(); i++) {
            authTableViewer.getTable().getColumn(i).pack();
        }
    }
    StringBuffer sb = new StringBuffer();
    if (groupList != null) {
        for (int i = 0, n = groupList.size(); i < n; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(groupList.get(i));
        }
    }
    lblUserGroup.setText(Messages.bind(Messages.lblGroupList, sb.length() < 1 ? Messages.lblGroupNotExist : sb.toString()));
    sb = new StringBuffer();
    if (memberList != null) {
        for (int i = 0, n = memberList.size(); i < n; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(memberList.get(i));
        }
    }
    lblUserMember.setText(Messages.bind(Messages.lblMemberList, sb.length() < 1 ? Messages.lblMemberNotExist : sb.toString()));
}
Also used : ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) HashMap(java.util.HashMap) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) Map(java.util.Map) HashMap(java.util.HashMap) 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