use of com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask in project cubrid-manager by CUBRID.
the class QueryConnDialog method buttonPressed.
/**
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
* @param buttonId the id of the button that was pressed (see
* <code>IDialogConstants.*_ID</code> constants)
*/
protected void buttonPressed(int buttonId) {
if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID || buttonId == SAVE_ID) {
String name = queryConnNameText.getText();
String dbName = connectionComp.getDatabaseText().getText();
String brokerIp = connectionComp.getBrokerIpText().getText();
String brokerPort = connectionComp.getBrokerPortText().getText();
String userName = connectionComp.getUserNameText().getText();
String password = connectionComp.getPasswordText().getText();
String charset = connectionComp.getCharsetCombo().getText();
String jdbcDriver = connectionComp.getJdbcCombo().getText();
String jdbcAttrs = connectionComp.getAttrText().getText().trim();
boolean isAutoCommit = connectionComp.isAutoCommit();
// [TOOLS-2425]Support shard broker
boolean isShard = connectionComp.getBtnShard().getSelection();
int currentShardId = connectionComp.getCurShardId();
int currentShardVal = connectionComp.getCurShardVal();
int defaultShardQueryType = connectionComp.getShardQueryType();
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);
DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
dbInfo.setBrokerIP(brokerIp);
dbInfo.setBrokerPort(brokerPort);
dbInfo.setCharSet(charset);
dbInfo.setJdbcAttrs(jdbcAttrs);
// [TOOLS-2425]Support shard broker
dbInfo.setShard(isShard);
dbInfo.setCurrentShardId(currentShardId);
dbInfo.setCurrentShardVal(currentShardVal);
dbInfo.setShardQueryType(defaultShardQueryType);
DbUserInfo userInfo = new DbUserInfo();
userInfo.setDbName(dbName);
userInfo.setName(userName);
userInfo.setNoEncryptPassword(password);
dbInfo.setAuthLoginedDbUserInfo(userInfo);
if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID) {
TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
new ExecTaskWithProgress(taskExcutor).exec();
if (!taskExcutor.isSuccess()) {
return;
}
if (buttonId == TEST_CONNECT_ID) {
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.msgTestConnSuccess);
return;
}
}
if (buttonId == CONNECT_ID) {
// check whether dba authorization
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
userInfo.setDbaAuthority(checkTask.isDBAUser());
dbInfo.setRunningType(DbRunningType.CS);
dbInfo.getServerInfo().setConnected(true);
dbInfo.setLogined(true);
boolean userChanged = !name.equals(oldLoginUserName);
fireLogoutEvent = oldDatabaseIsLogin && userChanged;
}
if (!isNewQueryConn && database != null) {
boolean isContinue = CQBConnectionUtils.processConnectionLogout(database);
if (!isContinue) {
return;
}
}
// If this is new connection,then warning charset setting
if (isNewQueryConn) {
boolean sureCharset = CommonUITool.openConfirmBox(Messages.bind(com.cubrid.cubridquery.ui.connection.Messages.msgConfirmCharset, charset));
if (!sureCharset) {
connectionComp.getCharsetCombo().setFocus();
return;
}
}
if (isNewQueryConn && (buttonId == CONNECT_ID || buttonId == SAVE_ID) && EditorConstance.getDefaultBackground().equals(getSelectedBackground())) {
boolean surePurpose = CommonUITool.openConfirmBox(Messages.msgUseDefaultPurpose);
if (!surePurpose) {
selectColorCombo.expandMenu();
return;
}
}
CubridServer server = new CubridServer(name, name, null, null);
server.setServerInfo(serverInfo);
server.setType(NodeType.SERVER);
String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
if (isNewQueryConn) {
database = new CubridDatabase(dbId, name);
} else {
database.setId(dbId);
database.setLabel(name);
}
database.setDatabaseInfo(dbInfo);
database.setServer(server);
database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
CubridNodeLoader loader = new CQBDbConnectionLoader();
loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
database.setLoader(loader);
database.setAutoSavePassword(connectionComp.isAutoSavePassword());
if (buttonId == CONNECT_ID || buttonId == SAVE_ID) {
if (database != null) {
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, false);
if (editorConfig == null) {
editorConfig = new DatabaseEditorConfig();
}
editorConfig.setBackGround(getSelectedBackground());
editorConfig.setDatabaseComment(getDatabaseComment());
QueryOptions.putEditorConfig(database, editorConfig, false);
}
newInfo = CQBDBNodePersistManager.getInstance().getConnectionInfo(database);
if (isNewQueryConn) {
CQBDBNodePersistManager.getInstance().fireAddDatabase(database);
} else if (oldInfo != null) {
CQBDBNodePersistManager.getInstance().fireModifyDatabase(oldInfo, newInfo);
}
}
QueryOptions.setAutoCommit(serverInfo, isAutoCommit);
}
setReturnCode(buttonId);
close();
}
use of com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask in project cubrid-manager by CUBRID.
the class LoginQueryEditorDialog method buttonPressed.
/**
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
* @param buttonId the id of the button that was pressed (see
* <code>IDialogConstants.*_ID</code> constants)
*/
protected void buttonPressed(int buttonId) {
if (buttonId == TEST_CONNECT_ID || buttonId == IDialogConstants.OK_ID) {
String dbName = connectionComp.getDatabaseText().getText();
String brokerIp = connectionComp.getBrokerIpText().getText();
String brokerPort = connectionComp.getBrokerPortText().getText();
String userName = connectionComp.getUserNameText().getText();
String password = connectionComp.getPasswordText().getText();
String charset = connectionComp.getCharsetCombo().getText();
String jdbcDriver = connectionComp.getJdbcCombo().getText();
String jdbcAttrs = connectionComp.getAttrText().getText().trim();
boolean isShard = connectionComp.getBtnShard().getSelection();
int currentShardId = connectionComp.getCurShardId();
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerName(DatabaseNavigatorMenu.SELF_DATABASE_ID);
serverInfo.setHostAddress(brokerIp);
serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
serverInfo.setJdbcDriverVersion(jdbcDriver);
DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
dbInfo.setBrokerIP(brokerIp);
dbInfo.setBrokerPort(brokerPort);
dbInfo.setCharSet(charset);
dbInfo.setJdbcAttrs(jdbcAttrs);
dbInfo.setShard(isShard);
dbInfo.setCurrentShardId(currentShardId);
DbUserInfo userInfo = new DbUserInfo();
userInfo.setDbName(dbName);
userInfo.setName(userName);
userInfo.setNoEncryptPassword(password);
dbInfo.setAuthLoginedDbUserInfo(userInfo);
TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
new ExecTaskWithProgress(taskExcutor).exec();
if (!taskExcutor.isSuccess()) {
return;
}
if (buttonId == TEST_CONNECT_ID) {
CommonUITool.openInformationBox(com.cubrid.cubridquery.ui.connection.Messages.titleSuccess, com.cubrid.cubridquery.ui.connection.Messages.msgTestConnSuccess);
return;
}
// check whether dba authorization
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
userInfo.setDbaAuthority(checkTask.isDBAUser());
dbInfo.setLogined(true);
dbInfo.setRunningType(DbRunningType.CS);
dbInfo.getServerInfo().setConnected(true);
dbInfo.setLogined(true);
CubridServer server = new CubridServer(DatabaseNavigatorMenu.SELF_DATABASE_ID, DatabaseNavigatorMenu.SELF_DATABASE_SELECTED_LABEL, null, null);
server.setServerInfo(serverInfo);
server.setType(NodeType.SERVER);
DatabaseNavigatorMenu.SELF_DATABASE.setDatabaseInfo(dbInfo);
DatabaseNavigatorMenu.SELF_DATABASE.setServer(server);
DatabaseNavigatorMenu.SELF_DATABASE.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
DatabaseNavigatorMenu.SELF_DATABASE.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
DatabaseNavigatorMenu.SELF_DATABASE.setLoader(new CQBDbConnectionLoader());
}
super.buttonPressed(buttonId);
}
use of com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method connectDatabaseWithErrMsg.
/**
*
* Connect the database
*
* @param dbInfo DatabaseInfo
* @return error messages String
*/
public static String connectDatabaseWithErrMsg(DatabaseInfo dbInfo) {
// FIXME extract
if (dbInfo == null || dbInfo.getServerInfo() == null) {
return "";
}
Map<String, String> jdbcVersionMap = CubridJdbcManager.getInstance().getLoadedJdbc();
if (jdbcVersionMap == null || jdbcVersionMap.get(dbInfo.getServerInfo().getJdbcDriverVersion()) == null) {
return Messages.errNoSupportDriver;
}
CUBRIDConnectionProxy connection = null;
try {
connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(dbInfo, false);
DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
userInfo.setDbaAuthority(checkTask.isDBAUser());
dbInfo.setLogined(true);
dbInfo.setRunningType(DbRunningType.CS);
dbInfo.getServerInfo().setConnected(true);
dbInfo.setLogined(true);
return null;
} catch (SQLException e) {
return Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage());
} catch (Exception e) {
return e.getMessage();
} finally {
if (connection != null) {
try {
connection.close();
connection = null;
} catch (SQLException e) {
connection = null;
}
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method connectDatabase.
/**
*
* Connect the database
*
* @param dbInfo DatabaseInfo
* @return boolean
*/
public static boolean connectDatabase(DatabaseInfo dbInfo) {
// FIXME extract
if (dbInfo == null || dbInfo.getServerInfo() == null) {
return false;
}
Map<String, String> jdbcVersionMap = CubridJdbcManager.getInstance().getLoadedJdbc();
if (jdbcVersionMap == null || jdbcVersionMap.get(dbInfo.getServerInfo().getJdbcDriverVersion()) == null) {
return false;
}
CUBRIDConnectionProxy connection = null;
try {
connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(dbInfo, false);
DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
userInfo.setDbaAuthority(checkTask.isDBAUser());
dbInfo.setLogined(true);
dbInfo.setRunningType(DbRunningType.CS);
dbInfo.getServerInfo().setConnected(true);
dbInfo.setLogined(true);
return true;
} catch (SQLException e) {
CommonUITool.openErrorBox(Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
return false;
} catch (Exception e) {
CommonUITool.openErrorBox(e.getMessage());
return false;
} finally {
if (connection != null) {
try {
connection.close();
connection = null;
} catch (SQLException e) {
connection = null;
}
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method connectDatabase.
/**
* Connect the database
*
* @param dbInfo DatabaseInfo
* @param showErrMsg boolean
* @return boolean
*/
public static boolean connectDatabase(DatabaseInfo dbInfo, boolean showErrMsg) {
if (dbInfo == null || dbInfo.getServerInfo() == null || dbInfo.getAuthLoginedDbUserInfo() == null) {
return false;
}
final String USER_DBA = "dba";
DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
String dbUser = dbUserInfo.getName();
String dbPassword = dbUserInfo.getNoEncryptPassword();
if (dbUser == null || dbUser.trim().length() == 0 || dbPassword == null) {
return false;
}
TaskExecutor taskExcutor = new LoginDatabaseTaskExecutor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dbInfo.getServerInfo(), dbInfo.getDbName(), dbUser, dbPassword, showErrMsg);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
boolean isSuccess = taskExcutor.isSuccess();
if (!isSuccess) {
LOGGER.error("login database failed");
}
/*For [TOOLS-3516]*/
if (dbInfo.getAuthLoginedDbUserInfo() != null && CompatibleUtil.isNeedCheckDbaAuthorityByJDBC(dbInfo)) {
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
if (checkTask.isSuccess()) {
dbInfo.getAuthLoginedDbUserInfo().setDbaAuthority(checkTask.isDBAUser());
} else {
dbInfo.getAuthLoginedDbUserInfo().setDbaAuthority(USER_DBA.equals(dbUser.toLowerCase()));
}
}
/*Modify*/
CMDBNodePersistManager.getInstance().fireModifyDatabase(dbInfo, dbInfo);
return taskExcutor.isSuccess();
}
Aggregations