use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.
the class DropTableAction method doRun.
/**
* Do run
* @param obj
*/
private void doRun(Object[] obj) {
int len = obj.length;
StringBuilder sb = new StringBuilder();
ISchemaNode table = (ISchemaNode) obj[0];
// FIXME move this logic to core module
String type = table.getType();
for (int i = 0; i < len && i < 100; i++) {
table = (DefaultSchemaNode) obj[i];
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(table.getName());
}
if (len > 100) {
sb.append("...");
}
String message = null;
if (NodeType.USER_TABLE.equals(type) || NodeType.USER_PARTITIONED_TABLE_FOLDER.equals(type)) {
message = Messages.bind(Messages.dropTable, sb.toString());
}
boolean ret = CommonUITool.openConfirmBox(message);
if (!ret) {
return;
}
String taskName = Messages.bind(Messages.dropTableTaskName, sb.toString());
TaskExecutor taskExecutor = new CommonTaskExec(taskName);
DropTableOrViewTask task = new DropTableOrViewTask(table.getDatabase().getDatabaseInfo());
List<String> tableNameList = new ArrayList<String>();
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
tableNameList.add(table.getName());
}
String[] tableNames = new String[tableNameList.size()];
tableNames = tableNameList.toArray(tableNames);
task.setTableName(tableNames);
taskExecutor.addTask(task);
new ExecTaskWithProgress(taskExecutor).exec();
if (taskExecutor.isSuccess()) {
// delete table/column descriptions which is dropping table.
DatabaseInfo dbInfo = table.getDatabase().getDatabaseInfo();
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(dbInfo, false);
IDatabaseSpec dbSpec = table.getDatabase().getDatabaseInfo();
boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
if (isSupportTableComment) {
for (int i = 0; i < len; i++) {
table = (DefaultSchemaNode) obj[i];
SchemaCommentHandler.deleteDescription(dbInfo, conn, table.getName());
}
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
} finally {
QueryUtil.freeQuery(conn);
}
//TODO -KK
TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer();
ICubridNode parent = table.getParent();
table.getDatabase().getDatabaseInfo().removeSchema(table.getName());
for (int i = 0; i < len; i++) {
parent.removeChild((ISchemaNode) obj[i]);
/*Broadcast the view changed*/
QueryEditorUtil.fireSchemaNodeChanged((ISchemaNode) obj[i]);
}
treeViewer.remove(parent, obj);
treeViewer.setSelection(new StructuredSelection(parent), true);
//refresh user folder count label
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, parent);
/*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();
for (int i = 0; i < len; i++) {
if (tableOfEditor.equals((ISchemaNode) obj[i])) {
workbenchWindow.getActivePage().closeEditor(editor, false);
break;
}
}
}
}
}
}
use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.
the class TableEditorPart method init.
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
TableEditorInput tableInfoEditorInput = (TableEditorInput) input;
this.database = tableInfoEditorInput.getDatabase();
this.editedTableNode = tableInfoEditorInput.getEditedTableNode();
this.isNewTableFlag = tableInfoEditorInput.isNewTableFlag();
this.dbUserList = tableInfoEditorInput.getDbUserList();
this.showDefaultType = tableInfoEditorInput.getType();
this.collationList = tableInfoEditorInput.getCollationList();
if (collationList != null) {
Collation emptyCollation = new Collation();
emptyCollation.setCharset("");
emptyCollation.setName("");
collationList.add(0, emptyCollation);
}
this.oldSchemaInfo = tableInfoEditorInput.getSchemaInfo();
this.supportCharset = CompatibleUtil.isSupportCreateDBByCharset(database.getDatabaseInfo());
if (isNewTableFlag) {
newSchemaInfo = new SchemaInfo();
//$NON-NLS-1$
newSchemaInfo.setClassname("");
newSchemaInfo.setOwner(database.getUserName());
newSchemaInfo.setDbname(database.getName());
newSchemaInfo.setType(Messages.userSchema);
newSchemaInfo.setVirtual(Messages.schemaTypeClass);
if (database.getDatabaseInfo() != null) {
newSchemaInfo.setCollation(database.getDatabaseInfo().getCollation());
}
} else {
newSchemaInfo = null;
if (tableInfoEditorInput.getSchemaInfo() != null) {
newSchemaInfo = tableInfoEditorInput.getSchemaInfo().clone();
originalConstraints.addAll(newSchemaInfo.getConstraints());
}
}
if (supportCharset) {
columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_COLLATION, IAttributeColumn.COL_MEMO };
} else {
columnProperites = new String[] { IAttributeColumn.COL_EMPTY, IAttributeColumn.COL_FLAG, IAttributeColumn.COL_NAME, IAttributeColumn.COL_DATATYPE, IAttributeColumn.COL_DEFAULT, IAttributeColumn.COL_AUTO_INCREMENT, IAttributeColumn.COL_NOT_NULL, IAttributeColumn.COL_PK, IAttributeColumn.COL_UK, IAttributeColumn.COL_SHARED, IAttributeColumn.COL_MEMO };
}
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
IDatabaseSpec dbSpec = database.getDatabaseInfo();
isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
if (isSupportTableComment && !isNewTableFlag && newSchemaInfo != null) {
Map<String, SchemaComment> map = SchemaCommentHandler.loadDescription(dbSpec, conn, newSchemaInfo.getClassname());
for (DBAttribute attr : newSchemaInfo.getAttributes()) {
SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), attr.getName());
if (schemaComment != null) {
attr.setDescription(schemaComment.getDescription());
}
}
// get description for index
for (Constraint cons : newSchemaInfo.getConstraints()) {
if (CompatibleUtil.isCommentSupports(dbSpec)) {
String indexName = cons.getName();
SchemaComment indexComment = SchemaCommentHandler.loadObjectDescription(dbSpec, conn, indexName, CommentType.INDEX);
if (indexComment != null) {
cons.setDescription(indexComment.getDescription());
}
}
}
SchemaComment schemaComment = SchemaCommentHandler.find(map, newSchemaInfo.getClassname(), null);
if (schemaComment != null) {
newSchemaInfo.setDescription(schemaComment.getDescription());
}
}
} catch (SQLException e) {
LOGGER.error("", e);
} catch (Exception e) {
LOGGER.error("", e);
} finally {
QueryUtil.freeQuery(conn);
}
schemaChangeMgr = new SchemaChangeManager(database.getDatabaseInfo(), isNewTableFlag);
schemaDDL = new SchemaDDL(schemaChangeMgr, database.getDatabaseInfo());
if (database != null) {
isSupportChange = CompatibleUtil.isSupportChangeColumn(database.getDatabaseInfo());
}
setSite(site);
setInput(input);
setPartName(input.getName());
setTitleToolTip(input.getName());
setTitleImage(CommonUIPlugin.getImage("icons/navigator/schema_table.png"));
}
Aggregations