Search in sources :

Example 6 with DBResolution

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

the class SuperClassUtil method getNextResolution.

/**
	 * get next resolution from a list,given removed resolution is not an alias
	 * resolution
	 * 
	 * @param resolutions List<DBResolution> the given list that contains the
	 *        instances of DBResolution
	 * @param removedResolution DBResolution the given reference of DBResolution
	 *        object
	 * @param conflicts List<String[]> the given list that contains the
	 *        conflicts items
	 * @return DBResolution the next reference of DBResolution
	 */
public static DBResolution getNextResolution(List<DBResolution> resolutions, DBResolution removedResolution, List<String[]> conflicts) {
    String column = removedResolution.getName();
    String table = removedResolution.getClassName();
    boolean started = false;
    boolean found = false;
    DBResolution firstResolution = null;
    DBResolution nextResolution = null;
    for (String[] strs : conflicts) {
        if (!strs[0].equals(column)) {
            continue;
        }
        if (!started) {
            DBResolution r = SuperClassUtil.getResolution(resolutions, strs[0], strs[2]);
            if (r == null) {
                started = true;
                firstResolution = new DBResolution(strs[0], strs[2], null);
            }
        }
        if (!found && strs[2].equals(table)) {
            found = true;
            continue;
        }
        if (started && found) {
            DBResolution r = SuperClassUtil.getResolution(resolutions, strs[0], strs[2]);
            if (r == null) {
                nextResolution = new DBResolution(strs[0], strs[2], null);
                break;
            }
        }
        continue;
    }
    assert (found);
    if (nextResolution == null) {
        return firstResolution;
    } else {
        return nextResolution;
    }
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution)

Example 7 with DBResolution

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

the class AddResolutionDialog 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) {
        String sup = superCombo.getText();
        String col = columnCombo.getText();
        String alias = aliasText.getText().trim();
        resolution = new DBResolution();
        resolution.setName(col);
        resolution.setClassName(sup);
        resolution.setAlias(alias);
        resolution.setClassResolution(isClassResolution);
    } else {
        resolution = null;
    }
    super.buttonPressed(buttonId);
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution)

Example 8 with DBResolution

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

the class AddResolutionDialog method validate.

/**
	 * 
	 * Validate the content
	 * 
	 * @return boolean
	 */
private boolean validate() {
    setErrorMessage(null);
    getButton(IDialogConstants.OK_ID).setEnabled(false);
    String sup = superCombo.getText();
    String col = columnCombo.getText();
    String alias = aliasText.getText();
    if ("".equals(sup)) {
        //$NON-NLS-1$
        setErrorMessage(Messages.errNoSelectedSuperClass);
        return false;
    }
    if ("".equals(col)) {
        //$NON-NLS-1$
        setErrorMessage(Messages.errNoSelectedColumn);
        return false;
    }
    if ("".equals(alias)) {
        for (String[] str : currentConflicts) {
            if (str[0].equals(col) && str[2].equals(tableName)) {
                String msg = Messages.bind(Messages.errExistLocColumn, col);
                setErrorMessage(msg);
                aliasText.setFocus();
                return false;
            }
        }
    }
    List<DBResolution> resolutions = null;
    if (isClassResolution) {
        resolutions = schema.getClassResolutions();
    } else {
        resolutions = schema.getResolutions();
    }
    for (DBResolution r : resolutions) {
        if (r.getName().equals(col) && r.getClassName().equals(sup) && r.getAlias().equals(alias)) {
            setErrorMessage(Messages.errExistResolution);
            return false;
        }
    }
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    return true;
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution)

Example 9 with DBResolution

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

the class SchemaInfoTest method testData.

/**
	 * test data
	 * 
	 */
