use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class ImportDataFromFileDialog method updateData.
/**
*
* Update data
*
* @param parameterList List<PstmtParameter>
*/
private void updateData(List<PstmtParameter> parameterList) {
taskList.clear();
String fileName = fileNameTxt.getText();
String charset = fileCharsetCombo.getText();
int threadCount = threadCountSpinner.getSelection();
int commitedLineOnce = commitLineSpinner.getSelection();
int totalLine = Integer.parseInt(totalLinesText.getText());
int threadLine = totalLine / threadCount;
int line = totalLine % threadCount;
int startRow = 0;
int totalProgress = 0;
boolean isIgnoreError = importErrorControl.isIgoreOrBreak();
if (isIgnoreError) {
errorLogDir = PstmtDataTask.makeErrorLogDir();
} else {
errorLogDir = null;
}
if (importFileHandler == null) {
importFileHandler = ImportFileHandlerFactory.getHandler(fileName, charset);
}
for (int i = 0; i < threadCount; i++) {
// FIXME move this logic to core module
int rowCount = threadLine;
if (i == threadCount - 1) {
rowCount = threadLine + line;
}
int commitCount = rowCount / commitedLineOnce + (rowCount % commitedLineOnce > 0 ? 1 : 0);
int taskProgress = commitCount * PstmtDataTask.PROGRESS_COMMIT + rowCount * PstmtDataTask.PROGRESS_ROW;
totalProgress = totalProgress + taskProgress + PstmtDataTask.PROGRESS_ROW;
PstmtDataTask task = new PstmtDataTask(sqlTxt.getText(), database, fileNameTxt.getText(), parameterList, startRow, rowCount, commitedLineOnce, charset, firstRowAsColumnBtn.getSelection(), isIgnoreError, errorLogDir, importFileHandler);
task.setTotalProgress(taskProgress);
taskList.add(task);
startRow += rowCount;
}
getShell().setVisible(false);
beginTimestamp = System.currentTimeMillis();
String jobName = Messages.executeSqlJobName;
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getServerInfo().getServerName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
final IProgressMonitor pmGroup = Job.getJobManager().createProgressGroup();
pmGroup.beginTask(jobName, totalProgress);
setStartShowResult(false);
final CountDownLatch cdl = new CountDownLatch(taskList.size());
final List<PstmtDataTask> threadTaskList = taskList;
for (PstmtDataTask task : taskList) {
TaskJobExecutor taskExec = new CommonTaskJobExec() {
public IStatus exec(IProgressMonitor monitor) {
IStatus status = super.exec(monitor);
if (Status.CANCEL_STATUS == status) {
return status;
}
return Status.OK_STATUS;
}
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.CANCEL_STATUS) {
for (PstmtDataTask task : threadTaskList) {
if (!task.isCancel()) {
task.cancel();
}
}
}
countDownAndAwait(cdl);
Display.getDefault().syncExec(new Runnable() {
public void run() {
pmGroup.done();
finish();
}
});
}
};
taskExec.addTask(task);
TaskJob job = new TaskJob(jobName, taskExec);
if (jobFamily != null) {
job.setJobFamily(jobFamily);
}
job.setPriority(Job.LONG);
job.setUser(false);
job.setProgressGroup(pmGroup, task.getTotalProgress());
job.schedule();
try {
Thread.sleep(30);
} catch (InterruptedException e) {
}
pmGroup.worked(PstmtDataTask.PROGRESS_ROW);
}
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class CopyDatabaseDialog method okPressed.
/**
* When ok button press,call this method
*/
protected void okPressed() {
if (!verify()) {
return;
}
destDbName = destinationDBNameText.getText();
if (!CommonUITool.openConfirmBox(parentComp.getShell(), Messages.warnYesNoCopyDb)) {
return;
}
SocketTask checkTask = getCheckDirsTask();
SocketTask copyTask = getCopyDbTask();
TaskJobExecutor taskExec = new CommonTaskJobExec(this);
taskExec.addTask(checkTask);
taskExec.addTask(copyTask);
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
jobName = Messages.msgCopyDbRearJobName + " - " + dbName + "@" + serverName;
taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class UserEditor method loadData.
/**
*
* Load data
*
* @return <code>true</code> if it is successfully;<code>false</code>
* otherwise
*/
public boolean loadData() {
final CommonQueryTask<DbUserInfoList> userTask = new CommonQueryTask<DbUserInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbUserInfoList(), database.getDatabaseInfo().getCharSet());
userTask.setDbName(database.getName());
final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo());
final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo());
TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {
@SuppressWarnings("unchecked")
@Override
public IStatus exec(IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
for (ITask t : taskList) {
if (t instanceof GetAllClassListTask) {
allClassInfoList = ((GetAllClassListTask) t).getAllClassInfoList();
} else {
t.execute();
}
if (t instanceof CommonQueryTask) {
userListInfo = ((CommonQueryTask<DbUserInfoList>) t).getResultModel();
}
if (t instanceof GetAllPartitionClassTask) {
partitionClassMap = ((GetAllPartitionClassTask) t).getPartitionClassMap();
}
final String msg = t.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 (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
Display.getDefault().syncExec(new Runnable() {
public void run() {
initial();
}
});
return Status.OK_STATUS;
}
};
taskJobExecutor.addTask(userTask);
taskJobExecutor.addTask(classInfoTask);
taskJobExecutor.addTask(partitionTask);
String jobName = Messages.viewUserInfoJobName + " - " + userName + "@" + database.getName() + "@" + database.getServer().getName();
taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
return true;
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class ServiceDashboardEditor method loadServerBrokerInfo.
/**
* Load Server Broker Info
*/
private void loadServerBrokerInfo(final ServerInfo serverInfo, final String key) {
final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), new BrokerInfos());
TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {
public void completeAll() {
Object input = serviceTreeViewer.getInput();
ServiceDashboardInfo sDashInfo = getSelectedDashInfo(input, serverInfo.getServerName(), key);
BrokerInfos brokerInfos = task.getResultModel();
setBrokerData(sDashInfo, brokerInfos);
serviceTreeViewer.refresh(input);
}
public IStatus postTaskFinished(ITask task) {
return Status.OK_STATUS;
}
});
taskJobExec.addTask(task);
executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerBrokerInfo);
}
use of com.cubrid.common.ui.spi.progress.TaskJobExecutor in project cubrid-manager by CUBRID.
the class DBSpaceLabelProvider method loadVolumeData.
public void loadVolumeData() {
//if no database on this server ,don't get volumn data
if (serverInfo.getAllDatabaseList().size() == 0 || databaseInfoList == null) {
return;
}
final List<CommonQueryTask<DbSpaceInfoList>> getVolumnTaskList = new ArrayList<CommonQueryTask<DbSpaceInfoList>>();
if (serverInfo.getAllDatabaseList() != null) {
for (String dbName : serverInfo.getAllDatabaseList()) {
for (DatabaseInfo databaseInfo : databaseInfoList) {
// only load start database volumn data
if (dbName.equals(databaseInfo.getDbName()) && databaseInfo.getRunningType() == DbRunningType.CS) {
CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(serverInfo, CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoList());
task.setDbName(dbName);
getVolumnTaskList.add(task);
break;
}
}
}
}
//if no start database don't get volumn data
if (getVolumnTaskList.size() == 0) {
return;
}
TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {
public void completeAll() {
List<DBVolumeSpaceInfo> dbVolumeSpaceInfoList = new ArrayList<DBVolumeSpaceInfo>();
for (CommonQueryTask<DbSpaceInfoList> task : getVolumnTaskList) {
DbSpaceInfoList dbSpaceInfoList = task.getResultModel();
freespaceOnStorage = ((long) dbSpaceInfoList.getFreespace()) * 1024l * 1024l;
DBVolumeSpaceInfo dbSpaceInfo = new DBVolumeSpaceInfo(dbSpaceInfoList.getDbname());
dbSpaceInfo.setPageSize(dbSpaceInfoList.getPagesize());
dbVolumeSpaceInfoList.add(dbSpaceInfo);
if (dbSpaceInfoList != null) {
for (DbSpaceInfo spaceInfo : dbSpaceInfoList.getSpaceinfo()) {
dbSpaceInfo.addVolumeSpaceInfo(spaceInfo);
}
}
}
setVolumeData(dbVolumeSpaceInfoList);
finishedCount++;
updateToolBar();
}
public IStatus postTaskFinished(ITask task) {
return Status.OK_STATUS;
}
});
for (CommonQueryTask<DbSpaceInfoList> task : getVolumnTaskList) {
taskJobExec.addTask(task);
}
String serverName = serverInfo.getServerName();
String jobName = Messages.taskGetVolumeInfo + serverName;
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverName);
taskJobExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Aggregations