Search in sources :

Example 6 with SchemaComment

use of com.cubrid.common.core.schemacomment.model.SchemaComment 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 7 with SchemaComment

use of com.cubrid.common.core.schemacomment.model.SchemaComment 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 8 with SchemaComment

use of com.cubrid.common.core.schemacomment.model.SchemaComment 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)

Example 9 with SchemaComment

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

the class CreateViewDialog method getViewComment.

/**
	 * get view's comment
	 *
	 * @return
	 */
private String getViewComment() {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    SchemaComment schemaComment = null;
    String viewName = tableText.getText();
    try {
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        conn = JDBCConnectionManager.getConnection(dbInfo, true);
        schemaComment = SchemaCommentHandler.loadObjectDescription(dbInfo, conn, viewName, CommentType.VIEW);
    } catch (SQLException e) {
        LOGGER.error(e.getMessage());
        CommonUITool.openErrorBox(e.getMessage());
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    return schemaComment.getDescription();
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment)

Example 10 with SchemaComment

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

the class ColumnProposalAdvisor method loadProposal.

/**
	 * load proposal for database
	 * 
	 * @param databaseInfo
	 */
private void loadProposal(final DatabaseInfo databaseInfo) {
    final String key = makeKey(databaseInfo);
    Job job = new Job("Load database schema information job") {

        protected IStatus run(IProgressMonitor monitor) {
            List<String> tableNames = new ArrayList<String>();
            Map<String, List<ColumnProposalDetailInfo>> columns = new HashMap<String, List<ColumnProposalDetailInfo>>();
            GetAllSchemaTask task = null;
            try {
                task = new GetAllSchemaTask(databaseInfo, monitor);
                task.setNeedCollationInfo(false);
                task.execute();
                /*Check is canceled*/
                if (task.isCancel()) {
                    return Status.CANCEL_STATUS;
                }
                if (task.isSuccess()) {
                    Map<String, SchemaInfo> schemas = task.getSchemas();
                    Map<String, SchemaComment> descriptions = task.getComments();
                    List<String> fetchedTableNames = new ArrayList<String>();
                    for (SchemaInfo schemaInfo : schemas.values()) {
                        if (schemaInfo.isSystemClass()) {
                            continue;
                        }
                        String tableName = schemaInfo.getClassname();
                        if (ConstantsUtil.isExtensionalSystemTable(tableName)) {
                            continue;
                        }
                        fetchedTableNames.add(tableName);
                    }
                    Collections.sort(fetchedTableNames);
                    for (String tableName : fetchedTableNames) {
                        if (!tableNames.contains(tableName)) {
                            tableNames.add(tableName);
                        }
                        if (columns.containsKey(tableName)) {
                            continue;
                        }
                        SchemaInfo schemaInfo = schemas.get(tableName);
                        if (schemaInfo == null) {
                            continue;
                        }
                        if (descriptions != null) {
                            SchemaComment schemaComment = SchemaCommentHandler.find(descriptions, tableName, null);
                            if (schemaComment != null) {
                                String description = schemaComment.getDescription();
                                schemaInfo.setDescription(description);
                            }
                        }
                        List<ColumnProposalDetailInfo> colInfoList = new ArrayList<ColumnProposalDetailInfo>();
                        columns.put(tableName, colInfoList);
                        List<DBAttribute> dbClassAttrList = schemaInfo.getClassAttributes();
                        for (DBAttribute attr : dbClassAttrList) {
                            ColumnProposalDetailInfo colInfo = new ColumnProposalDetailInfo(schemaInfo, attr);
                            colInfoList.add(colInfo);
                        }
                        List<DBAttribute> attrList = schemaInfo.getAttributes();
                        for (DBAttribute attr : attrList) {
                            ColumnProposalDetailInfo colInfo = new ColumnProposalDetailInfo(schemaInfo, attr);
                            colInfoList.add(colInfo);
                        }
                        columns.put(schemaInfo.getClassname(), colInfoList);
                    }
                    /*Cache the data*/
                    ColumnProposal proposal = new ColumnProposal();
                    proposal.setTableNames(tableNames);
                    proposal.setColumns(columns);
                    synchronized (ColumnProposalAdvisor.class) {
                        cachedMap.put(key, proposal);
                    }
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            } finally {
                synchronized (ColumnProposalAdvisor.class) {
                    collectingKeys.remove(key);
                }
                task.finish();
            }
            return Status.OK_STATUS;
        }
    };
    /*Record collecting key*/
    synchronized (ColumnProposalAdvisor.class) {
        collectingKeys.add(key);
        job.schedule();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) List(java.util.List) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) SchemaComment(com.cubrid.common.core.schemacomment.model.SchemaComment) Job(org.eclipse.core.runtime.jobs.Job) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)23 SQLException (java.sql.SQLException)11 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)8 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)8 Constraint (com.cubrid.common.core.common.model.Constraint)6 PreparedStatement (java.sql.PreparedStatement)6 Connection (java.sql.Connection)5 IDatabaseSpec (com.cubrid.common.core.common.model.IDatabaseSpec)4 ResultSet (java.sql.ResultSet)4 HashMap (java.util.HashMap)4 WritableSheet (jxl.write.WritableSheet)4 Statement (java.sql.Statement)3 ArrayList (java.util.ArrayList)3 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 PartInitException (org.eclipse.ui.PartInitException)2 DBResolution (com.cubrid.common.core.common.model.DBResolution)1 Trigger (com.cubrid.common.core.common.model.Trigger)1 ITask (com.cubrid.common.core.task.ITask)1