Search in sources :

Example 56 with Constraint

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

the class ERXmlContainer method parseKeyGroupColumn.

private void parseKeyGroupColumn(List<Node> nodeList, int begin, int length) {
    int max = 3;
    for (int i = begin; i < begin + length; i++) {
        try {
            Node keyColumnNode = nodeList.get(i);
            if (keyColumnNode.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            Node pNode = findPNode(keyColumnNode, "Key_Group");
            String id = pNode.getAttributes().getNamedItem("id").getNodeValue().trim();
            String columnId = keyColumnNode.getFirstChild().getNodeValue().trim();
            Constraint constraint = constraints.get(id);
            Node attributeNode = getNodeById(columnId, "Attribute");
            if (attributeNode == null) {
                continue;
            }
            String physicalName = handler.getChildValueByProperty(attributeNode, "AttributeProps.Physical_Name");
            if (physicalName == null) {
                physicalName = handler.getChildValueByProperty(attributeNode, "AttributeProps.Name");
            }
            if (physicalName == null) {
                physicalName = attributeNode.getAttributes().getNamedItem("Name").getNodeValue();
            }
            // Other attributes
            if (constraint.getType().equals(ConstraintType.PRIMARYKEY.getText()) || constraint.getType().equals(ConstraintType.FOREIGNKEY.getText())) {
                constraint.addAttribute(physicalName);
            } else {
                Node keyGroupSortOrder = keyColumnNode.getParentNode().getFirstChild().getNextSibling();
                while (keyGroupSortOrder != null) {
                    if (!keyGroupSortOrder.getNodeName().equals("Key_Group_Sort_Order")) {
                        keyGroupSortOrder = keyGroupSortOrder.getNextSibling();
                        continue;
                    }
                    String order = keyGroupSortOrder.getFirstChild().getNodeValue().trim();
                    if (StringUtil.isNotEmpty(order)) {
                        physicalName = physicalName + " " + order;
                    }
                    break;
                }
                constraint.addRule(physicalName);
            }
        } catch (Exception e) {
            max--;
            if (max != 0) {
                i--;
            } else {
                max = 3;
            }
            continue;
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) Node(org.w3c.dom.Node) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 57 with Constraint

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

the class TableSchemaCompareExtraColumnLabelProvider method getText.

public String getText(Object element) {
    TableSchemaCompareModel cm = (TableSchemaCompareModel) element;
    TableDetailInfo tableInfo = null;
    if (focus == 0) {
        if (cm.getCompareStatus() != TableSchemaCompareModel.SCHEMA_SMISS) {
            tableInfo = cm.getSourceTableDetailInfo();
        }
    } else if (focus == 1) {
        if (cm.getCompareStatus() != TableSchemaCompareModel.SCHEMA_TMISS) {
            tableInfo = cm.getTargetTableDetailInfo();
            if (tableInfo == null) {
                TableSchema tableSchema = (TableSchema) cm.getRight();
                SchemaInfo schemaInfo = cm.getTargetSchemas().get(tableSchema.getName());
                int columnCount = schemaInfo.getAttributes().size();
                int idxCount = 0;
                int pk = 0;
                for (Constraint constraint : schemaInfo.getConstraints()) {
                    if (constraint.getType().equals(ConstraintType.PRIMARYKEY.getText())) {
                        pk++;
                        continue;
                    } else {
                        idxCount++;
                    }
                }
                tableInfo = new TableDetailInfo();
                tableInfo.setPkCount(pk);
                tableInfo.setColumnsCount(columnCount);
                tableInfo.setIndexCount(idxCount);
            }
        }
    }
    if (type == RECORDS_COUNT) {
        long tableRecordCount = 0;
        if (tableInfo != null) {
            tableRecordCount = tableInfo.getRecordsCount();
        }
        if (focus == 0) {
            cm.setSourceRecords(tableRecordCount);
        } else if (focus == 1) {
            cm.setTargetRecords(tableRecordCount);
        }
        if (tableRecordCount < 0) {
            return Messages.notCount;
        }
        return String.valueOf(tableRecordCount);
    } else if (type == ATTRIBUTES_COUNT) {
        int attributeCount = 0;
        if (tableInfo != null) {
            attributeCount = tableInfo.getColumnsCount();
        }
        return String.valueOf(attributeCount);
    } else if (type == INDEX_COUNT) {
        int indexCount = 0;
        if (tableInfo != null) {
            indexCount = tableInfo.getIndexCount();
        }
        return String.valueOf(indexCount);
    } else if (type == PK_STATUS) {
        int pkCount = 0;
        if (tableInfo != null) {
            pkCount = tableInfo.getPkCount();
        }
        if (pkCount > 0) {
            return "Y";
        }
        return "";
    }
    return "";
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) Constraint(com.cubrid.common.core.common.model.Constraint) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 58 with Constraint

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

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

the class AddFKDialog method buttonPressed.

/**
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
	 * @param buttonId the id of the button that was pressed (see
	 *        <code>IDialogConstants.*_ID</code> constants)
	 */
protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
        if (checkFields() == 1) {
            return;
        }
        retFK = new Constraint(true);
        retFK.setType(Constraint.ConstraintType.FOREIGNKEY.getText());
        int itemCount = fkTable.getItemCount();
        Map<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < itemCount; i++) {
            TableItem item = fkTable.getItem(i);
            String pkColumn = item.getText(fkTableColCount - 1).trim();
            if (!("").equals(pkColumn)) {
                //$NON-NLS-1$
                map.put(pkColumn, item.getText(0));
            }
        }
        itemCount = pkForeignTable.getItemCount();
        for (int i = 0; i < itemCount; i++) {
            TableItem item = pkForeignTable.getItem(i);
            String pkColumn = item.getText(0).trim();
            assert (StringUtil.isNotEmpty(pkColumn));
            String refColumn = map.get(pkColumn);
            assert (refColumn != null);
            retFK.addAttribute(refColumn);
        }
        String fkName = fkNameText.getText().trim();
        if (StringUtil.isEmpty(fkName)) {
            //$NON-NLS-1$
            fkName = ConstraintNamingUtil.getFKName(schema.getClassname(), retFK.getAttributes());
        }
        retFK.setName(fkName);
        String foreignTable = foreignTableCombo.getText();
        //$NON-NLS-1$
        retFK.addRule("REFERENCES " + foreignTable);
        List<Constraint> fkList = schema.getFKConstraints();
        if (editedFK != null) {
            fkList.remove(editedFK);
        }
        for (Constraint fk : fkList) {
            if (fk.getAttributes().equals(retFK.getAttributes())) {
                setErrorMessage(Messages.errColumnExistInFK);
                return;
            }
        }
        for (int i = 0; i < deleteBTNs.length; i++) {
            if (deleteBTNs[i].getSelection()) {
                //$NON-NLS-1$
                retFK.addRule("ON DELETE " + buttonMap.get(deleteBTNs[i]));
                break;
            }
        }
        for (int i = 0; i < updateBTNs.length; i++) {
            if (updateBTNs[i].getSelection()) {
                //$NON-NLS-1$
                retFK.addRule("ON UPDATE " + buttonMap.get(updateBTNs[i]));
                break;
            }
        }
        if (onCacheObjectButton.getSelection()) {
            //$NON-NLS-1$
            retFK.addRule("ON CACHE OBJECT " + newColumnNameText.getText().trim());
        }
    }
    super.buttonPressed(buttonId);
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) HashMap(java.util.HashMap) TableItem(org.eclipse.swt.widgets.TableItem) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 60 with Constraint

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

