Search in sources :

Example 56 with DBAttribute

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

the class TableEditorPart method getUpdateDescriptionTaskList.

/**
	 * Get UpdateDescriptionTaskList
	 *
	 * @param dbInfo
	 * @return
	 */
private List<UpdateDescriptionTask> getUpdateDescriptionTaskList(DatabaseInfo dbInfo) {
    // FIXME move this logic to core module
    List<UpdateDescriptionTask> updateDescriptionTaskList = new ArrayList<UpdateDescriptionTask>();
    if (isSupportTableComment) {
        for (DBAttribute newAttr : newSchemaInfo.getAttributes()) {
            DBAttribute oldAttr = null;
            if (oldSchemaInfo != null) {
                oldAttr = oldSchemaInfo.getDBAttributeByName(newAttr.getName(), newAttr.isClassAttribute());
            }
            if (oldAttr != null && StringUtil.isEqual(oldAttr.getDescription(), newAttr.getDescription())) {
                continue;
            } else {
                updateDescriptionTaskList.add(new UpdateDescriptionTask(Messages.updateDescriptionTask, dbInfo, tableName, newAttr.getName(), newAttr.getDescription()));
            }
        }
        boolean notSameDescription = false;
        if (oldSchemaInfo != null) {
            notSameDescription = !StringUtil.isEqualNotIgnoreNull(oldSchemaInfo.getDescription(), newSchemaInfo.getDescription());
        }
        if (oldSchemaInfo == null || notSameDescription) {
            UpdateDescriptionTask task = new UpdateDescriptionTask(Messages.updateDescriptionTask, dbInfo, tableName, null, newSchemaInfo.getDescription());
            updateDescriptionTaskList.add(task);
        }
    }
    return updateDescriptionTaskList;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) UpdateDescriptionTask(com.cubrid.cubridmanager.core.cubrid.table.task.UpdateDescriptionTask)

Example 57 with DBAttribute

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

the class TableEditorPart method handleSelectionChangeInColumnTable.

/**
	 * Handle selection change event in column table
	 */
