Search in sources :

Example 21 with DBAttribute

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

the class AddColumnAction method run.

public void run() {
    ERTable table = this.getERTable();
    List<String> names = new ArrayList<String>();
    List<ERTableColumn> columns = table.getColumns();
    for (ERTableColumn column : columns) {
        names.add(column.getName());
    }
    AddColumnDialog dlg = new AddColumnDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), table.getName(), true, names, getERSchema());
    int ret = dlg.open();
    if (ret == IDialogConstants.OK_ID) {
        boolean isPhysical = table.getERSchema().isPhysicModel();
        String newName = dlg.getNewColumnName();
        String type = dlg.getDataType();
        String realType = null;
        String enumeration = null;
        if (isPhysical) {
            realType = DataType.getRealType(type);
        } else {
            String upPhysicalShowType = type;
            realType = DataType.getRealType(upPhysicalShowType);
        }
        if (DataType.DATATYPE_ENUM.equals(type)) {
            realType = DataType.getUpperEnumType().toLowerCase();
            enumeration = "('" + DataType.ENUM_DAFAULT_VALUE + "')";
        }
        DBAttribute addAttribute = new DBAttribute(newName, realType, table.getName(), false, false, false, false, null, Collation.DEFAULT_COLLATION);
        addAttribute.setEnumeration(enumeration);
        ERTableColumn col = new ERTableColumn(table, addAttribute, false);
        if (DataType.DATATYPE_STRING.equals(type)) {
            col.setLogicalType(DataType.DATATYPE_STRING);
        }
        table.addColumnAndFire(col);
    }
}
Also used : AddColumnDialog(com.cubrid.common.ui.er.dialog.AddColumnDialog) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ArrayList(java.util.ArrayList) ERTable(com.cubrid.common.ui.er.model.ERTable)

Example 22 with DBAttribute

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

the class QueryEditorDNDController method getScript.

/**
	 * Get the script
	 *
	 * @param selectedNode ISchemaNode
	 * @return script
	 */
private String getScript(ISchemaNode selectedNode) {
    // FIXME move this logic to core module
    if (selectedNode == null) {
        return null;
    }
    CubridDatabase db = selectedNode.getDatabase();
    DatabaseInfo dbInfo = db.getDatabaseInfo();
    GetAllAttrTask task = new GetAllAttrTask(dbInfo);
    task.setClassName(selectedNode.getName());
    task.getAttrList();
    if (task.getErrorMsg() != null) {
        CommonUITool.openErrorBox(task.getErrorMsg());
        return null;
    }
    List<DBAttribute> allAttrList = task.getAllAttrList();
    String sql = SQLGenerateUtils.getSelectSQLWithLimit(selectedNode.getName(), allAttrList);
    if (sql == null) {
        return "";
    }
    try {
        return new SqlFormattingStrategy().format(sql).trim() + StringUtil.NEWLINE + StringUtil.NEWLINE;
    } catch (Exception ignored) {
        return sql.trim() + StringUtil.NEWLINE + StringUtil.NEWLINE;
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy) GetAllAttrTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)

Example 23 with DBAttribute

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

the class SchemaAlterDDLTest method dropColumn.

/**
	 * drop a column
	 * 
	 * @param newSchema
	 * @param isClassAttribute
	 * @param attrName
	 */
private void dropColumn(SchemaInfo newSchema, boolean isClassAttribute, String attrName) {
    DBAttribute oldAttribute;
    oldAttribute = newSchema.getDBAttributeByName(attrName, isClassAttribute);
    if (!isClassAttribute) {
        newSchema.getAttributes().remove(oldAttribute);
        newSchema.removeUniqueByAttrName(attrName);
    } else {
        newSchema.getClassAttributes().remove(oldAttribute);
    }
    SuperClassUtil.fireSuperClassChanged(databaseInfo, testedSchemaInfo, newSchema, newSchema.getSuperClasses());
    String oldAttrName = oldAttribute.getName();
    addDropAttrLog(oldAttrName, isClassAttribute);
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute)

Example 24 with DBAttribute

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

the class SchemaAlterDDLTest method firePKAdded.

