Search in sources :

Example 1 with IDatabaseSpec

use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.

the class ExportTableDefinitionProgress method loadSchemaCommentData.

/**
	 * load schema comment data(
	 * @param conn
	 * @return
	 */
public void loadSchemaCommentData(Connection conn) {
    // FIXME move this logic to core module
    IDatabaseSpec dbSpec = database.getDatabaseInfo();
    isInstalledMetaTable = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
    if (isInstalledMetaTable) {
        try {
            schemaCommentMap = SchemaCommentHandler.loadDescriptions(dbSpec, conn);
        } catch (Exception e) {
            LOGGER.error("load schema comment error", e);
        }
    }
}
Also used : IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) SQLException(java.sql.SQLException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with IDatabaseSpec

use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.

the class ERDNDController method getDescInformation.

private void getDescInformation(SchemaInfo newSchemaInfo, CubridDatabase database, Connection conn) {
    // FIXME move this logic to core module
    try {
        IDatabaseSpec dbSpec = database.getDatabaseInfo();
        boolean isSupportTableComment = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
        database.getDatabaseInfo().setSupportTableComment(isSupportTableComment);
        if (isSupportTableComment && 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());
                }
            }
            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);
    }
}
Also used : IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) SQLException(java.sql.SQLException) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) SQLException(java.sql.SQLException)

Example 3 with IDatabaseSpec

use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.

the class DropTableAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (!isSupported(obj)) {
        setEnabled(false);
        return;
    }
    // FIXME move this logic to core module
    int len = obj.length;
    StringBuilder sb = new StringBuilder();
    ISchemaNode table = (ISchemaNode) obj[0];
    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);
        }
        ISelectionProvider provider = this.getSelectionProvider();
        final TreeViewer viewer = (TreeViewer) provider;
        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]);
        }
        viewer.remove(parent, obj);
        viewer.setSelection(new StructuredSelection(parent), true);
        //refresh user folder count label
        CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, 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 : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) Connection(java.sql.Connection) 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) DropTableOrViewTask(com.cubrid.cubridmanager.core.cubrid.table.task.DropTableOrViewTask)

Example 4 with IDatabaseSpec

use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method openTableDetail.

private void openTableDetail(TableDetailInfo info) {
    //if had opend, set it selection
    for (CTabItem tabItem : tabFolder.getItems()) {
        if (tabItem.getText().equals(info.getTableName())) {
            tabFolder.setSelection(tabItem);
            return;
        }
    }
    //if a new table info, create a new tab
    TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
    tableComp.initialize();
    SchemaProvider schemaProvider = new SchemaProvider(database.getDatabaseInfo(), info.getTableName());
    SchemaInfo schemaInfo = schemaProvider.getSchema();
    if (schemaInfo == null && StringUtil.isNotEmpty(schemaProvider.getErrorMessage())) {
        String msg = Messages.bind(Messages.errGetSchemaInfo, info.getTableName());
        CommonUITool.openErrorBox(msg);
        return;
    }
    // load table descriptions
    // FIXME move this logic to core module
    Connection conn = null;
    try {
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        IDatabaseSpec dbSpec = database.getDatabaseInfo();
        boolean isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(dbSpec, conn);
        if (schemaInfo != null && isSchemaCommentInstalled) {
            Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, conn, schemaInfo.getClassname());
            SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
        }
    } catch (SQLException e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(conn);
    }
    tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
}
Also used : IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SchemaProvider(com.cubrid.cubridmanager.core.cubrid.table.SchemaProvider) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) TablesDetailInfoCTabItem(com.cubrid.common.ui.cubrid.table.dashboard.control.TableDashboardComposite.TablesDetailInfoCTabItem) CTabItem(org.eclipse.swt.custom.CTabItem) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 5 with IDatabaseSpec

use of com.cubrid.common.core.common.model.IDatabaseSpec in project cubrid-manager by CUBRID.

the class ColumnViewerSorter method setInputs.

public void setInputs() {
    tableListView.setInput(tableList);
    tableListView.refresh();
    Connection connection = null;
    try {
        connection = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        isSchemaCommentInstalled = SchemaCommentHandler.isInstalledMetaTable(database.getDatabaseInfo(), connection);
        TableDashboardComposite tableComp = new TableDashboardComposite(tabFolder, SWT.NONE);
        tableComp.initialize();
        if (database.getDatabaseInfo().getUserTableInfoList().size() > 0) {
            ClassInfo classInfo = database.getDatabaseInfo().getUserTableInfoList().get(0);
            SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(connection, classInfo.getClassName());
            IDatabaseSpec dbSpec = database.getDatabaseInfo();
            if (schemaInfo != null && SchemaCommentHandler.isInstalledMetaTable(dbSpec, connection)) {
                Map<String, SchemaComment> comments = SchemaCommentHandler.loadDescription(dbSpec, connection, classInfo.getClassName());
                if (comments != null) {
                    SchemaCommentHandler.bindSchemaInfo(comments, schemaInfo);
                }
            }
            tableComp.setInput(schemaInfo, database.getDatabaseInfo(), isSchemaCommentInstalled);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        QueryUtil.freeQuery(connection);
    }
    if (isSchemaCommentInstalled) {
        new TableEditButtonSupport(tableListView, this, 1);
    }
}
Also used : TableEditButtonSupport(com.cubrid.common.ui.spi.table.button.TableEditButtonSupport) IDatabaseSpec(com.cubrid.common.core.common.model.IDatabaseSpec) Connection(java.sql.Connection) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo) 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