Search in sources :

Example 6 with IDatabaseSpec

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;
                    }
                }
            }
        }
    }
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) IEditorReference(org.eclipse.ui.IEditorReference) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Example 7 with IDatabaseSpec

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"));
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SQLException(java.sql.SQLException) SchemaChangeManager(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeManager) Connection(java.sql.Connection) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

IDatabaseSpec (com.cubrid.common.core.common.model.IDatabaseSpec)7 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)5 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)4 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)3 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 TableEditorInput (com.cubrid.common.ui.cubrid.table.editor.TableEditorInput)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)2 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 DropTableOrViewTask (com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)2 ArrayList (java.util.ArrayList)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IEditorReference (org.eclipse.ui.IEditorReference)2 IWorkbench (org.eclipse.ui.IWorkbench)2