use of com.cubrid.cubridmanager.core.common.task.CommonQueryTask in project cubrid-manager by CUBRID.
the class RenameDatabaseAction method run.
public void run() {
Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
setEnabled(false);
return;
}
final CubridDatabase database = (CubridDatabase) obj[0];
ISelectionProvider provider = this.getSelectionProvider();
final TreeViewer viewer = (TreeViewer) provider;
String serverName = database.getServer().getName();
String dbName = database.getName();
final String jobName = serverName + "-" + dbName + "-" + Messages.msgRenameDBRearJobName;
final RenameDatabaseDialog dialog = new RenameDatabaseDialog(getShell(), new ITaskExecutorInterceptor() {
public void completeAll() {
QueryOptions.removePref(database.getDatabaseInfo());
CommonUITool.openInformationBox(Messages.titleSuccess, Messages.bind(Messages.msgRenameDBComplete, jobName));
CommonUITool.refreshNavigatorTree(viewer, database.getParent());
}
public IStatus postTaskFinished(ITask task) {
return Status.OK_STATUS;
}
});
dialog.setDatabase(database);
final Shell shell = getShell();
TaskExecutor taskExcutor = new TaskExecutor() {
@SuppressWarnings("unchecked")
public boolean exec(final IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return false;
}
monitor.beginTask(Messages.getDbSpaceInfoTaskName, IProgressMonitor.UNKNOWN);
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (openErrorBox(shell, msg, monitor)) {
return false;
}
if (monitor.isCanceled()) {
return false;
}
if (task instanceof CommonQueryTask) {
dbSpaceInfo = ((CommonQueryTask<DbSpaceInfoList>) task).getResultModel();
}
}
return true;
}
};
dbSpaceInfo = new DbSpaceInfoList();
CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbSpaceInfo);
task.setDbName(database.getLabel());
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
if (taskExcutor.isSuccess()) {
dialog.setDbSpaceInfoList(dbSpaceInfo);
dialog.open();
}
}
use of com.cubrid.cubridmanager.core.common.task.CommonQueryTask in project cubrid-manager by CUBRID.
the class DatabaseDashboardEditor method loadBrokerInfo.
/**
* load broker information
*/
public void loadBrokerInfo() {
// if database is stop, do not get data
if (database.getRunningType() != DbRunningType.CS) {
return;
}
// broker info tasks
BrokerInfos brokerInfos = new BrokerInfos();
final CommonQueryTask<BrokerInfos> brokerInfosTask = new CommonQueryTask<BrokerInfos>(database.getServer().getServerInfo(), CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
new Thread(new Runnable() {
public void run() {
brokerInfosTask.execute();
if (!brokerInfosTask.isSuccess()) {
brokerInfosTask.finish();
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
process();
}
});
}
private void process() {
asinfoLst.clear();
brokerInfoListData.clear();
BrokerInfos brokerInfos = brokerInfosTask.getResultModel();
if (null != brokerInfos) {
BrokerInfoList list = brokerInfos.getBorkerInfoList();
if (list != null && list.getBrokerInfoList() != null) {
// all broker
List<BrokerInfo> newBrokerInfoList = list.getBrokerInfoList();
for (BrokerInfo brokerInfo : newBrokerInfoList) {
BrokerStatusInfos brokerStatusInfos = new BrokerStatusInfos();
final GetBrokerStatusInfosTask<BrokerStatusInfos> statisTask = new GetBrokerStatusInfosTask<BrokerStatusInfos>(database.getServer().getServerInfo(), CommonSendMsg.getGetBrokerStatusItems(), brokerStatusInfos);
statisTask.setBrokerName(brokerInfo.getName());
statisTask.execute();
brokerStatusInfos = statisTask.getResultModel();
if (brokerStatusInfos != null) {
//one broker status
List<ApplyServerInfo> applyServerInfoList = brokerStatusInfos.getAsinfo();
for (ApplyServerInfo applyServerInfo : applyServerInfoList) {
if (database.getName().equalsIgnoreCase(applyServerInfo.getAs_dbname())) {
HashMap<String, ApplyServerInfo> valueMap = new HashMap<String, ApplyServerInfo>();
valueMap.put(brokerInfo.getName(), applyServerInfo);
asinfoLst.add(valueMap);
}
}
}
statisTask.finish();
}
}
}
//set task obejct to table view
for (HashMap<String, ApplyServerInfo> brokerValueMap : asinfoLst) {
for (Entry<String, ApplyServerInfo> entry : brokerValueMap.entrySet()) {
String brokerName = entry.getKey();
ApplyServerInfo applyServerInfo = entry.getValue();
Map<String, String> brokerInfoMap = new HashMap<String, String>();
brokerInfoMap.put("0", brokerName);
brokerInfoMap.put("1", applyServerInfo.getAs_id());
brokerInfoMap.put("2", applyServerInfo.getAs_pid());
brokerInfoMap.put("3", applyServerInfo.getAs_num_query());
brokerInfoMap.put("4", applyServerInfo.getAs_long_query());
brokerInfoMap.put("5", applyServerInfo.getAs_status());
brokerInfoMap.put("6", applyServerInfo.getAs_lct());
brokerInfoListData.add(brokerInfoMap);
}
}
setBrokerInfoData();
brokerInfosTask.finish();
}
}).start();
}
use of com.cubrid.cubridmanager.core.common.task.CommonQueryTask in project cubrid-manager by CUBRID.
the class DatabaseDashboardEditor method loadTransactionInfo.
/**
* load lock and transaction information
*/
public void loadTransactionInfo() {
//if database is stop, do not get data
if (database.getRunningType() != DbRunningType.CS) {
return;
}
final CommonQueryTask<DatabaseLockInfo> getLockInfotask = new CommonQueryTask<DatabaseLockInfo>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DatabaseLockInfo());
getLockInfotask.setDbName(database.getName());
final CommonQueryTask<DbTransactionList> getTransactionTask = new CommonQueryTask<DbTransactionList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbTransactionList());
getTransactionTask.setDbName(database.getName());
new Thread(new Runnable() {
public void run() {
getLockInfotask.execute();
if (!getLockInfotask.isSuccess()) {
getLockInfotask.finish();
return;
}
getTransactionTask.execute();
if (!getTransactionTask.isSuccess()) {
getTransactionTask.finish();
return;
}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
process();
}
});
}
private void process() {
lockAndTransactionListData.clear();
databaseLockInfo = getLockInfotask.getResultModel();
LockInfo lockInfo = databaseLockInfo.getLockInfo();
if (lockInfo == null) {
return;
}
DbLotInfo dbLotInfo = lockInfo.getDbLotInfo();
if (dbLotInfo == null) {
return;
}
if (dbLotInfo.getDbLotEntryList() != null) {
//get Lock
for (DbLotEntry dbLot : dbLotInfo.getDbLotEntryList()) {
Map<String, String> map = new HashMap<String, String>();
if (dbLot.getLockHoldersList() != null) {
lockAndTransactionListData.add(map);
map.put("4", dbLot.getOb_type());
//get lock holder
for (int i = 0; i < dbLot.getLockHoldersList().size(); i++) {
LockHolders lockHolders = dbLot.getLockHoldersList().get(i);
//add mode to the last mode
String previousMode = map.get("5");
if (i != 0 && previousMode != null) {
previousMode += ",";
}
if (previousMode != null) {
previousMode += lockHolders.getGranted_mode();
} else {
previousMode = lockHolders.getGranted_mode();
}
map.put("5", previousMode);
//get DatabaseTransaction which id is equlas lock holder tranid
for (DatabaseTransaction tran : lockInfo.getTransaction()) {
if (tran.getIndex() == lockHolders.getTran_index()) {
map.put("0", Integer.toString(tran.getIndex()));
map.put("1", tran.getUid());
map.put("2", tran.getHost());
map.put("3", tran.getPid());
}
}
}
}
}
}
setTransactionInfoData();
getLockInfotask.finish();
getTransactionTask.finish();
}
}).start();
}
use of com.cubrid.cubridmanager.core.common.task.CommonQueryTask in project cubrid-manager by CUBRID.
the class DatabaseDashboardEditor method showLogView.
/**
* show sql log view at broker table
*
* @param type sql type
*/
public void showLogView(String type) {
try {
int i = brokerInfoTable.getSelectionIndex();
if (i < 0) {
return;
}
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
String brokerName = brokerInfoTable.getItem(i).getText(0);
String serverId = brokerInfoTable.getItem(i).getText(1);
//get all log infor
BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
final CommonQueryTask<BrokerLogInfos> task = new CommonQueryTask<BrokerLogInfos>(database.getDatabaseInfo().getServerInfo(), CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
task.setBroker(brokerName);
task.execute();
brokerLogInfos = task.getResultModel();
String logFileName = brokerName + "_" + serverId + "." + type + ".log";
sqlLogViewPartName = logFileName + "@" + database.getServer().getLabel() + ":" + database.getServer().getMonPort();
List<LogInfo> logInfoList = brokerLogInfos == null ? null : brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
task.finish();
//get the current log
LogInfo logInfo = null;
if (logInfoList != null && !logInfoList.isEmpty()) {
for (LogInfo logInfoInlist : logInfoList) {
if (logFileName.equals(logInfoInlist.getName())) {
logInfo = logInfoInlist;
break;
}
}
}
if (logInfo == null) {
String msg = Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.errLogFileNoExist, logFileName);
LOGGER.error(msg);
//CommonUITool.openErrorBox(msg);
return;
}
final String filePath = logInfo.getPath();
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (ITask task : taskList) {
task.execute();
final String msg = task.getErrorMsg();
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
}
if (task instanceof CheckFileTask) {
CheckFileTask checkFileTask = (CheckFileTask) task;
final String[] files = checkFileTask.getExistFiles();
if (files == null || files.length == 0) {
return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, Messages.bind(com.cubrid.cubridmanager.ui.logs.Messages.errLogFileNoExist, filePath));
}
} else if (task instanceof GetLogListTask) {
GetLogListTask getLogListTask = (GetLogListTask) task;
final LogContentInfo logContentInfo = (LogContentInfo) getLogListTask.getLogContent();
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
ICubridNode logInfoNode = new DefaultCubridNode("", "", "");
IEditorPart editor = window.getActivePage().openEditor(logInfoNode, LogEditorPart.ID);
((LogEditorPart) editor).setTableInfo(logContentInfo, true);
((LogEditorPart) editor).setShowLogPartName(sqlLogViewPartName);
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
task.finish();
}
return Status.OK_STATUS;
}
};
CheckFileTask checkFileTask = new CheckFileTask(cubridNode.getServer().getServerInfo());
checkFileTask.setFile(new String[] { filePath });
taskJobExecutor.addTask(checkFileTask);
GetLogListTask getLogListTask = new GetLogListTask(cubridNode.getServer().getServerInfo());
getLogListTask.setPath(filePath);
getLogListTask.setStart("1");
getLogListTask.setEnd("100");
taskJobExecutor.addTask(getLogListTask);
String jobName = com.cubrid.cubridmanager.ui.logs.Messages.viewLogJobName + " - " + cubridNode.getName() + "@" + cubridNode.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
} catch (Exception e) {
LOGGER.error(Messages.exportDashboardOpenSQLLogErrMsg, e);
// CommonUITool.openErrorBox(Messages.exportDashboardOpenSQLLogErrMsg);
}
}
use of com.cubrid.cubridmanager.core.common.task.CommonQueryTask in project cubrid-manager by CUBRID.
the class DatabaseDashboardEditor method createVolumnComposite.
/**
* create volumn information composite
*
* @param bar ExpandBar
* @param bar index
*
*/
public void createVolumnComposite(ExpandBar bar, int index) {
ExpandItem volumnItem = new ExpandItem(bar, SWT.NONE, index);
volumnItem.setText(Messages.exportDashboardVolumnTableTitle);
Composite volumnComposite = new Composite(bar, SWT.NONE);
volumnComposite.setLayout(new FillLayout());
volumnInfoTableViewer = new TableViewer(volumnComposite, SWT.BORDER | SWT.FULL_SELECTION);
volumnInfoTableViewer.getTable().setHeaderVisible(true);
volumnInfoTableViewer.getTable().setLinesVisible(true);
final TableViewerColumn columnVolumn = new TableViewerColumn(volumnInfoTableViewer, SWT.CENTER);
columnVolumn.getColumn().setWidth(140);
columnVolumn.getColumn().setText(Messages.volumnTableVolumnNameColumnLabel);
columnVolumn.getColumn().setToolTipText(Messages.volumnTableVolumnNameColumnLabel);
final TableViewerColumn columnType = new TableViewerColumn(volumnInfoTableViewer, SWT.CENTER);
columnType.getColumn().setWidth(90);
columnType.getColumn().setText(Messages.volumnTableVolumnTypeColumnLabel);
columnType.getColumn().setToolTipText(Messages.volumnTableVolumnTypeColumnLabel);
final TableViewerColumn columnFreeSize = new TableViewerColumn(volumnInfoTableViewer, SWT.RIGHT);
columnFreeSize.getColumn().setWidth(90);
columnFreeSize.getColumn().setText(Messages.volumnTableFreesizeColumnLabel);
columnFreeSize.getColumn().setToolTipText(Messages.volumnTableFreesizeColumnLabel);
final TableViewerColumn columnTotalSize = new TableViewerColumn(volumnInfoTableViewer, SWT.RIGHT);
columnTotalSize.getColumn().setWidth(90);
columnTotalSize.getColumn().setText(Messages.volumnTableTotalsizeColumnLabel);
columnTotalSize.getColumn().setToolTipText(Messages.volumnTableTotalsizeColumnLabel);
final TableViewerColumn lastModifyDate = new TableViewerColumn(volumnInfoTableViewer, SWT.CENTER);
lastModifyDate.getColumn().setWidth(90);
lastModifyDate.getColumn().setText(Messages.volumnTableLastModifyTimeColumnLabel);
lastModifyDate.getColumn().setToolTipText(Messages.volumnTableLastModifyTimeColumnLabel);
final TableViewerColumn columnLocation = new TableViewerColumn(volumnInfoTableViewer, SWT.LEFT);
columnLocation.getColumn().setWidth(300);
columnLocation.getColumn().setText(Messages.tblColumnVolPath);
columnLocation.getColumn().setToolTipText(Messages.tblColumnVolPath);
volumnInfoTableViewer.setContentProvider(new TableContentProvider());
volumnInfoTableViewer.setLabelProvider(new TableLabelProvider());
Table table = volumnInfoTableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
volumnInfoTableViewer.setInput(volumnInfoListData);
volumnItem.setControl(volumnComposite);
volumnItem.setHeight(130);
volumnItem.setExpanded(true);
Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
final MenuItem itemAddVolumn = new MenuItem(menu, SWT.PUSH);
itemAddVolumn.setText(com.cubrid.cubridmanager.ui.spi.Messages.setAddVolumeActionName);
itemAddVolumn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
DefaultSchemaNode node = null;
for (ICubridNode cubridNode : database.getChildren()) {
if (cubridNode.getType().equals(CubridNodeType.DBSPACE_FOLDER)) {
node = (DefaultSchemaNode) cubridNode;
}
}
if (node == null) {
return;
}
// Gets the status of adding volume
GetAddVolumeStatusInfo getAddVolumeStatusInfo = new GetAddVolumeStatusInfo();
final CommonQueryTask<GetAddVolumeStatusInfo> statusTask = new CommonQueryTask<GetAddVolumeStatusInfo>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), getAddVolumeStatusInfo);
statusTask.setDbName(database.getLabel());
TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.cubridmanager.ui.cubrid.dbspace.Messages.getVolumeInfoTaskName);
taskExecutor.addTask(statusTask);
CommonQueryTask<DbSpaceInfoList> spaceInfoTask = null;
DatabaseInfo databaseInfo = database.getDatabaseInfo();
DbSpaceInfoList dbSpaceInfoList = databaseInfo.getDbSpaceInfoList();
int pageSize = 0;
if (null == dbSpaceInfoList) {
dbSpaceInfoList = new DbSpaceInfoList();
spaceInfoTask = new CommonQueryTask<DbSpaceInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), dbSpaceInfoList);
spaceInfoTask.setDbName(database.getLabel());
taskExecutor.addTask(spaceInfoTask);
}
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (spaceInfoTask == null) {
pageSize = dbSpaceInfoList.getPagesize();
} else {
final DbSpaceInfoList model = ((CommonQueryTask<DbSpaceInfoList>) spaceInfoTask).getResultModel();
pageSize = model.getPagesize();
}
getAddVolumeStatusInfo = statusTask.getResultModel();
//open add volumn dialog
AddVolumeDialog addVolumeDialog = new AddVolumeDialog(getSite().getShell());
addVolumeDialog.setGetAddVolumeStatusInfo(getAddVolumeStatusInfo);
addVolumeDialog.initPara(node);
addVolumeDialog.setTreeViewer(CubridNavigatorView.getNavigatorView("com.cubrid.cubridmanager.host.navigator").getViewer());
addVolumeDialog.setPageSize(pageSize);
int returnCode = addVolumeDialog.open();
//if add volumn refresh table
if (returnCode == IDialogConstants.OK_ID) {
volumnInfoListData.clear();
loadVolumnsInfo();
volumnInfoTableViewer.refresh();
}
}
});
volumnInfoTableViewer.getTable().setMenu(menu);
tableViewOnBarIndexMap.put(volumnInfoTableViewer, index);
}
Aggregations