use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class CreateTriggerDialog method executeByJDBC.
/**
*
* Execute to add or alter trigger by JDBC
*
* @param buttonId int
*/
private void executeByJDBC(int buttonId) {
// FIXME move this logic to core module
String createSQL = generateSqlText().toString();
if (StringUtil.isEmpty(createSQL)) {
return;
}
String taskName = null;
String message = null;
if (buttonId == IDialogConstants.OK_ID) {
taskName = Messages.bind(Messages.addTriggerTaskName, triggerName);
message = Messages.newTriggerSuccess;
} else if (buttonId == ALTER_TRIGGER_OK_ID) {
createSQL = createSQL.substring(createSQL.indexOf("ALTER TRIGGER "));
message = Messages.alterTriggerSuccess;
taskName = Messages.bind(Messages.alterTriggerTaskName, triggerName);
}
// add or alter triggers by JDBC
JDBCSqlExecuteTask jdbcTask = new JDBCSqlExecuteTask(taskName, database.getDatabaseInfo(), createSQL);
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(jdbcTask);
new ExecTaskWithProgress(taskExecutor).busyCursorWhile();
if (taskExecutor.isSuccess()) {
triggerName = triggerNameText.getText();
setReturnCode(buttonId);
close();
CommonUITool.openInformationBox(Messages.msgInformation, message);
}
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class BLOBCellPopupDialog method exportData.
/**
*
* Export data to file
*
* @param isOpenProgram boolean
* @param filePath String
*/
private boolean exportData(final String filePath, final boolean isOpenProgram) {
final String charsetName = fileCharsetCombo.getText();
if (currValue instanceof String) {
try {
"".getBytes(charsetName);
} catch (UnsupportedEncodingException e) {
CommonUITool.openErrorBox(Messages.errCharset);
return false;
}
}
AbstractUITask task = new AbstractUITask() {
boolean isSuccess = false;
public void execute(final IProgressMonitor monitor) {
BufferedWriter writer = null;
FileOutputStream out = null;
InputStream in = null;
try {
if (currValue instanceof String) {
String content = (String) currValue;
if (DBAttrTypeFormatter.isBinaryString(content)) {
content = DBAttrTypeFormatter.getInnerString(content);
byte[] bytes = DBAttrTypeFormatter.getBytes(content, 2);
content = new String(bytes, charsetName);
} else if (DBAttrTypeFormatter.isHexString(content)) {
content = DBAttrTypeFormatter.getInnerString(content);
byte[] bytes = DBAttrTypeFormatter.getBytes(content, 16);
content = new String(bytes, charsetName);
}
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), charsetName));
writer.write(content);
writer.flush();
} else if (currValue instanceof File) {
out = new FileOutputStream(filePath);
in = new FileInputStream((File) currValue);
byte[] bytes = new byte[1024];
int len = 0;
while ((len = in.read(bytes)) != -1) {
out.write(bytes, 0, len);
}
out.flush();
} else if (currValue instanceof byte[]) {
out = new FileOutputStream(filePath);
byte[] bytes = (byte[]) currValue;
out.write(bytes, 0, bytes.length);
out.flush();
}
isSuccess = true;
} catch (Exception e) {
errorMsg = e.getMessage();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
// ignore
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// ignore
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
// ignore
}
}
}
}
public void cancel() {
//empty
}
public void finish() {
//empty
}
public boolean isCancel() {
return false;
}
public boolean isSuccess() {
return isSuccess;
}
};
TaskExecutor taskExecutor = new CommonTaskExec(Messages.msgExportFieldData);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
if (isOpenProgram) {
return true;
}
CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgExportSuccess);
return true;
}
return false;
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class PropertyAction method run.
/**
* Open property dialog,view and set property
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (!isSupported(obj[0])) {
return;
}
final ICubridNode node = (ICubridNode) obj[0];
String type = node.getType();
if (CubridNodeType.SERVER.equals(type) || CubridNodeType.DATABASE_FOLDER.equals(type) || CubridNodeType.DATABASE.equals(type) || CubridNodeType.BROKER_FOLDER.equals(type) || CubridNodeType.BROKER.equals(type)) {
TaskExecutor taskExcutor = new GetPropertyExecutor(node, getShell());
ServerInfo serverInfo = node.getServer().getServerInfo();
GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
if (CubridNodeType.SERVER.equals(type)) {
taskExcutor.addTask(getCubridConfParameterTask);
taskExcutor.addTask(getBrokerConfParameterTask);
taskExcutor.addTask(getCMConfParameterTask);
if (CompatibleUtil.isSupportNewHAConfFile(serverInfo)) {
GetHAConfParameterTask getHAConfParameterTask = new GetHAConfParameterTask(serverInfo);
taskExcutor.addTask(getHAConfParameterTask);
}
}
if (CubridNodeType.DATABASE_FOLDER.equals(type) || CubridNodeType.DATABASE.equals(type)) {
taskExcutor.addTask(getCubridConfParameterTask);
}
if (CubridNodeType.BROKER_FOLDER.equals(type) || CubridNodeType.BROKER.equals(type)) {
taskExcutor.addTask(getBrokerConfParameterTask);
}
new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
}
if (!isCancel) {
Dialog dialog = PreferenceUtil.createPropertyDialog(getShell(), node);
dialog.open();
}
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class BrokerParameterPropertyPage method performOk.
/**
* Save the page content
*
* @return <code>true</code> if it saved successfully;<code>false</code>
* otherwise
*/
public boolean performOk() {
// execute set parameter task
String[][] brokerParameters = ConfConstants.getBrokerParameters(serverInfo);
if (isTableChange()) {
Map<String, String> paraMap = confParaMap.get(node.getLabel());
//compare the default value, if equal default value and delete it from map
for (String[] brokerPara : brokerParameters) {
if (brokerPara[0].equals(ConfConstants.APPL_SERVER_PORT)) {
String serverPort = paraMap.get(ConfConstants.APPL_SERVER_PORT);
if (null != serverPort) {
int serverPortValue = Integer.parseInt(paraMap.get(ConfConstants.BROKER_PORT)) + 1;
if (serverPort.equalsIgnoreCase(Integer.toString(serverPortValue))) {
paraMap.remove(ConfConstants.APPL_SERVER_PORT);
}
}
} else if (brokerPara[0].equals(ConfConstants.LONG_QUERY_TIME)) {
if (isQueryOrTransTimeUseMs) {
int intValue = Integer.parseInt(brokerPara[2]) * 1000;
if (Integer.toString(intValue).equals(paraMap.get(ConfConstants.LONG_QUERY_TIME))) {
paraMap.remove(ConfConstants.LONG_QUERY_TIME);
} else {
String sVal = paraMap.get(ConfConstants.LONG_QUERY_TIME);
double dVal = Double.parseDouble(sVal) / 1000;
paraMap.put(ConfConstants.LONG_QUERY_TIME, String.valueOf(dVal));
}
} else {
if (brokerPara[2].equals(paraMap.get(ConfConstants.LONG_QUERY_TIME))) {
paraMap.remove(ConfConstants.LONG_QUERY_TIME);
}
}
} else if (brokerPara[0].equals(ConfConstants.LONG_TRANSACTION_TIME)) {
if (isQueryOrTransTimeUseMs) {
int intValue = Integer.parseInt(brokerPara[2]) * 1000;
if (Integer.toString(intValue).equals(paraMap.get(ConfConstants.LONG_TRANSACTION_TIME))) {
paraMap.remove(ConfConstants.LONG_TRANSACTION_TIME);
} else {
String sVal = paraMap.get(ConfConstants.LONG_TRANSACTION_TIME);
double dVal = Double.parseDouble(sVal) / 1000;
paraMap.put(ConfConstants.LONG_TRANSACTION_TIME, String.valueOf(dVal));
}
} else {
if (brokerPara[2].equals(paraMap.get(ConfConstants.LONG_TRANSACTION_TIME))) {
paraMap.remove(ConfConstants.LONG_TRANSACTION_TIME);
}
}
} else if (brokerPara[2].equals(paraMap.get(brokerPara[0]))) {
paraMap.remove(brokerPara[0]);
}
}
SetBrokerConfParameterTask setBrokerConfParameterTask = new SetBrokerConfParameterTask(serverInfo);
setBrokerConfParameterTask.setConfParameters(confParaMap);
String taskName = Messages.bind(Messages.setBrokerConfParameterTaskName, this.node.getName());
CommonTaskExec taskExec = new CommonTaskExec(taskName);
taskExec.addTask(setBrokerConfParameterTask);
new ExecTaskWithProgress(taskExec).exec();
if (taskExec.isSuccess()) {
CommonUITool.openInformationBox(com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.restartBrokerMsg);
} else {
return true;
}
}
// refresh tap
if (isSettingChange()) {
boolean isOn = refreshBtn.getSelection();
String interval = intervalTxt.getText();
String serverName = node.getServer().getLabel();
String nodeName = node.getLabel();
BrokerIntervalSetting newSetting = new BrokerIntervalSetting(serverName, nodeName, interval, isOn);
BrokerIntervalSettingManager manager = BrokerIntervalSettingManager.getInstance();
manager.removeBrokerIntervalSetting(serverName, brokerName);
manager.setBrokerInterval(newSetting);
}
return true;
}
use of com.cubrid.common.ui.spi.progress.ExecTaskWithProgress in project cubrid-manager by CUBRID.
the class StopServiceAction method doRun.
/**
* Perform do run
*
* @param servers
*/
public void doRun(CubridServer[] servers) {
CubridNavigatorView view = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
final TreeViewer viewer = view.getViewer();
if (servers.length > 0) {
CubridServer server = servers[0];
if (isSupported(server)) {
final JobFamily jobFamily = new JobFamily();
final String serverName = server.getName();
String dbName = JobFamily.ALL_DB;
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
Job[] jobs = Job.getJobManager().find(jobFamily);
if (jobs.length > 0) {
CommonUITool.openWarningBox(Messages.bind(Messages.msgStopServiceWithJob, serverName));
return;
}
TaskExecutor taskExcutor = new StopServiceExecutor(server, getShell(), viewer);
ServerInfo serverInfo = server.getServerInfo();
GetCubridConfParameterTask task = new GetCubridConfParameterTask(serverInfo);
taskExcutor.addTask(task);
new ExecTaskWithProgress(taskExcutor).exec();
}
}
// for(CubridServer server : servers) {
// final JobFamily jobFamily = new JobFamily();
// final String serverName = server.getName();
// String dbName = JobFamily.ALL_DB;
// jobFamily.setServerName(serverName);
// jobFamily.setDbName(dbName);
// Job[] jobs = Job.getJobManager().find(jobFamily);
// if (jobs.length > 0) {
// CommonUITool.openWarningBox(Messages.bind(
// Messages.msgStopServiceWithJob, serverName));
// return;
// }
//
// TaskExecutor taskExcutor = new StopServiceExecutor(server, getShell(),
// viewer);
// ServerInfo serverInfo = server.getServerInfo();
// GetCubridConfParameterTask task = new GetCubridConfParameterTask(
// serverInfo);
// taskExcutor.addTask(task);
// new ExecTaskWithProgress(taskExcutor).exec();
// }
}
Aggregations