Search in sources :

Example 81 with SchemaInfo

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

Example 82 with SchemaInfo

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

the class ColumnProposalDetailInfo method fillInTableColumnInfo.

/**
	 * Fill in the table column information
	 *
	 * @param dbInfo DatabaseInfo
	 * @param tableNames List<String>
	 * @param columns Map<String, List<ColumnProposalDetailInfo>>
	 */
public static void fillInTableColumnInfo(DatabaseInfo dbInfo, List<String> tableNames, Map<String, List<ColumnProposalDetailInfo>> columns) {
    try {
        GetAllSchemaTask task = new GetAllSchemaTask(dbInfo);
        task.setNeedCollationInfo(false);
        task.execute();
        Map<String, SchemaInfo> schemas = task.getSchemas();
        List<String> fetchedTableNames = new ArrayList<String>();
        for (SchemaInfo schemaInfo : schemas.values()) {
            String tableName = schemaInfo.getClassname();
            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;
            }
            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);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 83 with SchemaInfo

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

the class AddFKDialog method init.

/**
	 * initializes some values.
	 * 
	 */
private void init() {
    List<String> list = getTableList();
    //List<String> foreignTablelist = schema.getForeignTables();
    for (String table : list) {
        //if (!foreignTablelist.contains(table)) {
        foreignTableCombo.add(table);
    //}
    }
    if (editedFK == null) {
        if (defaultTableName != null) {
            foreignTableCombo.setText(defaultTableName);
        } else {
            foreignTableCombo.select(0);
        }
        getPKTableData();
        List<DBAttribute> attrList = schema.getLocalAttributes();
        for (int i = 0, n = attrList.size(); i < n; i++) {
            DBAttribute attr = attrList.get(i);
            TableItem item = new TableItem(fkTable, SWT.NONE);
            item.setText(0, attr.getName());
            item.setText(1, DataType.getShownType(attr.getType()));
            //$NON-NLS-1$
            item.setText(2, "");
        }
    } else {
        fkNameText.setText(editedFK.getName());
        String refTable = "";
        String delRule = "RESTRICT";
        String updateRule = "RESTRICT";
        String cacheRule = "";
        List<String> rules = editedFK.getRules();
        for (String rule : rules) {
            String refStr = "REFERENCES ";
            String delStr = "ON DELETE ";
            String updStr = "ON UPDATE ";
            String cacheStr = "ON CACHE OBJECT ";
            if (rule.startsWith(refStr)) {
                refTable = rule.replace(refStr, "");
            } else if (rule.startsWith(delStr)) {
                delRule = rule.replace(delStr, "");
            } else if (rule.startsWith(updStr)) {
                updateRule = rule.replace(updStr, "");
            } else if (rule.startsWith(cacheStr)) {
                cacheRule = rule.replace(cacheStr, "");
            }
        }
        List<String> refPKAttrs = new ArrayList<String>();
        SchemaInfo refSchema = getSchemaInfo(refTable);
        List<SchemaInfo> refSupers = getRefedSupper(refSchema);
        Constraint refPK = refSchema.getPK(refSupers);
        if (refPK != null) {
            refPKAttrs = refPK.getAttributes();
        }
        //Referenced foreign table name
        foreignTableCombo.setText(refTable);
        getPKTableData();
        //Foreign table columns
        List<String> fkColumns = editedFK.getAttributes();
        List<DBAttribute> attrList = schema.getLocalAttributes();
        for (int i = 0, n = attrList.size(); i < n; i++) {
            DBAttribute attr = attrList.get(i);
            TableItem item = new TableItem(fkTable, SWT.NONE);
            item.setText(0, attr.getName());
            item.setText(1, DataType.getShownType(attr.getType()));
            if (fkColumns.contains(attr.getName())) {
                int index = getPKMatchIndexInFK(attr.getName());
                if (index == -1) {
                    index = 0;
                }
                item.setText(2, refPKAttrs.isEmpty() ? "" : refPKAttrs.get(index));
            } else {
                item.setText(2, "");
            }
        }
        for (Button btn : updateBTNs) {
            String rule = buttonMap.get(btn);
            if (updateRule.equalsIgnoreCase(rule)) {
                btn.setSelection(true);
            } else {
                btn.setSelection(false);
            }
        }
        for (Button btn : deleteBTNs) {
            String rule = buttonMap.get(btn);
            if (delRule.equalsIgnoreCase(rule)) {
                btn.setSelection(true);
            } else {
                btn.setSelection(false);
            }
        }
        if (cacheRule != null && cacheRule.trim().length() > 0) {
            onCacheObjectButton.setSelection(true);
            newColumnNameText.setEnabled(true);
            newColumnNameText.setText(cacheRule);
        }
    }
    foreignTableCombo.setEnabled(canChangeTable);
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) Button(org.eclipse.swt.widgets.Button) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 84 with SchemaInfo

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

the class TableDashboardComposite method getData.

/**
	 * Get the data that displaying
	 */
public SchemaInfo getData() {
    if (columnTableView != null && !columnTableView.getTable().isDisposed()) {
        Object ob = columnTableView.getInput();
        SchemaInfo schema = (SchemaInfo) ob;
        return schema;
    }
    return null;
}
Also used : SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 85 with SchemaInfo

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

the class TableDashboardComposite method showEditDialog.

public void showEditDialog(Table table, int index) {
    SchemaInfo info = getData();
    if (info == null) {
        return;
    }
    List<DBAttribute> attrs = info.getAttributes();
    if (attrs == null) {
        return;
    }
    if (index >= attrs.size()) {
        return;
    }
    DBAttribute attr = attrs.get(index);
    if (attr == null) {
        return;
    }
    InputTextDialog dialog = new InputTextDialog(Display.getCurrent().getActiveShell(), com.cubrid.common.ui.cubrid.table.Messages.titleColumnDescEditor, com.cubrid.common.ui.cubrid.table.Messages.msgColumnDescEditor, com.cubrid.common.ui.cubrid.table.Messages.labelColumnDescEditor, attr.getDescription());
    if (dialog.open() == IDialogConstants.OK_ID) {
        // FIXME move this logic to core module
        String tableName = info.getClassname();
        String columnName = attr.getName();
        String description = dialog.getResult();
        Connection conn = null;
        try {
            conn = JDBCConnectionManager.getConnection(databaseInfo, true);
            SchemaCommentHandler.updateDescription(databaseInfo, conn, tableName, columnName, description);
            attr.setDescription(description);
            columnTableView.setInput(info);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            QueryUtil.commit(conn);
            QueryUtil.freeQuery(conn);
        }
    }
}
Also used : InputTextDialog(com.cubrid.common.ui.spi.table.button.InputTextDialog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) Connection(java.sql.Connection) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5