use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class DeleteTableAction method doRun.
/**
* Do run
*
* @param obj
*/
private void doRun(Object[] obj) {
StringBuilder sb = new StringBuilder();
final List<String> tableList = new ArrayList<String>();
CubridDatabase database = null;
for (int i = 0; i < obj.length; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
database = table.getDatabase();
final String tableName = table.getName();
tableList.add(tableName);
if (i < 100) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(tableName);
}
}
if (obj.length > 100) {
sb.append("...");
}
String message = Messages.bind(Messages.confirmTableDeleteWarn, sb.toString());
if (!CommonUITool.openConfirmBox(message)) {
return;
}
final DelAllRecordsTask task = new DelAllRecordsTask(database.getDatabaseInfo());
TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {
public void completeAll() {
int[] rowCount = task.getDeleteRecordsCount();
List<String> rowCountList = new ArrayList<String>();
for (int i = 0; i < rowCount.length; i++) {
rowCountList.add(String.valueOf(rowCount[i]));
}
String message = Messages.bind(Messages.resultTableDeleteInformantion, tableList, rowCountList);
CommonUITool.openInformationBox(Messages.msg_information, message);
}
public IStatus postTaskFinished(ITask task) {
return Status.OK_STATUS;
}
});
String[] tableNames = new String[tableList.size()];
tableNames = tableList.toArray(tableNames);
task.setTableName(tableNames);
taskExec.addTask(task);
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
String jobName = Messages.msgDeleteTableDataJobName + " - " + tableList.toString() + "@" + dbName + "@" + serverName;
taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class TableToPhpCodeAction method doRun.
/**
* Perform all tables
*
* @param obj
*/
private void doRun(final Object[] obj) {
final File filepath = TableUtil.getSavedDirForCreateCodes(getShell(), null);
if (filepath == null) {
return;
}
if (!CommonUITool.openConfirmBox(Messages.msgConfirmTableToCode)) {
return;
}
final Map<CubridDatabase, Connection> connections = new HashMap<CubridDatabase, Connection>();
try {
final Display display = PlatformUI.getWorkbench().getDisplay();
BusyIndicator.showWhile(display, new Runnable() {
public void run() {
// FIXME move this logic to core module
StringBuilder notExportedList = new StringBuilder();
for (int i = 0; i < obj.length; i++) {
DefaultSchemaNode table = (DefaultSchemaNode) obj[i];
Connection connection = connections.get(table.getDatabase());
if (connection == null) {
try {
connection = JDBCConnectionManager.getConnection(table.getDatabase().getDatabaseInfo(), true);
connections.put(table.getDatabase(), connection);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
if (connection == null) {
if (notExportedList.length() > 0) {
notExportedList.append(", ");
}
notExportedList.append(table.getName());
continue;
}
String pojoClassFileName = getPojoFileName(table);
String pojoClassData = getPojoString(connection, table);
String pojoClassPath = filepath.getAbsolutePath() + File.separator + pojoClassFileName;
//TODO: error handling
boolean result = FileUtil.writeToFile(pojoClassPath, pojoClassData, "utf-8");
if (!result) {
if (notExportedList.length() > 0) {
notExportedList.append(", ");
}
notExportedList.append(table.getName());
}
}
finishNotice(notExportedList.toString());
}
});
} finally {
Collection<Connection> items = connections.values();
for (Connection conn : items) {
QueryUtil.freeQuery(conn);
}
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class MakeCloneQueryAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
final Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
final DefaultSchemaNode tableNode = (DefaultSchemaNode) obj[0];
CubridDatabase db = tableNode.getDatabase();
DatabaseInfo dbInfo = db.getDatabaseInfo();
GetTablesTask getTableTask = new GetTablesTask(dbInfo);
List<String> tableList = getTableTask.getAllTableAndViews();
String tableName = null;
if (NodeType.USER_TABLE.equals(tableNode.getType())) {
tableName = tableNode.getName();
}
final CloneTableDialog dialog = new CloneTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableList, tableName);
if (IDialogConstants.OK_ID == dialog.open()) {
targetName = dialog.getTargetName();
ICubridNode[] nodeArray = { tableNode };
super.doRun(nodeArray);
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class MakeSelectQueryAction method getStmtSQL.
/**
* Create select statement SQL
*
* @param schemaNode DefaultSchemaNode
* @return String
*/
protected String getStmtSQL(DefaultSchemaNode schemaNode, IEditorPart editorPart) {
// FIXME move this logic to core module
String sql = "";
if (schemaNode != null) {
CubridDatabase db = schemaNode.getDatabase();
if (db == null) {
return sql;
}
DatabaseInfo dbInfo = db.getDatabaseInfo();
if (dbInfo == null) {
return sql;
}
GetAllAttrTask task = new GetAllAttrTask(dbInfo);
task.setClassName(schemaNode.getName());
task.getAttrList();
if (task.getErrorMsg() != null) {
return sql;
}
List<DBAttribute> allAttrList = task.getAllAttrList();
sql = SQLGenerateUtils.getSelectSQLNoWhere(schemaNode.getName(), allAttrList, true);
sql = wrapShardSQL(schemaNode, editorPart, sql);
}
try {
return new SqlFormattingStrategy().format(sql).trim();
} catch (Exception ignored) {
return sql;
}
}
use of com.cubrid.common.ui.spi.model.CubridDatabase in project cubrid-manager by CUBRID.
the class RenameTableAction method doRun.
/**
* Perform rename Table
*
* @param cubridDatabase
* @param table
*/
private void doRun(CubridDatabase cubridDatabase, ISchemaNode table) {
boolean isTable = false;
String type = table.getType();
if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
isTable = true;
} else if (NodeType.USER_VIEW.equals(type)) {
isTable = false;
}
String tableName = table.getName();
CubridDatabase db = table.getDatabase();
DatabaseInfo dbInfo = db.getDatabaseInfo();
GetTablesTask getTableTask = new GetTablesTask(dbInfo);
List<String> tableList = getTableTask.getAllTableAndViews();
RenameTableDialog dlg = new RenameTableDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), tableName, isTable, tableList, true);
int ret = dlg.open();
if (ret == IDialogConstants.OK_ID) {
String newName = dlg.getNewName();
RenameTableOrViewTask task = new RenameTableOrViewTask(dbInfo);
task.setOldClassName(tableName);
task.setNewClassName(newName);
task.setTable(isTable);
String taskName = Messages.bind(com.cubrid.common.ui.cubrid.table.Messages.renameTableTaskName, new String[] { tableName, newName });
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
ISelectionProvider provider = this.getSelectionProvider();
final TreeViewer viewer = (TreeViewer) provider;
//remove the old table schema information
table.getDatabase().getDatabaseInfo().removeSchema(tableName);
DefaultSchemaNode cloneTable = null;
try {
cloneTable = ((DefaultSchemaNode) table).clone();
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(cloneTable, CubridNodeChangedEventType.NODE_REMOVE));
} catch (CloneNotSupportedException ex) {
LOGGER.error(ex.getMessage());
}
ClassInfo classInfo = (ClassInfo) table.getAdapter(ClassInfo.class);
classInfo.setClassName(newName);
table.setId(table.getParent().getId() + ICubridNodeLoader.NODE_SEPARATOR + newName);
table.setLabel(newName);
viewer.refresh(table, true);
LayoutManager.getInstance().getWorkbenchContrItem().reopenEditorOrView(table);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(table, CubridNodeChangedEventType.NODE_ADD));
ActionManager.getInstance().fireSelectionChanged(getSelection());
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged(table);
/*For bug TOOLS-3118: close opened TableEditorPart about dropped table*/
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
IEditorPart editor = editorRef.getEditor(true);
if (editor.getEditorInput() instanceof TableEditorInput) {
TableEditorInput input = (TableEditorInput) editor.getEditorInput();
ISchemaNode tableOfEditor = input.getEditedTableNode();
if (tableOfEditor.equals(table)) {
workbenchWindow.getActivePage().closeEditor(editor, false);
break;
}
}
}
}
}
}
Aggregations