use of com.cubrid.common.ui.spi.model.CubridServer 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.CubridServer in project cubrid-manager by CUBRID.
the class CMGroupNodePersistManager method getAllGroupItems.
/**
* Get all group items just like hosts or connections.
*
* @return the group items of all.
*/
public List<ICubridNode> getAllGroupItems() {
List<ICubridNode> result = new ArrayList<ICubridNode>();
List<CubridServer> servers = CMHostNodePersistManager.getInstance().getAllServers();
for (CubridServer server : servers) {
result.add(server);
}
return result;
}
use of com.cubrid.common.ui.spi.model.CubridServer in project cubrid-manager by CUBRID.
the class CMHostNodePersistManager method addServer.
/**
* Add CUBRID Manager server information
*
* @param hostAddress String host address
* @param port int host port
* @param value ServerInfo given serverInfo
* @param userName the String
* @return ServerInfo
*/
public void addServer(String hostAddress, int port, String userName, ServerInfo value) {
synchronized (this) {
CubridServer server = getServer(hostAddress, port, userName);
if (server == null) {
CubridServer newServer = new CubridServer(value.getServerName(), value.getServerName(), "com.cubrid.cubridmananger.ui/icons/navigator/host.png", "com.cubrid.cubridmananger.ui/icons/navigator/host_connected.png");
newServer.setServerInfo(value);
newServer.setLoader(new CubridServerLoader());
addServer(newServer);
} else {
server.setServerInfo(value);
}
ServerManager.getInstance().addServer(hostAddress, port, userName, value);
}
}
use of com.cubrid.common.ui.spi.model.CubridServer in project cubrid-manager by CUBRID.
the class CMHostNodePersistManager method saveServer.
public void saveServer(List<CubridServer> servers, String f) {
synchronized (this) {
XMLMemento memento = XMLMemento.createWriteRoot("hosts");
Iterator<CubridServer> iterator = servers.iterator();
while (iterator.hasNext()) {
CubridServer server = (CubridServer) iterator.next();
IXMLMemento child = memento.createChild("host");
child.putString("id", server.getId());
child.putString("name", server.getLabel());
child.putString("port", String.valueOf(server.getMonPort()));
child.putString("address", server.getHostAddress());
child.putString("user", server.getUserName());
// String pwd = server.isAutoSavePassword() ? CipherUtils.encrypt(server.getPassword())
// : "";
// child.putString("password", pwd);
// child.putBoolean("savePassword", false);
child.putString("jdbcDriver", server.getJdbcDriverVersion());
if (server.getServerInfo() != null) {
child.putInteger("soTimeOut", server.getServerInfo().getSoTimeOut());
}
}
FileOutputStream fout = null;
try {
fout = new FileOutputStream(f);
fout.write(memento.getContents());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of com.cubrid.common.ui.spi.model.CubridServer in project cubrid-manager by CUBRID.
the class CMHostNodePersistManager method isContainedByHostAddress.
/**
*
* Return whether this server has been existed and exclude this server
*
* @param address the ip address
* @param port the port
* @param server the CubridServer object
* @return <code>true</code> if contain this server;<code>false</code>
* otherwise
*/
public boolean isContainedByHostAddress(String address, String port, CubridServer server) {
// FIXME extract
for (int i = 0; i < serverList.size(); i++) {
CubridServer serv = serverList.get(i);
if (server != null && server.getId().equals(serv.getId())) {
continue;
}
ServerInfo serverInfo = serv.getServerInfo();
if (serverInfo.getHostAddress().equals(address) && serverInfo.getHostMonPort() == Integer.parseInt(port)) {
return true;
}
}
return false;
}
Aggregations