Search in sources :

Example 1 with ConnectionInfo

use of com.cubrid.common.ui.common.persist.ConnectionInfo in project cubrid-manager by CUBRID.

the class CQBDBNodePersistManager method getConnectionInfo.

/**
	 * Retrives a connection information instance.
	 *
	 * @param database CubridDatabase
	 * @return ConnectionInfo
	 */
public ConnectionInfo getConnectionInfo(CubridDatabase database) {
    // FIXME extract
    DatabaseInfo dbInfo = database.getDatabaseInfo();
    String user = "";
    String password = "";
    if (dbInfo.getAuthLoginedDbUserInfo() != null) {
        user = dbInfo.getAuthLoginedDbUserInfo().getName();
        password = dbInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
    }
    String version = dbInfo.getServerInfo() == null ? "" : dbInfo.getServerInfo().getJdbcDriverVersion();
    String driverFileName = CubridJdbcManager.getInstance().getDriverFileByVersion(version);
    ConnectionInfo ci = new ConnectionInfo(database.getName(), dbInfo.getBrokerIP(), StringUtil.intValue(dbInfo.getBrokerPort(), -1), dbInfo.getDbName(), user, password, driverFileName, dbInfo.getCharSet());
    return ci;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo)

Example 2 with ConnectionInfo

use of com.cubrid.common.ui.common.persist.ConnectionInfo in project cubrid-manager by CUBRID.

the class DBParameter method fireModifyDatabase.

public void fireModifyDatabase(DatabaseInfo oldDbInfo, DatabaseInfo newDbInfo) {
    if (oldDbInfo == null || newDbInfo == null) {
        return;
    }
    ConnectionInfo oldInfo = getConnectionInfo(oldDbInfo);
    ConnectionInfo newInfo = getConnectionInfo(newDbInfo);
    try {
        for (IJDBCConnectionChangedObserver ob : observers) {
            ob.afterModify(this, oldInfo, newInfo);
        }
    } catch (Exception ex) {
    //ignore
    }
}
Also used : IJDBCConnectionChangedObserver(com.cubrid.common.configuration.jdbc.IJDBCConnectionChangedObserver) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo) IOException(java.io.IOException)

Example 3 with ConnectionInfo

use of com.cubrid.common.ui.common.persist.ConnectionInfo in project cubrid-manager by CUBRID.

the class EditQueryConnAction method run.

/**
	 * Open the query connection
	 */
