Search in sources :

Example 41 with DbUserInfo

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

the class TableLabelProvider method parseURL.

/**
	 * Parse the databases from the url
	 *
	 * @return
	 */
private CubridDatabase parseURL(String url) {
    // FIXME extract
    CubridDatabase database = null;
    String mainParams = null;
    String otherParams = null;
    /*Split the parameter by ?*/
    int questionIndex = url.indexOf("?");
    if (questionIndex > 0) {
        mainParams = url.substring(0, questionIndex);
        if (questionIndex + 1 < url.length()) {
            otherParams = url.substring(questionIndex + 1);
        }
    } else {
        mainParams = url;
    }
    String[] colonParams = mainParams.split(":");
    if (colonParams.length >= 5) {
        String host = colonParams[2];
        String port = colonParams[3];
        String dbName = colonParams[4];
        String dbUser = "", dbPassword = "";
        if (colonParams.length >= 6) {
            dbUser = colonParams[5];
        }
        if (colonParams.length >= 7) {
            dbPassword = colonParams[6];
        }
        String charset = null;
        StringBuilder jdbcAttrSB = new StringBuilder();
        /*Parse the connection parameters*/
        if (otherParams != null) {
            /*find the charset parameter*/
            String[] propertyArray = otherParams.split("&");
            for (int i = 0; i < propertyArray.length; i++) {
                String str = propertyArray[i];
                if (str.toLowerCase().indexOf("charset") >= 0) {
                    int index = str.indexOf("=");
                    if (index >= 0 && index + 1 < str.length()) {
                        charset = str.substring(index + 1);
                        propertyArray[i] = null;
                    }
                }
            }
            /*find other parameters*/
            for (int i = 0; i < propertyArray.length; i++) {
                if (propertyArray[i] != null) {
                    jdbcAttrSB.append(propertyArray[i]);
                }
                if (i + 1 < propertyArray.length && propertyArray[i + 1] != null) {
                    jdbcAttrSB.append("&");
                }
            }
        }
        String connenctionName = host + ":" + port + ":" + dbName + ":" + dbUser;
        ServerInfo serverInfo = new ServerInfo();
        serverInfo.setServerName(connenctionName);
        serverInfo.setHostAddress(host);
        serverInfo.setHostMonPort(Integer.parseInt(port));
        serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
        serverInfo.setUserName(dbName + "@" + host);
        DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
        dbInfo.setBrokerIP(host);
        dbInfo.setBrokerPort(port);
        if (charset != null) {
            dbInfo.setCharSet(charset);
        }
        dbInfo.setJdbcAttrs(jdbcAttrSB.toString());
        DbUserInfo userInfo = new DbUserInfo();
        userInfo.setDbName(dbName);
        userInfo.setName(dbUser);
        userInfo.setNoEncryptPassword(dbPassword);
        dbInfo.setAuthLoginedDbUserInfo(userInfo);
        CubridServer server = new CubridServer(connenctionName, connenctionName, null, null);
        server.setServerInfo(serverInfo);
        server.setType(NodeType.SERVER);
        String dbId = connenctionName + ICubridNodeLoader.NODE_SEPARATOR + connenctionName;
        database = new CubridDatabase(dbId, dbName);
        database.setDatabaseInfo(dbInfo);
        database.setServer(server);
        database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
        database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
        database.setAutoSavePassword(true);
        database.setLabel(connenctionName);
        CubridNodeLoader loader = new CQBDbConnectionLoader();
        loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
        database.setLoader(loader);
    }
    return database;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CubridNodeLoader(com.cubrid.common.ui.spi.model.CubridNodeLoader) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 42 with DbUserInfo

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

the class CubridWorkbenchContrItem method connectDatabaseWithErrMsg.

/**
	 *
	 * Connect the database
	 *
	 * @param dbInfo DatabaseInfo
	 * @return error messages String
	 */
public static String connectDatabaseWithErrMsg(DatabaseInfo dbInfo) {
    // FIXME extract
    if (dbInfo == null || dbInfo.getServerInfo() == null) {
        return "";
    }
    Map<String, String> jdbcVersionMap = CubridJdbcManager.getInstance().getLoadedJdbc();
    if (jdbcVersionMap == null || jdbcVersionMap.get(dbInfo.getServerInfo().getJdbcDriverVersion()) == null) {
        return Messages.errNoSupportDriver;
    }
    CUBRIDConnectionProxy connection = null;
    try {
        connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(dbInfo, false);
        DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
        IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
        checkTask.execute();
        userInfo.setDbaAuthority(checkTask.isDBAUser());
        dbInfo.setLogined(true);
        dbInfo.setRunningType(DbRunningType.CS);
        dbInfo.getServerInfo().setConnected(true);
        dbInfo.setLogined(true);
        return null;
    } catch (SQLException e) {
        return Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage());
    } catch (Exception e) {
        return e.getMessage();
    } finally {
        if (connection != null) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException e) {
                connection = null;
            }
        }
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) SQLException(java.sql.SQLException) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) CUBRIDConnectionProxy(com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy) SQLException(java.sql.SQLException) PartInitException(org.eclipse.ui.PartInitException)

