Search in sources :

Example 71 with ServerInfo

use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.

the class EditHostAction method checkServerChanges.

/**
	 * Check whether the two server changes
	 * 
	 * @param server1
	 * @param server2
	 * @return
	 */
public boolean checkServerChanges(CubridServer server1, CubridServer server2) {
    if (server1 == null || server2 == null) {
        LOGGER.error("server1={}, server2={}", server1, server2);
        return false;
    }
    ServerInfo serverInfo1 = server1.getServerInfo();
    ServerInfo serverInfo2 = server2.getServerInfo();
    if (serverInfo1 == null || serverInfo2 == null) {
        LOGGER.error("serverInfo1={}, serverInfo2={}", serverInfo1, serverInfo2);
        return false;
    }
    boolean equalServerName = StringUtil.isEqual(serverInfo1.getServerName(), serverInfo2.getServerName());
    boolean equalHostAddress = StringUtil.isEqual(serverInfo1.getHostAddress(), serverInfo2.getHostAddress());
    boolean equalHostPort = serverInfo1.getHostMonPort() == serverInfo2.getHostMonPort();
    boolean equalJdbcVersion = StringUtil.isEqual(serverInfo1.getJdbcDriverVersion(), serverInfo2.getJdbcDriverVersion());
    boolean equalUserName = StringUtil.isEqual(serverInfo1.getUserName(), serverInfo2.getUserName());
    boolean equalPassword = StringUtil.isEqual(serverInfo2.getUserPassword(), serverInfo1.getUserPassword());
    boolean equalAutoSave = server1.isAutoSavePassword() == server2.isAutoSavePassword();
    return !(equalServerName && equalHostAddress && equalHostPort && equalJdbcVersion && equalUserName && equalPassword && equalAutoSave);
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo)

Example 72 with ServerInfo

use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.

the class EditHostAction method doRun.

/**
	 * Perform do run
	 * 
	 * @param obj
	 */
public void doRun(CubridServer[] servers, boolean actionIsConnect) {
    //multi edit
    if (servers.length > 1) {
        MultiHostEditDialog dialog = new MultiHostEditDialog(getShell(), Arrays.asList(servers));
        if (dialog.open() != MultiHostEditDialog.SAVE_ID) {
            return;
        }
        BrokerIntervalSettingManager brokerManager = BrokerIntervalSettingManager.getInstance();
        //new server infolist
        List<CubridServer> newServerInfoList = dialog.getNewServerList();
        for (int i = 0; i < servers.length; i++) {
            CubridServer newServer = newServerInfoList.get(i);
            CubridServer server = servers[i];
            if (server == null) {
                continue;
            }
            // if the server is not changed, ignore it.
            if (!checkServerChanges(newServer, server)) {
                continue;
            }
            ServerInfo oldServerInfo = server.getServerInfo();
            if (oldServerInfo == null) {
                LOGGER.error("oldServerInfo is null.");
                continue;
            }
            ServerInfo newServerInfo = newServer.getServerInfo();
            if (newServerInfo == null) {
                LOGGER.error("newServerInfo is null.");
                continue;
            }
            if (!newServerInfo.getServerName().equals(server.getLabel())) {
                QueryOptions.removePref(server.getServerInfo());
                brokerManager.removeAllBrokerIntervalSettingInServer(server.getLabel());
            }
            if (oldServerInfo.isConnected()) {
                HostUtils.processHostDisconnected(server);
            }
            server.setAutoSavePassword(newServer.isAutoSavePassword());
            server.getServerInfo().setServerName(newServerInfo.getServerName());
            server.getServerInfo().setHostAddress(newServerInfo.getHostAddress());
            server.getServerInfo().setHostMonPort(newServerInfo.getHostMonPort());
            server.getServerInfo().setJdbcDriverVersion(newServerInfo.getJdbcDriverVersion());
            server.getServerInfo().setUserName(newServerInfo.getUserName());
            if (newServer.isAutoSavePassword()) {
                server.getServerInfo().setUserPassword(newServerInfo.getUserPassword());
            } else {
                server.getServerInfo().setUserPassword(null);
            }
            server.setId(newServerInfo.getServerName());
            server.setLabel(newServerInfo.getServerName());
            CMHostNodePersistManager.getInstance().addServer(newServerInfo.getHostAddress(), newServerInfo.getHostMonPort(), newServerInfo.getUserName(), newServerInfo);
            CMGroupNodePersistManager.getInstance().saveAllGroupNode();
            CMHostNodePersistManager.getInstance().saveServers();
            if (server.getLoader() != null) {
                server.getLoader().setLoaded(false);
            }
            CubridWorkbenchContrItem.closeAllEditorAndViewInServer(server, false);
            CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
            if (navigatorView != null) {
                navigatorView.getViewer().refresh(server, true);
            }
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_DISCONNECTED));
        }
        return;
    }
    // single edit
    HostDialog dialog = new HostDialog(getShell(), false, actionIsConnect);
    CubridServer server = null;
    try {
        server = servers[0];
        //read it from hostgroup preference first
        if (server.getParent() == null) {
            CMGroupNodePersistManager.getInstance();
        }
    } catch (ClassCastException cce) {
        CubridGroupNode node = (CubridGroupNode) getSelectedObj()[0];
        for (ICubridNode icNode : node.getChildren()) {
            if (icNode instanceof CubridServer) {
                if (!((CubridServer) icNode).isConnected())
                    server = (CubridServer) icNode;
            }
        }
    }
    ServerInfo oldServerInfo = server.getServerInfo();
    if (oldServerInfo == null) {
        LOGGER.error("oldServerInfo is null.");
        return;
    }
    dialog.setServer(server);
    int returnCode = dialog.open();
    if (returnCode != HostDialog.SAVE_ID && returnCode != HostDialog.CONNECT_ID) {
        return;
    }
    // Save the server info
    ServerInfo serverInfo = dialog.getServerInfo();
    if (serverInfo == null) {
        LOGGER.error("serverInfo is null.");
        return;
    }
    if (!serverInfo.getServerName().equals(server.getLabel())) {
        QueryOptions.removePref(server.getServerInfo());
        BrokerIntervalSettingManager.getInstance().removeAllBrokerIntervalSettingInServer(server.getLabel());
    }
    if (oldServerInfo.isConnected() && !oldServerInfo.equals(serverInfo)) {
        HostUtils.processHostDisconnected(server);
    }
    server.setId(serverInfo.getServerName());
    server.setLabel(serverInfo.getServerName());
    server.setServerInfo(serverInfo);
    server.setAutoSavePassword(dialog.isSavePassword());
    CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
    // Refresh the tree node
    if (returnCode == HostDialog.CONNECT_ID) {
        ISelectionProvider provider = getSelectionProvider();
        if (provider instanceof TreeViewer) {
            server.removeAllChild();
            if (server.getLoader() != null) {
                server.getLoader().setLoaded(false);
            }
            TreeViewer treeViewer = (TreeViewer) provider;
            treeViewer.refresh(server, true);
            treeViewer.expandToLevel(server, 1);
            treeViewer.setSelection(null, true);
            treeViewer.setSelection(new StructuredSelection(server), true);
            setEnabled(false);
        }
    }
    CMGroupNodePersistManager.getInstance().saveAllGroupNode();
    CMHostNodePersistManager.getInstance().saveServers();
    ActionManager.getInstance().fireSelectionChanged(getSelection());
    LayoutManager.getInstance().fireSelectionChanged(getSelection());
    CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
}
Also used : BrokerIntervalSettingManager(com.cubrid.cubridmanager.ui.broker.editor.internal.BrokerIntervalSettingManager) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) MultiHostEditDialog(com.cubrid.cubridmanager.ui.host.dialog.MultiHostEditDialog) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) HostDialog(com.cubrid.cubridmanager.ui.host.dialog.HostDialog)

