Search in sources :

Example 56 with SchemaInfo

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

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

the class ERTable method createEmptySchemaInfo.

public static SchemaInfo createEmptySchemaInfo(String tableName, String dbName) {
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.setType("user");
    schemaInfo.setClassname(tableName);
    schemaInfo.setDbname(dbName);
    schemaInfo.setVirtual(ClassType.NORMAL.getText());
    schemaInfo.setReuseOid(false);
    return schemaInfo;
}
Also used : SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 58 with SchemaInfo

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

the class ERTableColumn method setName.

public void setName(String newName) {
    if (StringUtil.isEqual(name, newName)) {
        return;
    }
    attr.setName(newName);
    SchemaInfo schemaInfo = this.getTable().getSchemaInfo();
    Constraint pk = schemaInfo.getPK();
    if (pk != null && pk.contains(name, false)) {
        pk.replaceAttribute(name, newName);
    }
    schemaInfo.updateAttrNameInIndex(name, newName);
    name = newName;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 59 with SchemaInfo

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

the class ERSchemaTableNodesLoader method getAllUserTablesInfo.

/**
	 * Get all the user tables node infos
	 * 
	 * @return List<SchemaInfo>
	 */
public List<SchemaInfo> getAllUserTablesInfo() {
    List<DefaultSchemaNode> tableNodes = getAllTablesNode();
    List<SchemaInfo> tables = new ArrayList<SchemaInfo>();
    for (DefaultSchemaNode node : tableNodes) {
        SchemaInfo table = dbNode.getDatabaseInfo().getSchemaInfo(node.getName());
        if (null != table) {
            tables.add(table);
        }
    }
    return tables;
}
Also used : ArrayList(java.util.ArrayList) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 60 with SchemaInfo

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

the class CubridTableParser method getReferredColumns.

/**
	 * Get the other table columns name which is referred on the foreign key
	 * constraint
	 * 
	 * @param schemaInfo
	 * @param fkConstaint
	 * @return The results is all columns of pk in the primary table actually.
	 * @throws Exception
	 */
private List<String> getReferredColumns(SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
    List<String> resultList = new ArrayList<String>();
    String refTable = getReferencedTableName(fkConstaint);
    SchemaInfo referedSchemaInfo = getReferencedTable(refTable);
    if (referedSchemaInfo != null) {
        Constraint pkConstaint = referedSchemaInfo.getPK();
        if (pkConstaint == null) {
            throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
        }
        List<String> pklist = pkConstaint.getAttributes();
        for (int i = 0; i < pklist.size(); i++) {
            String referedKey = pklist.get(i).replace(" ASC", "").replace(" DESC", "");
            resultList.add(referedKey);
        }
    }
    return resultList;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) ERException(com.cubrid.common.ui.er.ERException) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

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