Search in sources :

Example 11 with DbUserInfoList

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList in project cubrid-manager by CUBRID.

the class GetUserListTask method getResultModel.

/**
	 * get DbUserInfoList
	 * @return DbUserInfoList
	 */
public DbUserInfoList getResultModel() {
    DbUserInfoList dbUserInfoList = new DbUserInfoList();
    dbUserInfoList.setDbname(databaseInfo.getDbName());
    buildUserInfo(dbUserInfoList);
    finish();
    return dbUserInfoList;
}
Also used : DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)

Example 12 with DbUserInfoList

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList in project cubrid-manager by CUBRID.

the class GetUserListTask method buildUserInfo.

/**
	 * 
	 * Build the database user information
	 * 
	 * @param dbUserInfoList DbUserInfoList
	 * @throws SQLException The exception
	 */
private void buildUserInfo(DbUserInfoList dbUserInfoList) {
    Map<String, String> oidMap = new HashMap<String, String>();
    Map<String, List<String>> groupMap = new HashMap<String, List<String>>();
    String sql = "SELECT db_user, name, groups FROM db_user";
    // [TOOLS-2425]Support shard broker
    sql = databaseInfo.wrapShardQuery(sql);
    try {
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String oidStr = rs.getString(1);
            String name = rs.getString(2);
            CUBRIDResultSetProxy cubridRS = (CUBRIDResultSetProxy) rs;
            Object[] objs = (Object[]) cubridRS.getCollection(3);
            List<String> groups = new ArrayList<String>();
            for (Object obj : objs) {
                if (obj != null && obj.getClass() == CUBRIDOIDProxy.getCUBRIDOIDClass(cubridRS.getJdbcVersion())) {
                    groups.add((new CUBRIDOIDProxy(obj)).getOidString());
                }
            }
            if (name != null) {
                name = name.toLowerCase(Locale.getDefault());
            }
            oidMap.put(oidStr, name);
            groupMap.put(name, groups);
            DbUserInfo dbUserInfo = new DbUserInfo();
            dbUserInfo.setDbName(databaseInfo.getDbName());
            dbUserInfo.setName(name);
            dbUserInfo.addAuthorization(new HashMap<String, String>());
            dbUserInfoList.addUser(dbUserInfo);
        }
    } catch (SQLException ex) {
        errorMsg = ex.getMessage();
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    // get the group user
    if (dbUserInfoList.getUserList() != null) {
        for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
            UserGroup userGroup = userInfo.getGroups();
            if (userGroup == null) {
                userGroup = new UserGroup();
                userInfo.addGroups(userGroup);
            }
            List<String> groupOIDList = groupMap.get(userInfo.getName());
            for (String groupOID : groupOIDList) {
                String groupUser = oidMap.get(groupOID);
                if (groupUser != null) {
                    userInfo.getGroups().addGroup(groupUser);
                }
            }
        }
    }
//get the member user
//		for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
//			List<String> groupNameList = userInfo.getGroupList();
//			for (String groupName : groupNameList) {
//				User groupUser = catalog.getUserByName(groupName);
//				if (groupUser != null) {
//					((CUBRIDUser) groupUser).addMember(user.getName());
//				}
//			}
//		}
}
Also used : CUBRIDResultSetProxy(com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy) CUBRIDOIDProxy(com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) UserGroup(com.cubrid.cubridmanager.core.cubrid.user.model.UserGroup) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ArrayList(java.util.ArrayList) List(java.util.List) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)

Example 13 with DbUserInfoList

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList in project cubrid-manager by CUBRID.

the class UserEditor method loadData.

/**
	 * 
	 * Load data
	 * 
	 * @return <code>true</code> if it is successfully;<code>false</code>
	 *         otherwise
	 */
public boolean loadData() {
    final CommonQueryTask<DbUserInfoList> userTask = new CommonQueryTask<DbUserInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbUserInfoList(), database.getDatabaseInfo().getCharSet());
    userTask.setDbName(database.getName());
    final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo());
    final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo());
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @SuppressWarnings("unchecked")
        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (ITask t : taskList) {
                if (t instanceof GetAllClassListTask) {
                    allClassInfoList = ((GetAllClassListTask) t).getAllClassInfoList();
                } else {
                    t.execute();
                }
                if (t instanceof CommonQueryTask) {
                    userListInfo = ((CommonQueryTask<DbUserInfoList>) t).getResultModel();
                }
                if (t instanceof GetAllPartitionClassTask) {
                    partitionClassMap = ((GetAllPartitionClassTask) t).getPartitionClassMap();
                }
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    initial();
                }
            });
            return Status.OK_STATUS;
        }
    };
    taskJobExecutor.addTask(userTask);
    taskJobExecutor.addTask(classInfoTask);
    taskJobExecutor.addTask(partitionTask);
    String jobName = Messages.viewUserInfoJobName + " - " + userName + "@" + database.getName() + "@" + database.getServer().getName();
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)

Aggregations

DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)13 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)8 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)4 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)4 GetUserListTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask)4 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)3 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)3 GetAllPartitionClassTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)3 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 ITask (com.cubrid.common.core.task.ITask)2 CubridNavigatorView (com.cubrid.common.ui.common.navigator.CubridNavigatorView)2 EditUserDialog (com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog)2 DefaultSchemaNode (com.cubrid.common.ui.spi.model.DefaultSchemaNode)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetUserAuthorizationsTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask)2 SQLException (java.sql.SQLException)2