public void testData() {
    assertNull(classname);
    assertNull(type);
    assertNull(owner);
    assertNull(virtual);
    assertNull(dbname);
    assertNull(is_partitiongroup);
    assertNull(partitiongroupname);
    assertNull(classAttributes);
    // DBAttribute
    assertNull(attributes);
    // DBMethod
    assertNull(classMethods);
    // DBMethod
    assertNull(methods);
    // DBResolution
    assertNull(classResolutions);
    // DBResolution
    assertNull(resolutions);
    // Constraint
    assertNull(constraints);
    // add super classes
    assertNull(superClasses);
    assertNull(subClasses);
    assertNull(oidList);
    assertNull(methodFiles);
    assertNull(querySpecs);
    assertNull(partitions);
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.getConstraints();
    schemaInfo.getDBMethodByName("name");
    schemaInfo.addResolution(new DBResolution());
    schemaInfo.addResolution(new DBResolution());
    schemaInfo.addResolution(new DBResolution(), true);
    schemaInfo.addResolution(new DBResolution(), false);
    schemaInfo.clone();
    schemaInfo.getInheritAttributes();
    schemaInfo.getLocalAttributes();
    schemaInfo.getInheritClassAttributes();
    //create List<SchemaInfo>
    List<SchemaInfo> supers = new ArrayList<SchemaInfo>();
    supers.add(schemaInfo);
    schemaInfo.getPK(supers);
    schemaInfo.getConstraintByName("constraintName");
    schemaInfo.getConstraintByName("name", "type");
    schemaInfo.removeConstraintByName("name", "type");
    schemaInfo.removeUniqueByAttrName("constraintName");
    schemaInfo.getFKConstraint("name");
    schemaInfo.getFKConstraints();
    schemaInfo.removeFKConstraint("constraintName");
    schemaInfo.isAttributeUnique(new DBAttribute(), supers);
    schemaInfo.getForeignTables();
    //create constraint
    String name = "name";
    String type = "FOREIGN KEY";
    int keyCount = 6;
    // String
    List<String> rules = new ArrayList<String>();
    rules.add("REFERENCES aa");
    // test getters and setters
    Constraint constraintYes = new Constraint(name, type);
    constraintYes.setName(name);
    constraintYes.setType(type);
    constraintYes.setKeyCount(keyCount);
    constraintYes.setRules(rules);
    schemaInfo.addConstraint(constraintYes);
    schemaInfo.getFKConstraints();
    schemaInfo.getForeignTables();
    schemaInfo.removeFKConstraint(constraintYes);
    schemaInfo.addConstraint(constraintYes);
    schemaInfo.removeFKConstraint("name");
    schemaInfo.addConstraint(constraintYes);
    schemaInfo.addQuerySpec("name");
    schemaInfo.addMethodFile("constraintName");
    schemaInfo.addMethod(null);
    schemaInfo.addClassMethod(null);
    schemaInfo.removeConstraintByName("name", "type");
    schemaInfo.removeDBAttributeByName("name", false);
    partitions = null;
    schemaInfo.getPartitionByName("name");
    schemaInfo.isSystemClass();
    schemaInfo.setType("system");
    schemaInfo.isSystemClass();
    schemaInfo.setClassname("classname");
    schemaInfo.compareTo(schemaInfo);
    schemaInfo.hashCode();
    //+test the equal()
    assertTrue(schemaInfo.equals(schemaInfo));
    assertFalse(schemaInfo.equals(null));
    assertFalse(schemaInfo.equals("other object"));
    //-test the equal()
    schemaInfo.getMethodFiles();
    schemaInfo.getClassMethods();
    schemaInfo.getMethods();
    schemaInfo.getLocalClassAttributes();
    schemaInfo.getSubClasses();
    schemaInfo.getOidList();
    List<PartitionInfo> partitiona = new ArrayList<PartitionInfo>();
    //create partition
    String className = "className";
    String partitionName = "partitionName";
    @SuppressWarnings("unused") String partitionClassName = "partitionClassName";
    PartitionType partitionType = PartitionType.HASH;
    String partitionExpr = "partitionExpr";
    final List<String> partitionValues = new ArrayList<String>();
    int rows = -1;
    PartitionInfo partitionInfo3 = new PartitionInfo(className, partitionName, partitionType, partitionExpr, partitionValues, rows);
    partitiona.add(partitionInfo3);
    schemaInfo.setPartitionList(partitiona);
    schemaInfo.getPartitionByName("name");
    schemaInfo.getQuerySpecs();
    SchemaInfo schemaInfoOld = new SchemaInfo();
    schemaInfo.setAttributes(attributes);
    schemaInfo.setSuperClasses(superClasses);
    schemaInfo.setClassAttributes(classAttributes);
    schemaInfo.setClassResolutions(classResolutions);
    schemaInfo.setResolutions(classResolutions);
    schemaInfoOld.equals(schemaInfo);
    //create DBMethod();
    String sname = "name";
    String inherit = "inherit";
    String function = "function";
    // test getters and setters
    DBMethod dbMethod = new DBMethod();
    dbMethod.setName(sname);
    dbMethod.setInherit(inherit);
    dbMethod.setFunction(function);
    DBMethod dbMethod3 = new DBMethod();
    dbMethod3.setName("notsame");
    dbMethod3.setInherit("notsame");
    dbMethod3.setFunction("notsame");
    SchemaInfo schemaInfo3 = new SchemaInfo();
    schemaInfo3.addMethod(dbMethod);
    schemaInfo3.addClassMethod(dbMethod);
    schemaInfo3.getDBMethodByName("name");
    SchemaInfo schemaInfo2 = new SchemaInfo();
    //create DBAttribute
    String dname = "name";
    String dtype = "type";
    // it belongs to which class
    String dinherit = "inherit";
    boolean indexed = true;
    boolean notNull = true;
    boolean shared = true;
    boolean unique = true;
    String defaultValue = "defaultValue";
    DBAttribute dbAttribute1 = new DBAttribute(dname, dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
    DBAttribute dbAttribute2 = new DBAttribute(dname, dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
    DBAttribute dbAttribute3 = new DBAttribute("notsame", dtype, dinherit, indexed, notNull, shared, unique, defaultValue, null);
    //+test the equal()
    SchemaInfo schemaInfo1 = new SchemaInfo();
    schemaInfo1.addAttribute(dbAttribute2);
    schemaInfo2.addAttribute(dbAttribute3);
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.addAttribute(dbAttribute2);
    schemaInfo2.removeDBAttributeByName("notsame", false);
    schemaInfo2.addAttribute(dbAttribute2);
    schemaInfo1.addClassAttribute(dbAttribute2);
    schemaInfo2.addClassAttribute(dbAttribute3);
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.addClassAttribute(dbAttribute2);
    schemaInfo2.removeDBAttributeByName("notsame", true);
    schemaInfo2.addAttribute(dbAttribute2);
    schemaInfo1.addClassMethod(dbMethod);
    schemaInfo2.addClassMethod(dbMethod3);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.equals(schemaInfo1);
    schemaInfoOld.addClassMethod(dbMethod);
    schemaInfo2.getClassMethods().clear();
    schemaInfo2.addClassMethod(dbMethod);
    //create DBResolution
    String rname = "name";
    String rclassName = "className";
    String alias = "alias";
    boolean isClassResolution = true;
    DBResolution dbResolution = new DBResolution(rname, rclassName, alias);
    dbResolution.setName(rname);
    dbResolution.setClassName(rclassName);
    dbResolution.setAlias(alias);
    dbResolution.setClassResolution(isClassResolution);
    DBResolution dbResolution3 = new DBResolution(rname, rclassName, alias);
    dbResolution3.setName("notsame");
    dbResolution3.setClassName(rclassName);
    dbResolution3.setAlias(alias);
    dbResolution3.setClassResolution(isClassResolution);
    schemaInfo1.addClassResolution(dbResolution);
    schemaInfo2.addClassResolution(dbResolution3);
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.addClassResolution(dbResolution);
    schemaInfo2.getClassResolutions().clear();
    schemaInfo2.addClassResolution(dbResolution);
    schemaInfo1.setClassname("classname");
    schemaInfo2.setClassname("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setClassname("classname");
    schemaInfo2.setClassname("classname");
    schemaInfo1.setClassname("classname");
    schemaInfo2.setClassname("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setClassname("classname");
    schemaInfo2.setClassname("classname");
    schemaInfo2.addConstraint(new Constraint(false));
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.addConstraint(constraintYes);
    schemaInfo2.getConstraints().clear();
    schemaInfo2.addConstraint(constraintYes);
    schemaInfo1.setDbname("dbname");
    schemaInfo2.setDbname("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setDbname("dbname");
    schemaInfo2.setDbname("dbname");
    schemaInfo1.setPartitionGroup("isPartitiongroup");
    schemaInfo2.setPartitionGroup("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setPartitionGroup("isPartitiongroup");
    schemaInfo2.setPartitionGroup("isPartitiongroup");
    schemaInfo1.setOwner("owner");
    schemaInfo2.setOwner("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setOwner("owner");
    schemaInfo2.setOwner("owner");
    schemaInfo1.addResolution(dbResolution);
    schemaInfo2.addResolution(dbResolution3);
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.addResolution(dbResolution);
    schemaInfo2.getResolutions().clear();
    schemaInfo2.addResolution(dbResolution);
    schemaInfo1.getSuperClasses().clear();
    schemaInfo1.addSuperClass("superClass");
    schemaInfo2.addSuperClass("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.addSuperClass("superClass");
    schemaInfo2.getSuperClasses().clear();
    schemaInfo2.addSuperClass("superClass");
    schemaInfo1.setType("type");
    schemaInfo2.setType("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setType("type");
    schemaInfo2.setType("type");
    schemaInfo1.setVirtual("virtual");
    schemaInfo2.setVirtual("notsame");
    schemaInfoOld.equals(schemaInfo1);
    schemaInfo2.equals(schemaInfo1);
    schemaInfoOld.setVirtual("virtual");
    schemaInfo2.setVirtual("virtual");
    //+test the equal()
    schemaInfo.addDBAttribute(dbAttribute2, true);
    schemaInfo.addDBAttribute(dbAttribute2, false);
    schemaInfo.replaceDBAttributeByName(dbAttribute1, dbAttribute2, true, supers);
    schemaInfo.replaceDBAttributeByName(dbAttribute1, dbAttribute2, false, supers);
    schemaInfo.setClassname("inherit");
    schemaInfo.getLocalClassAttributes();
    constraintYes.setType("UNIQUE");
    List<String> a = new ArrayList<String>();
    a.add("name");
    constraintYes.setAttributes(a);
    schemaInfo.addConstraint(constraintYes);
    schemaInfo.removeUniqueByAttrName("name");
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) DBMethod(com.cubrid.common.core.common.model.DBMethod) PartitionType(com.cubrid.common.core.common.model.PartitionType) Constraint(com.cubrid.common.core.common.model.Constraint) DBResolution(com.cubrid.common.core.common.model.DBResolution) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 10 with DBResolution

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

the class TableModelTest method testModelDBResolution.

public void testModelDBResolution() {
    DBResolution bean = new DBResolution();
    bean.setName("name");
    assertEquals(bean.getName(), "name");
    bean.setClassName("className");
    assertEquals(bean.getClassName(), "className");
    bean.setAlias("alias");
    assertEquals(bean.getAlias(), "alias");
    bean.isClassResolution();
    bean.setClassResolution(true);
    assertEquals(bean.isClassResolution(), true);
}
Also used : DBResolution(com.cubrid.common.core.common.model.DBResolution)

Aggregations

DBResolution (com.cubrid.common.core.common.model.DBResolution)18 Constraint (com.cubrid.common.core.common.model.Constraint)10 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)6 ArrayList (java.util.ArrayList)6 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)5 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)2 PartitionType (com.cubrid.common.core.common.model.PartitionType)2 List (java.util.List)2 DBMethod (com.cubrid.common.core.common.model.DBMethod)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)1 PreparedStatement (java.sql.PreparedStatement)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1