Example 43 with DbUserInfo

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

the class AddProcedureAction method run.

/**
	 * Open AddProcedureDialog
	 */
public void run() {
    // FIXME logic code move to core module
    Shell shell = getShell();
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    ISchemaNode node = (ISchemaNode) obj[0];
    CubridDatabase database = node.getDatabase();
    EditProcedureDialog dlg = new EditProcedureDialog(shell);
    dlg.setDatabase(database);
    dlg.setNewFlag(true);
    ISelectionProvider provider = getSelectionProvider();
    if (dlg.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.SP_FOLDER_ID);
        folderNode = folderNode.getChild(folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.PROCEDURE_FOLDER_ID);
        TreeViewer treeViewer = (TreeViewer) provider;
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        String procedureName = dlg.getProcedureName().toLowerCase(Locale.getDefault());
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + procedureName;
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        SPInfo spInfo = new SPInfo(procedureName);
        spInfo.setOwner(userInfo.getName());
        ICubridNode newNode = CubridProcedureFolderLoader.createProcedureNode(id, spInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) EditProcedureDialog(com.cubrid.common.ui.cubrid.procedure.dialog.EditProcedureDialog) Shell(org.eclipse.swt.widgets.Shell) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SPInfo(com.cubrid.cubridmanager.core.cubrid.sp.model.SPInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 44 with DbUserInfo

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

the class CreateSerialAction method run.

/**
	 * run create serial
	 * @param database
	 */
public void run(CubridDatabase database) {
    CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), true);
    dialog.setDatabase(database);
    ISelectionProvider provider = getSelectionProvider();
    if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
        TreeViewer treeViewer = (TreeViewer) provider;
        ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSerialFolderLoader.SERIAL_FOLDER_ID);
        if (folderNode == null || !folderNode.getLoader().isLoaded()) {
            return;
        }
        // FIXME move this logic to core module
        String serialName = dialog.getSerialName().toLowerCase(Locale.getDefault());
        DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + serialName;
        SerialInfo serialInfo = new SerialInfo();
        serialInfo.setName(serialName);
        serialInfo.setOwner(userInfo.getName());
        ICubridNode newNode = CubridSerialFolderLoader.createSerialNode(id, serialInfo);
        CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
    }
}
Also used : CreateOrEditSerialDialog(com.cubrid.common.ui.cubrid.serial.dialog.CreateOrEditSerialDialog) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) SerialInfo(com.cubrid.common.core.common.model.SerialInfo)

Example 45 with DbUserInfo

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

the class ActionSupportUtil method hasAdminPermission.

/**
	 * Whether having cubrid manager's administrative permissions
	 *
	 * @param obj ISchemaNode or ISchemaNode[]
	 * @return boolean
	 */
public static boolean hasAdminPermission(Object obj) {
    if (!(obj instanceof ISchemaNode)) {
        return false;
    }
    ISchemaNode node = (ISchemaNode) obj;
    CubridServer server = node.getServer();
    if (server == null) {
        return false;
    }
    ServerInfo serverInfo = server.getServerInfo();
    if (serverInfo == null) {
        return false;
    }
    if (!serverInfo.isConnected()) {
        return false;
    }
    ServerUserInfo serverUserInfo = serverInfo.getLoginedUserInfo();
    if (serverUserInfo == null) {
        return false;
    }
    if (serverUserInfo.getDbCreateAuthType() == DbCreateAuthType.AUTH_ADMIN) {
        return true;
    }
    CubridDatabase database = node.getDatabase();
    if (database == null) {
        return false;
    }
    DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    if (dbUserInfo != null && dbUserInfo.isDbaAuthority() && database.isLogined()) {
        return true;
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)80 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)36 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)30 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)16 ArrayList (java.util.ArrayList)14 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)9 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)8 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)7 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)6 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)6 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)6 IsDBAUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask)6 CQBDbConnectionLoader (com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader)6 HashMap (java.util.HashMap)6 CubridNodeLoader (com.cubrid.common.ui.spi.model.CubridNodeLoader)5 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)5