use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CubridDbUsersFolderLoader method formatUserList.
/**
*
* Format user list
*
* @param list the DbUserInfo list
*/
private void formatUserList(List<DbUserInfo> list) {
if (list == null || list.size() < 2) {
return;
}
DbUserInfo dbaUser = null;
DbUserInfo publicUser = null;
for (DbUserInfo bean : list) {
if (bean.getName().equalsIgnoreCase("public")) {
publicUser = bean;
}
if (bean.getName().equalsIgnoreCase("dba")) {
dbaUser = bean;
}
}
list.remove(dbaUser);
list.remove(publicUser);
if (dbaUser == null || publicUser == null) {
return;
}
Collections.sort(list, new Comparator<DbUserInfo>() {
public int compare(DbUserInfo o1, DbUserInfo o2) {
if (o1 == null || o2 == null || o1.getName() == null || o2.getName() == null) {
return 0;
}
int cc = o1.getName().compareToIgnoreCase(o2.getName());
return (cc < 0 ? -1 : cc > 0 ? 1 : 0);
}
});
list.add(0, publicUser);
list.add(0, dbaUser);
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CQBDbUsersFolderLoader method formatUserList.
/**
*
* Format user list
*
* @param list the DbUserInfo list
*/
private void formatUserList(List<DbUserInfo> list) {
// FIXME extract
if (list == null || list.size() < 2) {
return;
}
DbUserInfo dbaUser = null;
DbUserInfo publicUser = null;
for (DbUserInfo bean : list) {
if (bean.getName().equalsIgnoreCase("public")) {
publicUser = bean;
}
if (bean.getName().equalsIgnoreCase("dba")) {
dbaUser = bean;
}
}
list.remove(dbaUser);
list.remove(publicUser);
if (dbaUser == null || publicUser == null) {
return;
}
Collections.sort(list, new Comparator<DbUserInfo>() {
public int compare(DbUserInfo o1, DbUserInfo o2) {
if (o1 == null || o2 == null || o1.getName() == null || o2.getName() == null) {
return 0;
}
int cc = o1.getName().compareToIgnoreCase(o2.getName());
return (cc < 0 ? -1 : cc > 0 ? 1 : 0);
}
});
list.add(0, publicUser);
list.add(0, dbaUser);
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CQBDbUsersFolderLoader method load.
/**
*
* Load children object for parent
*
* @param parent the parent node
* @param monitor the IProgressMonitor object
*/
public void load(ICubridNode parent, final IProgressMonitor monitor) {
synchronized (this) {
if (isLoaded()) {
return;
}
CubridDatabase database = ((ISchemaNode) parent).getDatabase();
if (database.getRunningType() == DbRunningType.STANDALONE) {
parent.removeAllChild();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
return;
}
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DbUserInfoList dbUserInfoList = new DbUserInfoList();
GetUserListTask task = new GetUserListTask(database.getDatabaseInfo());
parent.removeAllChild();
try {
dbUserInfoList = task.getResultModel();
} catch (Exception e) {
LOGGER.error("load user failed", e);
}
DbUserInfo latestDLoginedbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
List<DbUserInfo> dbUserList = dbUserInfoList == null ? null : dbUserInfoList.getUserList();
formatUserList(dbUserList);
for (int i = 0; dbUserList != null && dbUserList.size() > i; i++) {
DbUserInfo dbUserInfo = dbUserList.get(i);
if (dbUserInfo.getName().equals(latestDLoginedbUserInfo.getName())) {
dbUserInfo.setDbaAuthority(latestDLoginedbUserInfo.isDbaAuthority());
// databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
}
String id = parent.getId() + NODE_SEPARATOR + dbUserInfo.getName();
ICubridNode dbUserInfoNode = new DefaultSchemaNode(id, dbUserInfo.getName(), "icons/navigator/user_item.png");
dbUserInfoNode.setType(NodeType.USER);
dbUserInfoNode.setModelObj(dbUserInfo);
dbUserInfoNode.setContainer(false);
dbUserInfoNode.setEditorId(CQBUserEditor.ID);
parent.addChild(dbUserInfoNode);
}
databaseInfo.setDbUserInfoList(dbUserInfoList);
setLoaded(true);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
}
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo 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.cubridmanager.core.cubrid.user.model.DbUserInfo 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);
}
}
Aggregations