use of com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader in project cubrid-manager by CUBRID.
the class CQBDBNodePersistManager method parseDatabaseFromXML.
public List<CubridDatabase> parseDatabaseFromXML(File file) {
// FIXME extract?
List<CubridDatabase> list = new ArrayList<CubridDatabase>();
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
IXMLMemento xmlContent = XMLMemento.loadMemento(fis);
IXMLMemento[] children = xmlContent == null ? null : xmlContent.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 brokerIp = children[i].getString("brokerIp");
String brokerPort = children[i].getString("brokerPort");
String charset = children[i].getString("charset");
String jdbcAttrs = children[i].getString("jdbcAttrs");
String dbUser = children[i].getString("dbUser");
String dbPassword = children[i].getString("dbPassword");
boolean savePassword = children[i].getBoolean("savePassword");
String jdbcDriver = children[i].getString("jdbcDriver");
// [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);
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;
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"));
}
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);
/*Save DatabaseEditorConfig to database object*/
if (editorConfig != null) {
database.setData(CubridDatabase.DATA_KEY_EDITOR_CONFIG, editorConfig);
}
list.add(database);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
} finally {
FileUtil.close(fis);
}
return list;
}
Aggregations