Example 73 with ServerInfo

use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.

the class ExportHAConfigAction method isSupported.

/**
	 * 
	 * Return whether this action support this object,if not support,this action
	 * will be disabled
	 * 
	 * @param obj the Object
	 * @return <code>true</code> if support this obj;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (obj instanceof CubridServer) {
        CubridServer server = (CubridServer) obj;
        ServerInfo serverInfo = server.getServerInfo();
        if (!CompatibleUtil.isSupportNewHAConfFile(serverInfo)) {
            return false;
        }
        ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
        if (userInfo == null || CasAuthType.AUTH_ADMIN != userInfo.getCasAuth()) {
            return false;
        }
        return true;
    }
    return false;
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 74 with ServerInfo

use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.

the class ERSchemaEditor method syncComments.

/**
	 * sync table comments to db tables.
	* 
	* @return void
	 */
public void syncComments() {
    DatabaseInfo info = database.getDatabaseInfo();
    if (info == null) {
        CommonUITool.openErrorBox(Messages.errNoDatabase);
        return;
    }
    if (!info.isLogined()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    ServerInfo serverInfo = info.getServerInfo();
    if (serverInfo != null && !serverInfo.isConnected()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    boolean isSupportTableComment = false;
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(info, false);
        isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(info, conn);
        if (!isSupportTableComment) {
            CommonUITool.openErrorBox(Messages.cannotSyncComments);
            return;
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        QueryUtil.freeQuery(conn);
    }
    if (!CommonUITool.openConfirmBox(getSite().getShell(), Messages.bind(Messages.msgConfirmSyncComments, database.getLabel()))) {
        return;
    }
    CommonTaskExec taskJobExec = new CommonTaskExec(null);
    List<UpdateDescriptionTask> updateDescTasks = getUpdateDescriptionTaskList(info);
    for (UpdateDescriptionTask task : updateDescTasks) {
        taskJobExec.addTask(task);
    }
    if (updateDescTasks.size() == 0) {
        CommonUITool.openInformationBox(Messages.msgNoComments);
        return;
    }
    new ExecTaskWithProgress(taskJobExec).exec();
    Set<String> failTables = new HashSet<String>();
    for (UpdateDescriptionTask task : updateDescTasks) {
        if (!task.isSuccess()) {
            failTables.add(task.getTableName());
        }
    }
    if (failTables.size() == 0) {
        CommonUITool.openInformationBox(Messages.msgSuccessSyncComments);
    } else {
        CommonUITool.openErrorBox(Messages.bind(Messages.errSyncComments, failTables.toString()));
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) Connection(java.sql.Connection) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) UpdateDescriptionTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask) HashSet(java.util.HashSet)

Example 75 with ServerInfo

use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.

the class QueryExecuter method makeResult.

/**
	 * Make query editor result panel,including table panel and sql text and
	 * message text
	 *
	 * @param resultTbl the Table.
	 * @param sqlText the Text.
	 * @param messageText the StyledText.
	 */
public void makeResult(final TableSelectSupport tableSelectSupport, StyledText messageText, boolean multiQueryResult) {
    this.selectableSupport = tableSelectSupport;
    this.tblResult = tableSelectSupport.getTable();
    logMessageText = messageText;
    int[] queryInfoRange = new int[2];
    int[] queryRange = new int[2];
    StringBuilder resultMessage = new StringBuilder();
    resultMessage.append(getQueryMsg() == null ? "" : getQueryMsg().trim());
    queryInfoRange[0] = 0;
    queryInfoRange[1] = resultMessage.length();
    resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT).append(StringUtil.NEWLINE);
    queryRange[0] = resultMessage.length();
    resultMessage.append(query);
    queryRange[1] = query.length();
    ServerInfo serverInfo = database.getServer() == null ? null : database.getServer().getServerInfo();
    String fontString = QueryOptions.getFontString(serverInfo);
    Font tmpFont = ResourceManager.getFont(fontString);
    if (tmpFont == null) {
        String[] fontData = QueryOptions.getDefaultFont();
        tmpFont = ResourceManager.getFont(fontData[0], Integer.valueOf(fontData[1]), Integer.valueOf(fontData[2]));
    }
    font = tmpFont;
    tblResult.setFont(font);
    int[] fontColor = QueryOptions.getFontColor(serverInfo);
    color = ResourceManager.getColor(fontColor[0], fontColor[1], fontColor[2]);
    tblResult.setForeground(color);
    // Set font and foreground
    selectableSupport.getTableCursor().setFont(font);
    selectableSupport.getTableCursor().setForeground(color);
    selectableSupport.setShowDetailOperator(this);
    tblResult.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            selectableSupport.redrawMoreButton();
        }
    });
    if (queryEditor != null) {
        if (!multiQueryResult) {
            createContextMenuItems();
        }
        editor = new ControlEditor(selectableSupport.getTableCursor());
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        editor.grabVertical = true;
        bindEvents();
        addTableItemToolTips();
    }
    makeColumn();
    makeItem();
    if (!StringUtil.isEmpty(queryPlanLog)) {
        resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        resultMessage.append(StringUtil.NEWLINE).append(queryPlanLog);
    }
    if (!StringUtil.isEmpty(statsLog)) {
        resultMessage.append(StringUtil.NEWLINE).append(Messages.queryStat).append(":");
        resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        resultMessage.append(StringUtil.NEWLINE).append(statsLog);
    }
    messageText.setText(resultMessage.toString());
    // Styled Query info
    StyleRange queryInfoStyle = new StyleRange();
    queryInfoStyle.start = queryInfoRange[0];
    queryInfoStyle.length = queryInfoRange[1];
    queryInfoStyle.fontStyle = SWT.NORMAL;
    queryInfoStyle.foreground = ResourceManager.getColor(SWT.COLOR_BLUE);
    messageText.setStyleRange(queryInfoStyle);
    StyleRange queryStyle = new StyleRange();
    queryStyle.start = queryRange[0];
    queryStyle.length = queryRange[1];
    queryStyle.fontStyle = SWT.BOLD;
    messageText.setStyleRange(queryStyle);
    // styled log text
    updateStyledLogTextForStatistics(messageText);
    updateStyledLogTextForPlan(messageText);
    updateStyledLogTextForTrace(messageText);
}
Also used : ControlEditor(org.eclipse.swt.custom.ControlEditor) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) StyleRange(org.eclipse.swt.custom.StyleRange) Font(org.eclipse.swt.graphics.Font)

Aggregations

ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)255 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)40 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)40 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)39 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)35 ArrayList (java.util.ArrayList)30 EnvInfo (com.cubrid.cubridmanager.core.common.model.EnvInfo)29 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)28 TreeViewer (org.eclipse.jface.viewers.TreeViewer)27 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)24 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)24 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)24 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)21 SelectionEvent (org.eclipse.swt.events.SelectionEvent)20 GridData (org.eclipse.swt.layout.GridData)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 ITask (com.cubrid.common.core.task.ITask)15