private void firePKAdded(SchemaInfo newSchema, Constraint newPK) {
    List<String> attrList = newPK.getAttributes();
    if (attrList.size() == 1) {
        String attr = attrList.get(0);
        DBAttribute a = newSchema.getDBAttributeByName(attr, false);
        boolean changed = false;
        if (!a.isNotNull()) {
            a.setNotNull(true);
            changed = true;
        }
        if (!a.isUnique()) {
            a.setUnique(true);
            changed = true;
        }
        if (changed) {
            changeList.addSchemeChangeLog(new SchemaChangeLog(a.getName(), a.getName(), SchemeInnerType.TYPE_ATTRIBUTE));
        }
    } else {
        for (String attr : attrList) {
            DBAttribute a = newSchema.getDBAttributeByName(attr, false);
            boolean changed = false;
            if (!a.isNotNull()) {
                a.setNotNull(true);
                changed = true;
            }
            if (changed) {
                changeList.addSchemeChangeLog(new SchemaChangeLog(a.getName(), a.getName(), SchemeInnerType.TYPE_ATTRIBUTE));
            }
        }
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute)

Example 25 with DBAttribute

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

the class SchemaAlterDDLTest method pkTest.

private void pkTest() {
    changeList = new SchemaChangeManager(databaseInfo, false);
    ddl = new SchemaDDL(changeList, databaseInfo);
    SchemaInfo newSchema = sup3.clone();
    Constraint newPK = new Constraint(false);
    newPK.setType(Constraint.ConstraintType.PRIMARYKEY.getText());
    newPK.addAttribute("smallint");
    newPK.addAttribute("integer");
    String op = "ADD";
    resetPK(newSchema, null, newPK, op);
    String alterDDL = ddl.getAlterDDL(sup3, newSchema);
    String expected = "ALTER TABLE sup3 ADD PRIMARY KEY([smallint],[integer]);";
    //		assertEquals(expected, alterDDL.trim());
    assertTrue(alterDDL.trim().indexOf(expected) > -1);
    /*	ALTER TABLE sup3 CHANGE COLUMN [smallint] [smallint] smallint AUTO_INCREMENT(1,1) NOT NULL;
ALTER TABLE sup3 CHANGE COLUMN [integer] [integer] integer AUTO_INCREMENT(2,1) NOT NULL;
ALTER TABLE sup3 ADD PRIMARY KEY([smallint],[integer]);
*/
    changeList = new SchemaChangeManager(databaseInfo, false);
    ddl = new SchemaDDL(changeList, databaseInfo);
    newSchema = testedSchemaInfo.clone();
    String testColumn = "pkattr";
    boolean isClassAttribute = false;
    DBAttribute attr = new DBAttribute();
    attr.setName(testColumn);
    attr.setType("smallint");
    attr.setInherit(newSchema.getClassname());
    addColumn(newSchema, isClassAttribute, attr);
    Constraint oldPK = newSchema.getPK(superList);
    newPK = oldPK.clone();
    newPK.addAttribute(testColumn);
    op = "MODIFY";
    resetPK(newSchema, oldPK, newPK, op);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    expected = "ALTER TABLE " + testTableName.toLowerCase() + " DROP CONSTRAINT pk_testschemaalterddl_name_gender;" + StringUtil.NEWLINE;
    expected += "ALTER TABLE " + testTableName.toLowerCase() + " ADD COLUMN pkattr smallint NOT NULL AFTER [shared];" + StringUtil.NEWLINE;
    expected += "ALTER TABLE " + testTableName.toLowerCase() + " ADD CONSTRAINT pk_testschemaalterddl_name_gender PRIMARY KEY ([name],gender,pkattr);";
    assertEquals(expected, alterDDL.trim());
    //drop pk
    oldPK = newPK;
    newPK = null;
    op = "DEL";
    resetPK(newSchema, oldPK, newPK, op);
    alterDDL = ddl.getAlterDDL(testedSchemaInfo, newSchema);
    expected = "ALTER TABLE " + testTableName.toLowerCase() + " DROP CONSTRAINT pk_testschemaalterddl_name_gender;" + StringUtil.NEWLINE;
    assertTrue(alterDDL.trim().indexOf(expected) > -1);
    expected = "ALTER TABLE " + testTableName.toLowerCase() + " ADD COLUMN pkattr smallint AFTER [shared];";
    //assertEquals(expected, alterDDL.trim());
    assertTrue(alterDDL.trim().indexOf(expected) > -1);
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

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