public void run() {
    // TODO remove later
    CQBGroupNodePersistManager.getInstance().fix();
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    ISelectionProvider provider = getSelectionProvider();
    if (!(provider instanceof TreeViewer)) {
        return;
    }
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    ConnectionInfo oldInfo = null;
    ConnectionInfo newInfo = null;
    if (cubridDatabases.length > 1) {
        MultiQueryConnEditDialog dialog = new MultiQueryConnEditDialog(getShell(), Arrays.asList(cubridDatabases));
        if (dialog.open() != MultiQueryConnEditDialog.SAVE_ID) {
            return;
        }
        List<CubridDatabase> newDBList = dialog.getNewDBList();
        for (int i = 0; i < cubridDatabases.length; i++) {
            CubridDatabase saveCubridDatabase = cubridDatabases[i];
            CubridDatabase newCubridDatabase = newDBList.get(i);
            oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(saveCubridDatabase);
            newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(newCubridDatabase);
            saveCubridDatabase.setLabel(newCubridDatabase.getLabel());
            saveCubridDatabase.getDatabaseInfo().setDbName(newCubridDatabase.getDatabaseInfo().getDbName());
            saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setName(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getName());
            saveCubridDatabase.setAutoSavePassword(newCubridDatabase.isAutoSavePassword());
            if (saveCubridDatabase.isAutoSavePassword()) {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(newCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword());
            } else {
                saveCubridDatabase.getDatabaseInfo().getAuthLoginedDbUserInfo().setNoEncryptPassword(null);
            }
            saveCubridDatabase.getDatabaseInfo().setBrokerIP(newCubridDatabase.getDatabaseInfo().getBrokerIP());
            saveCubridDatabase.getDatabaseInfo().setBrokerPort(newCubridDatabase.getDatabaseInfo().getBrokerPort());
            DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(saveCubridDatabase, false);
            if (editorConfig == null) {
                editorConfig = new DatabaseEditorConfig();
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            } else if (editorConfig.getBackGround() == null) {
                editorConfig.setBackGround(EditorConstance.getDefaultBackground());
            }
            if (newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY) != null) {
                editorConfig.setDatabaseComment((String) newCubridDatabase.getData(MultiQueryConnEditDialog.COMMENTKEY));
            }
            QueryOptions.putEditorConfig(saveCubridDatabase, editorConfig, false);
            CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
            boolean isContinue = CQBConnectionUtils.processConnectionLogout(saveCubridDatabase);
            if (isContinue) {
                TreeViewer viewer = (TreeViewer) provider;
                viewer.refresh(saveCubridDatabase, true);
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(saveCubridDatabase, CubridNodeChangedEventType.DATABASE_LOGOUT));
            }
        }
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        return;
    }
    CubridDatabase database = (CubridDatabase) cubridDatabases[0];
    if (database.getParent() == null) {
        CQBGroupNodePersistManager.getInstance();
    }
    String preName = (database == null || database.getServer() == null) ? "" : database.getServer().getName();
    ServerInfo preServerInfo = (database == null || database.getServer() == null) ? null : database.getServer().getServerInfo();
    oldInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
    QueryConnDialog dialog = new QueryConnDialog(getShell(), database, false);
    int returnCode = dialog.open();
    if (returnCode == QueryConnDialog.CONNECT_ID) {
        database.removeAllChild();
        newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
        TreeViewer treeViewer = (TreeViewer) provider;
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
        if (!preName.equals(database.getServer().getName())) {
            QueryOptions.removePref(preServerInfo);
        }
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        LayoutManager.getInstance().fireSelectionChanged(getSelection());
        if (dialog.isFireLogoutEvent()) {
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT));
        }
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
        CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
        try {
            CommonUITool.openQueryEditor(database, true);
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage(), e);
        }
    } else if (returnCode == QueryConnDialog.SAVE_ID) {
        TreeViewer treeViewer = (TreeViewer) provider;
        treeViewer.refresh(database, true);
        treeViewer.expandToLevel(database, 1);
        CQBGroupNodePersistManager.getInstance().saveAllGroupNode();
        CQBDBNodePersistManager.getInstance().saveDatabases();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) MultiQueryConnEditDialog(com.cubrid.cubridquery.ui.connection.dialog.MultiQueryConnEditDialog) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig) QueryConnDialog(com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)

Example 4 with ConnectionInfo

use of com.cubrid.common.ui.common.persist.ConnectionInfo in project cubrid-manager by CUBRID.

the class DBParameter method getConnectionInfo.

/**
	 * Retrives a connection information instance.
	 *
	 * @param database CubridDatabase
	 * @return ConnectionInfo
	 */
public ConnectionInfo getConnectionInfo(DatabaseInfo databaseInfo) {
    // FIXME extract
    String user = "";
    String password = "";
    if (databaseInfo.getAuthLoginedDbUserInfo() != null) {
        user = databaseInfo.getAuthLoginedDbUserInfo().getName();
        password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
    }
    ServerInfo serverInfo = databaseInfo.getServerInfo();
    String version = "";
    String driverFileName = "";
    if (serverInfo != null) {
        version = serverInfo.getJdbcDriverVersion();
        driverFileName = CubridJdbcManager.getInstance().getDriverFileByVersion(version);
    }
    String connName = databaseInfo.getDbName() + "@" + databaseInfo.getBrokerIP() + ":" + databaseInfo.getBrokerPort();
    ConnectionInfo ci = new ConnectionInfo(connName, databaseInfo.getBrokerIP(), StringUtil.intValue(databaseInfo.getBrokerPort(), -1), databaseInfo.getDbName(), user, password, driverFileName, databaseInfo.getCharSet());
    return ci;
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ConnectionInfo(com.cubrid.common.ui.common.persist.ConnectionInfo)

Aggregations

ConnectionInfo (com.cubrid.common.ui.common.persist.ConnectionInfo)4 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 IJDBCConnectionChangedObserver (com.cubrid.common.configuration.jdbc.IJDBCConnectionChangedObserver)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 MultiQueryConnEditDialog (com.cubrid.cubridquery.ui.connection.dialog.MultiQueryConnEditDialog)1 QueryConnDialog (com.cubrid.cubridquery.ui.connection.dialog.QueryConnDialog)1 IOException (java.io.IOException)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 PartInitException (org.eclipse.ui.PartInitException)1