use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class ConnectionComposite method changeData.
public void changeData(CubridDatabase database) {
charsetCombo.removeAll();
if (database == null) {
showDefaultForm();
return;
}
dbInfo = database.getDatabaseInfo();
if (dbInfo == null) {
showDefaultForm();
return;
}
ServerInfo serverInfo = dbInfo.getServerInfo();
if (serverInfo == null) {
showDefaultForm();
return;
}
String databaseName = dbInfo.getDbName();
String brokerIp = dbInfo.getBrokerIP();
String brokerPort = dbInfo.getBrokerPort();
String userName = dbInfo.getAuthLoginedDbUserInfo().getName();
String userPassword = dbInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
String charset = dbInfo.getCharSet();
String jdbcAttrs = dbInfo.getJdbcAttrs();
String jdbcVersion = serverInfo.getJdbcDriverVersion();
if (databaseText != null) {
databaseText.setText(databaseName);
}
userNameText.setText(userName);
btnAutoCommit.setSelection(QueryOptions.getAutoCommit(serverInfo));
if (database.isAutoSavePassword()) {
passwordText.setText(StringUtil.nvl(userPassword));
if (isIncludingSavePwd) {
btnSavePassword.setSelection(true);
}
} else {
passwordText.setText("");
if (isIncludingSavePwd) {
btnSavePassword.setSelection(false);
}
}
brokerIpText.setText(brokerIp);
if (brokerPortText != null) {
brokerPortText.setText(brokerPort);
}
charsetCombo.setItems(QueryOptions.getAllCharset(charset));
if (charset == null) {
charsetCombo.select(0);
} else {
charsetCombo.setText(charset);
}
jdbcCombo.setText(jdbcVersion);
attrText.setText(StringUtil.nvl(jdbcAttrs));
passwordText.selectAll();
passwordText.setFocus();
if (hasValidDatabaseInfo(database)) {
boolean isShard = database.getDatabaseInfo().isShard();
btnShard.setSelection(isShard);
btnShardId.setEnabled(isShard);
}
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class JdbcManageComposite method isJdbcDriverUsing.
/**
*
* Return whether the JDBC driver is using
*
* @param jdbcVersion String
* @return boolean
*/
private boolean isJdbcDriverUsing(String jdbcVersion) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return false;
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
return false;
}
IViewReference[] viewReference = page.getViewReferences();
for (int i = 0; viewReference != null && i < viewReference.length; i++) {
IViewPart viewPart = viewReference[i].getView(false);
if (!(viewPart instanceof CubridNavigatorView)) {
continue;
}
CubridNavigatorView navigatorView = (CubridNavigatorView) viewPart;
List<ICubridNode> list = getUsingJdbcNodeList(navigatorView);
if (list == null) {
continue;
}
for (ICubridNode node : list) {
if (NodeType.SERVER.equals(node.getType())) {
CubridServer server = (CubridServer) node;
ServerInfo serverInfo = server.getServerInfo();
if (serverInfo == null) {
continue;
}
if (serverInfo.isConnected() && serverInfo.getJdbcDriverVersion().equals(jdbcVersion)) {
CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcServer, new Object[] { serverInfo.getServerName(), jdbcVersion }));
return true;
}
} else if (NodeType.DATABASE.equals(node.getType())) {
CubridDatabase database = (CubridDatabase) node;
if (database == null || database.getServer() == null || database.getServer().getServerInfo() == null) {
continue;
}
ServerInfo serverInfo = database.getServer().getServerInfo();
if (serverInfo == null) {
LOGGER.error("The serverInfo is a null.");
return false;
}
boolean isSameVersion = StringUtil.isEqual(serverInfo.getJdbcDriverVersion(), jdbcVersion);
if (isSameVersion && database.isLogined()) {
CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcConn, new Object[] { database.getName(), jdbcVersion }));
return true;
}
}
}
}
IEditorReference[] editorReference = page.getEditorReferences();
for (int i = 0; editorReference != null && i < editorReference.length; i++) {
IEditorPart editorPart = editorReference[i].getEditor(false);
if (!(editorPart instanceof QueryEditorPart)) {
continue;
}
QueryEditorPart queryEditorPart = (QueryEditorPart) editorPart;
CubridServer server = queryEditorPart.getSelectedServer();
ServerInfo serverInfo = server == null ? null : server.getServerInfo();
String partName = queryEditorPart.getPartName();
if (serverInfo != null && serverInfo.getJdbcDriverVersion().equals(jdbcVersion)) {
CommonUITool.openErrorBox(Messages.bind(Messages.errDeleteJdbcQuery, new Object[] { partName, jdbcVersion }));
return true;
}
}
return false;
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class MultiQueryThread method run.
/**
* Execute query
*/
public void run() {
// FIXME move this logic to core module
DBConnection connection = new DBConnection(database.getDatabaseInfo());
try {
connection.checkAndConnect();
connection.setAutoClosable(true);
} catch (final SQLException event) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
String errorMsg = Messages.errDbConnect;
if (event.getMessage() != null) {
errorMsg = Messages.bind(com.cubrid.common.ui.common.Messages.errCommonTip, event.getErrorCode(), event.getMessage());
}
LOGGER.error(errorMsg);
CommonUITool.openErrorBox(Display.getDefault().getActiveShell(), errorMsg);
CTabFolder queryResultTabFolder = queryResultComp.getQueryResultTabFolder();
queryResultComp.disposeAllResult();
if (event.getMessage().length() <= 0) {
queryResultComp.makeEmptyResult();
} else {
if (event.getMessage().length() > 0) {
queryResultComp.makeLogResult(queries, event.getMessage());
}
}
if (queryResultTabFolder.getItemCount() > 0) {
queryResultTabFolder.setSelection(queryResultTabFolder.getItemCount() - 1);
}
queryResultComp.setCanDispose(true);
}
});
return;
}
final Vector<String> qVector = QueryUtil.queriesToQuery(queries);
int currentQueryIndex = 0;
int cntResults = 0;
String noSelectSql = "";
StringBuilder log = new StringBuilder(256);
@SuppressWarnings("unused") boolean hasModifyQuery = false;
@SuppressWarnings("unused") boolean isIsolationHigher = false;
long beginTimestamp = 0;
double elapsedTime = 0.0;
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(3);
result = null;
String multiQuerySql = null;
final Vector<QueryExecuter> curResult = new Vector<QueryExecuter>();
if (database == null) {
database = ((QueryUnit) queryEditor.getEditorInput()).getDatabase();
}
try {
if (qVector.isEmpty()) {
return;
} else {
isIsolationHigher = queryEditor.isIsolationHigherThanRepeatableRead(connection.getConnection(), queryEditor.isActive());
}
ServerInfo serverInfo = null;
if (database != null) {
serverInfo = this.database.getServer().getServerInfo();
}
RecentlyUsedSQLDetailPersistUtils.load(database);
boolean enableSearchUnit = QueryOptions.getEnableSearchUnit(serverInfo);
int unitCount = QueryOptions.getSearchUnitCount(serverInfo);
int sqlTotalCount = qVector.size();
for (int i = 0; i < sqlTotalCount; i++) {
currentQueryIndex = i;
log.delete(0, log.length());
long endTimestamp = 0;
SQLHistoryDetail sqlHistoryDetail = new SQLHistoryDetail();
sqlHistoryDetail.setExecuteTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()));
sql = qVector.get(i).toString();
if (database.getDatabaseInfo().isShard()) {
if (queryEditor.getDefaultShardQueryType() == DatabaseInfo.SHARD_QUERY_TYPE_ID) {
sql = QueryUtil.wrapShardQueryWithId(sql, queryEditor.getShardId());
} else {
sql = QueryUtil.wrapShardQueryWithVal(sql, queryEditor.getShardVal());
}
}
if (sql != null && sql.trim().lastIndexOf(";") == -1) {
sql += ";";
}
String orignSQL = sql;
if (enableSearchUnit && unitCount > 0) {
multiQuerySql = SqlParser.getPaginatingSqlClause(sql);
}
String order = StringUtil.getOrdinalFromCardinalNumber(i + 1);
if (multiQuerySql == null) {
sql = SqlParser.convertComment(sql);
beginTimestamp = System.currentTimeMillis();
try {
stmt = QueryExecuter.getStatement(connection.getConnection(), sql, false, false);
} catch (final SQLException e) {
throw e;
}
if (stmt.hasResultSet()) {
stmt.setQueryInfo(false);
stmt.setOnlyQueryPlan(false);
try {
stmt.executeQuery();
endTimestamp = System.currentTimeMillis();
rs = (CUBRIDResultSetProxy) stmt.getResultSet();
} catch (final SQLException e) {
throw e;
}
elapsedTime = (endTimestamp - beginTimestamp) * 0.001;
String elapsedTimeStr = nf.format(elapsedTime);
if (elapsedTime < 0.001) {
elapsedTimeStr = "0.000";
}
List<String> columnTableNameList = UIQueryUtil.loadColumnTableNameList(stmt);
result = createQueryExecutor(queryEditor, cntResults, sql, database, connection, orignSQL, columnTableNameList);
result.makeResult(rs);
String queryMsg = Messages.bind(Messages.querySeq, order) + "[ " + elapsedTimeStr + " " + Messages.second + " , " + Messages.totalRows + " : " + result.cntRecord + " ]" + StringUtil.NEWLINE;
result.setQueryMsg(queryMsg);
sqlHistoryDetail.setExecuteInfo(queryMsg);
sqlHistoryDetail.setElapseTime(elapsedTimeStr);
if (stmt.getStatementType() == CUBRIDCommandType.CUBRID_STMT_EVALUATE || stmt.getStatementType() == CUBRIDCommandType.CUBRID_STMT_CALL) {
hasModifyQuery = true;
}
curResult.addElement(result);
queryExecuterMap.put(sql, result);
cntResults++;
} else {
byte execType = stmt.getStatementType();
/*
* the previous version , the variable
* threadExecResult is class field, but why ? is it
* necessary?
*/
int threadExecResult = 0;
try {
threadExecResult = stmt.executeUpdate();
endTimestamp = System.currentTimeMillis();
} catch (final SQLException ee) {
throw ee;
}
elapsedTime = (endTimestamp - beginTimestamp) * 0.001;
int cntModify = threadExecResult;
noSelectSql += sql + StringUtil.NEWLINE;
hasModifyQuery = true;
log.append(Messages.bind(Messages.querySeq, order)).append(" ");
switch(execType) {
case CUBRIDCommandType.CUBRID_STMT_ALTER_CLASS:
case CUBRIDCommandType.CUBRID_STMT_ALTER_SERIAL:
case CUBRIDCommandType.CUBRID_STMT_RENAME_CLASS:
case CUBRIDCommandType.CUBRID_STMT_RENAME_TRIGGER:
log.append(Messages.alterOk);
break;
case CUBRIDCommandType.CUBRID_STMT_CREATE_CLASS:
case CUBRIDCommandType.CUBRID_STMT_CREATE_INDEX:
case CUBRIDCommandType.CUBRID_STMT_CREATE_TRIGGER:
case CUBRIDCommandType.CUBRID_STMT_CREATE_SERIAL:
log.append(Messages.createOk);
break;
case CUBRIDCommandType.CUBRID_STMT_DROP_DATABASE:
case CUBRIDCommandType.CUBRID_STMT_DROP_CLASS:
case CUBRIDCommandType.CUBRID_STMT_DROP_INDEX:
case CUBRIDCommandType.CUBRID_STMT_DROP_LABEL:
case CUBRIDCommandType.CUBRID_STMT_DROP_TRIGGER:
case CUBRIDCommandType.CUBRID_STMT_DROP_SERIAL:
case CUBRIDCommandType.CUBRID_STMT_REMOVE_TRIGGER:
log.append(Messages.dropOk);
break;
case CUBRIDCommandType.CUBRID_STMT_INSERT:
log.append(Messages.bind(Messages.insertOk, cntModify));
break;
case CUBRIDCommandType.CUBRID_STMT_SELECT:
break;
case CUBRIDCommandType.CUBRID_STMT_UPDATE:
log.append(Messages.bind(Messages.updateOk2, cntModify));
break;
case CUBRIDCommandType.CUBRID_STMT_DELETE:
log.append(Messages.bind(Messages.deleteOk, cntModify));
break;
/*
* Under two line works disable button when query's
* last command is commit/rollback
*/
case CUBRIDCommandType.CUBRID_STMT_COMMIT_WORK:
case CUBRIDCommandType.CUBRID_STMT_ROLLBACK_WORK:
hasModifyQuery = false;
default:
log.append(Messages.queryOk);
break;
}
String elapsedTimeStr = nf.format(elapsedTime);
if (elapsedTime < 0.001) {
elapsedTimeStr = "0.000";
}
log.append(" [").append(elapsedTimeStr).append(" ");
log.append(Messages.second).append("]").append(StringUtil.NEWLINE);
logs.append(log);
logs.append(QueryEditorPart.makeSqlLogOnResult(sql));
sqlHistoryDetail.setExecuteInfo(log.toString());
sqlHistoryDetail.setElapseTime(elapsedTimeStr);
}
} else {
result = createQueryExecutor(queryEditor, cntResults, "", database, connection, orignSQL, null);
result.setMultiQuerySql(multiQuerySql);
result.setQueryMsg(Messages.bind(Messages.querySeq, order) + StringUtil.NEWLINE);
result.setSqlDetailHistory(sqlHistoryDetail);
queryExecuterMap.put(sql, result);
try {
result.makeTable(1, false);
} catch (final SQLException ee) {
throw ee;
}
curResult.addElement(result);
cntResults++;
}
QueryUtil.freeQuery(stmt, rs);
stmt = null;
rs = null;
// SQL execution log
sqlHistoryDetail.setSql(sql);
RecentlyUsedSQLDetailPersistUtils.addLog(database, sqlHistoryDetail);
}
// if (editor.isAutocommit()) {
// editor.queryAction(QUERY_ACTION.COMMIT);
// }
} catch (final SQLException event) {
LOGGER.error(event.getMessage(), event);
// }
if (multiQuerySql == null || result == null) {
final String errorSql = (String) qVector.get(currentQueryIndex);
noSelectSql += errorSql;
logs.append(QueryEditorPart.makeSqlErrorOnResult(currentQueryIndex, errorSql, event));
} else {
noSelectSql += result.getQuerySql();
logs.append(result.getQueryMsg());
}
logsMap.put(sql, logs);
} catch (final Exception event) {
LOGGER.error(event.getMessage(), event);
if (multiQuerySql == null || result == null) {
final String errorSql = (String) qVector.get(currentQueryIndex);
noSelectSql += errorSql;
logs.append(QueryEditorPart.makeSqlErrorOnResult(currentQueryIndex, errorSql, event));
} else {
noSelectSql += result.getQuerySql();
logs.append(result.getQueryMsg());
}
logsMap.put(sql, logs);
} finally {
RecentlyUsedSQLDetailPersistUtils.save(database);
QueryUtil.freeQuery(stmt, rs);
stmt = null;
rs = null;
if (connection != null && connection.isAutoClosable()) {
connection.close();
}
}
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class DatabaseNavigatorMenu method selectMenuItem.
/**
* target a database selection change
*
* @param item DatabaseMenuItem
*/
public void selectMenuItem(DatabaseMenuItem item) {
DatabaseMenuItem tmpItem = item;
if (tmpItem != null) {
if (selectedMenuItem != null && !selectedMenuItem.isDisposed()) {
selectedMenuItem.setSelection(false);
}
if (listener != null) {
Event e = new Event();
e.data = tmpItem.getDatabase();
listener.handleEvent(e);
}
if (editor.getConnection() == null) {
tmpItem = nullDbMenuItem;
}
tmpItem.setSelection(true);
selectedMenuItem = tmpItem;
setText(tmpItem);
selectdDb = tmpItem.getDatabase();
// [TOOLS-2425]Support shard broker
if (CubridDatabase.hasValidDatabaseInfo(selectdDb)) {
DatabaseInfo dbInfo = selectdDb.getDatabaseInfo();
if (dbInfo.isShard()) {
editor.setShardId(dbInfo.getCurrentShardId());
editor.setShardVal(dbInfo.getCurrentShardVal());
editor.setShardQueryType(dbInfo.getShardQueryType());
}
}
editor.changeQueryEditorPartName(selectDbLabel.getText());
editor.changeQueryEditorPartNameWithShard();
/*For bug Tools-1250 Update the auto commit status by select db*/
if (selectdDb != null && lastSelectdDb != null && !StringUtil.isEqualNotIgnoreNull(selectdDb.getId(), lastSelectdDb.getId())) {
ServerInfo serverInfo = selectdDb.getServer() == null ? null : selectdDb.getServer().getServerInfo();
boolean autoCommit = QueryOptions.getAutoCommit(serverInfo);
editor.setAutocommit(autoCommit);
}
/*Save current selectDB*/
lastSelectdDb = selectdDb;
lastUser = (selectdDb == null ? null : selectdDb.getUserName());
LayoutManager.getInstance().getTitleLineContrItem().changeTitleForQueryEditor(selectdDb);
LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(selectdDb, editor);
}
}
use of com.cubrid.cubridmanager.core.common.model.ServerInfo in project cubrid-manager by CUBRID.
the class QueryPropertyComposite method loadPreference.
/**
* load query option from preference store
*/
public void loadPreference() {
ServerInfo serverInfo = server == null ? null : server.getServerInfo();
boolean autoCommit = QueryOptions.getAutoCommit(serverInfo);
boolean unitInstances = QueryOptions.getEnableSearchUnit(serverInfo);
int recordCount = QueryOptions.getSearchUnitCount(serverInfo);
int pageCount = QueryOptions.getPageLimit(serverInfo);
int loadSize = QueryOptions.getLobLoadSize(serverInfo);
boolean isKeywordLowerCase = QueryOptions.getKeywordLowercase(serverInfo);
boolean isNoAutoUppercaseKeyword = QueryOptions.getNoAutoUppercaseKeyword(serverInfo);
boolean isWithoutPromptSave = QueryOptions.getWithoutPromptSave(serverInfo);
boolean isShowMultiPageConfirm = QueryOptions.getMultiPageConfirm();
boolean isUseScientificNotation = QueryOptions.getUseScientificNotation(serverInfo);
fontColorRed = QueryOptions.getFontColorRed(serverInfo);
fontColorBlue = QueryOptions.getFontColorBlue(serverInfo);
fontColorGreen = QueryOptions.getFontColorGreen(serverInfo);
fontString = QueryOptions.getFontString(serverInfo);
autocommitBtn.setSelection(autoCommit);
searchUnitBtn.setSelection(unitInstances);
unitCountSpinner.setEnabled(unitInstances);
unitCountSpinner.setSelection(recordCount);
loadSizeSpinner.setSelection(loadSize);
pageUnitCountSpinner.setSelection(pageCount);
keywordLowerBtn.setSelection(isKeywordLowerCase);
keywordLowerBtn.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
autoNoUppercaseKeywordBtn.setEnabled(!keywordLowerBtn.getSelection());
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
autoNoUppercaseKeywordBtn.setSelection(isNoAutoUppercaseKeyword);
withoutPromptSaveBtn.setSelection(isWithoutPromptSave);
multiPageConfirmBtn.setSelection(isShowMultiPageConfirm);
changeExampleFont();
autoNoUppercaseKeywordBtn.setEnabled(!isKeywordLowerCase);
useScientificNotationBtn.setSelection(isUseScientificNotation);
}
Aggregations