private void handleSelectionChangeInColumnTable() {
    int selectionCount = columnsTable.getSelectionCount();
    if (selectionCount <= 0) {
        deleteColumnBtn.setEnabled(false);
        downColumnBtn.setEnabled(false);
        upColumnBtn.setEnabled(false);
    } else {
        TableItem[] tblItems = columnsTable.getSelection();
        DBAttribute attr = (DBAttribute) tblItems[0].getData();
        boolean isInheritAttr = attr.getInherit() != null && !tableNameText.getText().trim().equalsIgnoreCase(attr.getInherit().trim());
        deleteColumnBtn.setEnabled(!isInheritAttr);
        if (selectionCount > 1) {
            upColumnBtn.setEnabled(false);
            downColumnBtn.setEnabled(false);
        } else {
            if (database == null || database.getDatabaseInfo() == null) {
                return;
            }
            boolean isSupportReorderColumn = CompatibleUtil.isSupportReorderColumn(database.getDatabaseInfo());
            if (isSupportReorderColumn && !isNewTableFlag) {
                // class attribute do not support to reorder
                if (attr.isClassAttribute() || isInheritAttr) {
                    isSupportReorderColumn = false;
                }
                // the attribute which was used by subClass, it not support reorder.
                if (isSupportReorderColumn && isHasSubClass()) {
                    isSupportReorderColumn = false;
                }
            }
            int count = 0;
            if (newSchemaInfo.getClassAttributes() != null) {
                count = newSchemaInfo.getClassAttributes().size();
            }
            int index = columnsTable.getSelectionIndex();
            if (!attr.isClassAttribute()) {
                List<DBAttribute> attrList = newSchemaInfo.getAttributes();
                count = attrList.size();
                int inheritAttrCount = 0;
                for (DBAttribute dbAttr : attrList) {
                    boolean isInheritDbAttr = dbAttr.getInherit() != null && dbAttr.getInherit().trim().length() > 0 && !tableNameText.getText().trim().equalsIgnoreCase(dbAttr.getInherit().trim());
                    if (isInheritDbAttr) {
                        inheritAttrCount++;
                    }
                }
                index = index - inheritAttrCount;
                count = count - inheritAttrCount;
            }
            if (index == 0) {
                upColumnBtn.setEnabled(false);
            } else {
                upColumnBtn.setEnabled(isNewTableFlag ? !isInheritAttr : isSupportReorderColumn);
            }
            if (index == count - 1) {
                downColumnBtn.setEnabled(false);
            } else {
                downColumnBtn.setEnabled(isNewTableFlag ? !isInheritAttr : isSupportReorderColumn);
            }
            List<DBAttribute> items = newSchemaInfo.getAttributes();
            if (!items.contains(attr)) {
                deleteColumnBtn.setEnabled(false);
            } else {
                deleteColumnBtn.setEnabled(true);
            }
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) TableItem(org.eclipse.swt.widgets.TableItem) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 58 with DBAttribute

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

the class TableEditorPart method getNotNullChangedColumn.

/**
	 * Get all not null changed column
	 *
	 * @return
	 */
private List<String[]> getNotNullChangedColumn() {
    // FIXME move this logic to core module
    List<String[]> notNullChangedColumn = new ArrayList<String[]>();
    List<SchemaChangeLog> allAttrChanges = schemaChangeMgr.getAttrChangeLogs();
    List<SchemaInfo> oldSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), oldSchemaInfo);
    if (oldSupers == null) {
        return notNullChangedColumn;
    }
    List<SchemaInfo> newSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo);
    if (newSupers == null) {
        return notNullChangedColumn;
    }
    for (SchemaChangeLog changeLog : allAttrChanges) {
        if (changeLog.getOldValue() == null || changeLog.getNewValue() == null) {
            continue;
        }
        boolean isClassAttr = changeLog.getType() == SchemeInnerType.TYPE_CLASSATTRIBUTE;
        DBAttribute oldAttr = oldSchemaInfo.getDBAttributeByName(changeLog.getOldValue(), isClassAttr);
        DBAttribute newAttr = newSchemaInfo.getDBAttributeByName(changeLog.getNewValue(), isClassAttr);
        if (oldAttr == null || newAttr == null) {
            continue;
        }
        boolean oldNotNull = oldAttr.isNotNull();
        boolean newNotNull = newAttr.isNotNull();
        Constraint newPK = newSchemaInfo.getPK(newSupers);
        List<String> pkAttributes = newPK == null ? new ArrayList<String>() : newPK.getAttributes();
        if (oldNotNull == newNotNull) {
            continue;
        }
        boolean isChangedByPK = false;
        if (newNotNull) {
            // add a new PK
            if (pkAttributes.contains(newAttr.getName())) {
                isChangedByPK = true;
            }
        } else {
            // drop an old PK
            Constraint oldPK = oldSchemaInfo.getPK(oldSupers);
            if (oldPK != null) {
                List<String> oldPKAttrs = oldPK.getAttributes();
                if (oldPKAttrs != null && oldPKAttrs.contains(newAttr.getName())) {
                    isChangedByPK = true;
                }
            }
        }
        if (!isChangedByPK) {
            String[] newColumn = new String[] { newAttr.getName(), String.valueOf(newNotNull) };
            notNullChangedColumn.add(newColumn);
        }
    }
    return notNullChangedColumn;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) SchemaChangeLog(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaChangeLog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 59 with DBAttribute

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

the class TableEditorPart method buildColumnTableMenu.

private void buildColumnTableMenu() {
    Menu menu = new Menu(columnsTable.getShell(), SWT.POP_UP);
    columnsTable.setMenu(menu);
    final MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
    deleteItem.setText(Messages.itemDeleteColumn);
    deleteItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            deleteColumn();
        }
    });
    menu.addMenuListener(new MenuListener() {

        public void menuShown(MenuEvent e) {
            TableItem[] tblItems = columnsTable.getSelection();
            if (tblItems.length > 0) {
                DBAttribute attr = (DBAttribute) tblItems[0].getData();
                List<DBAttribute> items = newSchemaInfo.getAttributes();
                if (!items.contains(attr)) {
                    deleteItem.setEnabled(false);
                } else {
                    deleteItem.setEnabled(true);
                }
            }
        }

        public void menuHidden(MenuEvent e) {
        }
    });
}
Also used : MenuListener(org.eclipse.swt.events.MenuListener) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 60 with DBAttribute

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

the class ERTable method buildColumns.

/**
	 * Build the columns in the schemaInfo to {@code ERTable}, and add to the er
	 * table.
	 *
	 * @param schemaInfo
	 */
public void buildColumns(SchemaInfo schemaInfo) {
    List<DBAttribute> attributesList = schemaInfo.getAttributes();
    Constraint pk = schemaInfo.getPK();
    for (DBAttribute attribute : attributesList) {
        if (attribute == null || attribute.getInherit() == null) {
            continue;
        }
        boolean isPK = pk == null ? false : pk.contains(attribute.getName(), false);
        ERTableColumn column = new ERTableColumn(this, attribute, isPK);
        this.addColumn(column);
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute)

Aggregations

DBAttribute (com.cubrid.common.core.common.model.DBAttribute)130 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)57 Constraint (com.cubrid.common.core.common.model.Constraint)53 ArrayList (java.util.ArrayList)46 HashMap (java.util.HashMap)16 List (java.util.List)15 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)14 TableItem (org.eclipse.swt.widgets.TableItem)13 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)10 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 Map (java.util.Map)8 Point (org.eclipse.swt.graphics.Point)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)7 SQLException (java.sql.SQLException)7 PreparedStatement (java.sql.PreparedStatement)6 DBResolution (com.cubrid.common.core.common.model.DBResolution)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)5 SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)5