use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class ExportConnectionUtil method getColumnText.
public String getColumnText(Object element, int columnIndex) {
if (element instanceof CubridServer && columnIndex == 0) {
CubridServer server = (CubridServer) element;
return server.getName();
}
if (element instanceof CubridDatabase) {
CubridDatabase database = (CubridDatabase) element;
DatabaseInfo dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
LOGGER.warn("DatabaseInfo is a null.");
return "";
}
switch(columnIndex) {
case 0:
return dbInfo.getDbName();
case 1:
return dbInfo.getBrokerIP();
case 2:
return dbInfo.getBrokerPort();
case 3:
return dbInfo.getAuthLoginedDbUserInfo().getName();
case 4:
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, isCMMode);
if (editorConfig != null) {
return editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment();
}
return "";
case 5:
return NodeUtil.getJavaConnectionUrl(database.getDatabaseInfo());
case 6:
return NodeUtil.getPHPConnectionUrl(database.getDatabaseInfo());
}
}
return null;
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class MultiDatabaseLoginFailedDialog method editHost.
public void editHost(MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo) {
if (multiDatabaseloginFailedInfo == null) {
return;
}
CubridDatabase database = multiDatabaseloginFailedInfo.getCubridDatabase();
//if login ,can't edit
if (database.isLogined()) {
return;
}
// CubridDatabase oldDatabase = null;
// try {
// oldDatabase = database.clone();
// } catch (CloneNotSupportedException e) {
// //Ignore
// }
LoginDatabaseDialog dialog = new LoginDatabaseDialog(getShell(), database);
int returnVal = dialog.open();
if (returnVal == IDialogConstants.OK_ID) {
CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
TreeViewer treeViewer = view.getViewer();
database.removeAllChild();
if (database.getLoader() != null) {
database.getLoader().setLoaded(false);
}
treeViewer.refresh(database, true);
treeViewer.expandToLevel(database, 1);
/*Save the data*/
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, true);
if (editorConfig == null) {
editorConfig = new DatabaseEditorConfig();
}
editorConfig.setBackGround(dialog.getSelectedColor());
CMDBNodePersistManager.getInstance().addDatabase(database, editorConfig);
ActionManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
LayoutManager.getInstance().fireSelectionChanged(treeViewer.getSelection());
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGIN));
multiDatabaseloginFailedInfo.setErrMsg("");
}
databaseTable.refresh();
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class CQBDBNodePersistManager method saveDatabases.
/**
*
* Save added database to plug-in preference
*
*/
public void saveDatabases() {
synchronized (this) {
XMLMemento memento = XMLMemento.createWriteRoot("databases");
Iterator<CubridDatabase> iterator = databaseList.iterator();
while (iterator.hasNext()) {
CubridDatabase database = (CubridDatabase) iterator.next();
DatabaseInfo dbInfo = database.getDatabaseInfo();
ServerInfo serverInfo = dbInfo.getServerInfo();
DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
IXMLMemento child = memento.createChild("database");
child.putString("name", database.getLabel());
child.putString("dbName", dbInfo.getDbName());
child.putString("dbUser", dbUserInfo.getName());
if (database.isAutoSavePassword()) {
child.putString("dbPassword", CipherUtils.encrypt(dbUserInfo.getNoEncryptPassword()));
} else {
child.putString("dbPassword", "");
}
child.putString("savePassword", String.valueOf(database.isAutoSavePassword()));
// [TOOLS-2425]Support shard broker
child.putString("isShard", String.valueOf(dbInfo.isShard()));
child.putString("shardQueryType", String.valueOf(dbInfo.getShardQueryType()));
child.putString("jdbcDriver", serverInfo.getJdbcDriverVersion());
child.putString("brokerIp", dbInfo.getBrokerIP());
child.putString("brokerPort", dbInfo.getBrokerPort());
child.putString("charset", dbInfo.getCharSet());
child.putString("jdbcAttrs", dbInfo.getJdbcAttrs());
/*Save the database editor config*/
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
if (editorConfig != null) {
IXMLMemento editorConfigChild = child.createChild("editorConfig");
editorConfigChild.putString("database-comment", editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment());
if (editorConfig.getBackGround() != null) {
RGB background = editorConfig.getBackGround();
int bgPos = EditorConstance.getBGPos(background);
editorConfigChild.putInteger("purpose-code", bgPos);
}
}
}
PersistUtils.saveXMLMemento(ApplicationUtil.CQB_UI_PLUGIN_ID, DATABASE_XML_CONTENT, memento);
}
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class CQBDBNodePersistManager method loadDatabases.
/**
*
* Load databases from xml memento
*
* @param memento IXMLMemento
* @param isLoadOptions boolean
* @param optionPath String
*/
protected void loadDatabases(IXMLMemento memento, boolean isLoadOptions, String optionPath) {
//when import connections, load the global preference
if (isLoadOptions) {
QueryOptions.load(optionPath, null);
}
IXMLMemento[] children = memento == null ? null : memento.getChildren("database");
for (int i = 0; children != null && i < children.length; i++) {
String name = children[i].getString("name");
String dbName = children[i].getString("dbName");
String dbUser = children[i].getString("dbUser");
String dbPassword = children[i].getString("dbPassword");
String jdbcDriver = children[i].getString("jdbcDriver");
boolean savePassword = children[i].getBoolean("savePassword");
// [TOOLS-2425]Support shard broker
Boolean isShardObj = children[i].getBoolean("isShard");
boolean isShard = isShardObj == null ? false : isShardObj;
String shardQueryTypeStr = children[i].getString("shardQueryType");
int shardQueryType = StringUtil.intValue(shardQueryTypeStr, 0);
if (shardQueryType == 0) {
shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
}
String brokerIp = children[i].getString("brokerIp");
String brokerPort = children[i].getString("brokerPort");
String charset = children[i].getString("charset");
String jdbcAttrs = children[i].getString("jdbcAttrs");
DatabaseEditorConfig editorConfig = null;
IXMLMemento editorConfigElement = children[i].getChild("editorConfig");
if (editorConfigElement != null) {
editorConfig = new DatabaseEditorConfig();
String strBGPos = editorConfigElement.getString("purpose-code");
if (strBGPos == null) {
strBGPos = "0";
}
int bgPos = StringUtil.intValue(strBGPos, 0);
RGB background = EditorConstance.getRGBByPos(bgPos);
editorConfig.setBackGround(background);
editorConfig.setDatabaseComment(editorConfigElement.getString("database-comment"));
}
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerName(name);
serverInfo.setHostAddress(brokerIp);
serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
serverInfo.setUserName(dbName + "@" + brokerIp);
serverInfo.setJdbcDriverVersion(jdbcDriver);
CubridServer server = new CubridServer(name, name, null, null);
server.setServerInfo(serverInfo);
server.setType(NodeType.SERVER);
DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
dbInfo.setBrokerIP(brokerIp);
dbInfo.setBrokerPort(brokerPort);
dbInfo.setCharSet(charset);
dbInfo.setJdbcAttrs(jdbcAttrs);
dbInfo.setRunningType(DbRunningType.CS);
// [TOOLS-2425]Support shard broker
dbInfo.setShard(isShard);
dbInfo.setShardQueryType(shardQueryType);
String decDbPassword = null;
if (dbPassword != null && dbPassword.trim().length() > 0) {
decDbPassword = CipherUtils.decrypt(dbPassword);
}
DbUserInfo dbUserInfo = new DbUserInfo(dbName, dbUser, dbPassword, decDbPassword, false);
dbInfo.setAuthLoginedDbUserInfo(dbUserInfo);
String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
if (this.getDatabase(dbId) != null) {
continue;
}
CubridDatabase database = new CubridDatabase(dbId, name);
database.setServer(server);
database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
database.setDatabaseInfo(dbInfo);
CubridNodeLoader loader = new CQBDbConnectionLoader();
loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
database.setLoader(loader);
database.setAutoSavePassword(savePassword);
if (isLoadOptions) {
QueryOptions.load(optionPath, serverInfo);
}
/*Save the DatabaseEditorConfig to the memory*/
QueryOptions.putEditorConfig(database, editorConfig, false);
databaseList.add(database);
fireAddDatabase(database);
}
}
use of com.cubrid.common.ui.spi.model.DatabaseEditorConfig in project cubrid-manager by CUBRID.
the class MultiQueryConnEditDialog method cloneMultiEditQueryConnInfo.
/**
* clone edit database
*
* @param cloneDB
* @return
*/
public CubridDatabase cloneMultiEditQueryConnInfo(CubridDatabase cloneDB) {
CubridDatabase newCubridDatabase = new CubridDatabase(cloneDB.getId(), cloneDB.getLabel());
DatabaseInfo cloneDBInfo = cloneDB.getDatabaseInfo();
ServerInfo cloneServerInfo = cloneDBInfo.getServerInfo();
String databaseName = cloneDBInfo.getDbName();
String brokerIp = cloneDBInfo.getBrokerIP();
String brokerPort = cloneDBInfo.getBrokerPort();
String userName = cloneDBInfo.getAuthLoginedDbUserInfo().getName();
String userPassword = cloneDBInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
String charset = cloneDBInfo.getCharSet();
String jdbcAttrs = cloneDBInfo.getJdbcAttrs();
String jdbcVersion = cloneServerInfo.getJdbcDriverVersion();
ServerInfo newServerInfo = new ServerInfo();
newServerInfo.setServerName(databaseName);
newServerInfo.setHostAddress(brokerIp);
newServerInfo.setHostMonPort(Integer.parseInt(brokerPort));
newServerInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
newServerInfo.setUserName(databaseName + "@" + brokerIp);
newServerInfo.setJdbcDriverVersion(jdbcVersion);
DatabaseInfo newDBInfo = new DatabaseInfo(databaseName, newServerInfo);
newDBInfo.setBrokerIP(brokerIp);
newDBInfo.setBrokerPort(brokerPort);
newDBInfo.setCharSet(charset);
newDBInfo.setJdbcAttrs(jdbcAttrs);
DbUserInfo newUserInfo = new DbUserInfo();
newUserInfo.setDbName(databaseName);
newUserInfo.setName(userName);
newUserInfo.setNoEncryptPassword(userPassword);
newDBInfo.setAuthLoginedDbUserInfo(newUserInfo);
newCubridDatabase.setAutoSavePassword(cloneDB.isAutoSavePassword());
newCubridDatabase.setServer(cloneDB.getServer());
newCubridDatabase.setDatabaseInfo(newDBInfo);
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(cloneDB, false);
if (editorConfig != null) {
newCubridDatabase.setData(COMMENTKEY, editorConfig.getDatabaseComment());
} else {
newCubridDatabase.setData(COMMENTKEY, "");
}
return newCubridDatabase;
}
Aggregations