the class CubridIndexNavigatorContentProvider method getElements.

public Object[] getElements(Object inputElement) {
    if (inputElement instanceof SchemaInfo) {
        SchemaInfo schema = (SchemaInfo) inputElement;
        List<Constraint> list = new ArrayList<Constraint>();
        List<Constraint> constraints = schema.getConstraints();
        for (Constraint constraint : constraints) {
            if (constraint.getType().equals(Constraint.ConstraintType.INDEX.getText()) || constraint.getType().equals(Constraint.ConstraintType.UNIQUE.getText()) || constraint.getType().equals(Constraint.ConstraintType.REVERSEINDEX.getText()) || constraint.getType().equals(Constraint.ConstraintType.REVERSEUNIQUE.getText()) || constraint.getType().equals(Constraint.ConstraintType.PRIMARYKEY.getText())) {
                list.add(constraint);
            }
        }
        return list.toArray();
    } else {
        return new Object[0];
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

Constraint (com.cubrid.common.core.common.model.Constraint)90 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)47 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)37 ArrayList (java.util.ArrayList)27 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)11 TableItem (org.eclipse.swt.widgets.TableItem)10 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)9 List (java.util.List)9 SchemaChangeLog (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog)7 HashMap (java.util.HashMap)6 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)5 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 Node (org.w3c.dom.Node)4 DBResolution (com.cubrid.common.core.common.model.DBResolution)3 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)3 ERSchema (com.cubrid.common.ui.er.model.ERSchema)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 NodeList (org.w3c.dom.NodeList)3