Search in sources :

Example 76 with Constraint

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

the class FKTableViewerContentProvider method getElements.

/**
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 * @param inputElement the input element
	 * @return the array of elements to display in the viewer
	 */
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.FOREIGNKEY.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)

Example 77 with Constraint

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

the class IndexTableViewerContentProvider method getElements.

/**
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 * @param inputElement the input element
	 * @return the array of elements to display in the viewer PRIMARY KEY
	 */
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof SchemaInfo) {
        SchemaInfo schema = (SchemaInfo) inputElement;
        List<Constraint> list = schema.getAllIndexTypeConstraints();
        return list.toArray();
    } else {
        return new Object[0];
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 78 with Constraint

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

the class IndexTableViewerLabelProvider method getColumnText.

/**
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
	 *      int)
	 * @param element the object representing the entire row, or
	 *        <code>null</code> indicating that no input object is set in the
	 *        viewer
	 * @param columnIndex the zero-based index of the column in which the label
	 *        appears
	 * @return String or or <code>null</code> if there is no text for the given
	 *         object at columnIndex
	 */
public String getColumnText(Object element, int columnIndex) {
    Constraint a = (Constraint) element;
    switch(columnIndex) {
        case 0:
            return a.getName();
        case 1:
            return a.getType();
        case 2:
            List<String> columns = a.getAttributes();
            StringBuffer bf = new StringBuffer();
            int count = 0;
            for (String column : columns) {
                if (count != 0) {
                    bf.append(",");
                }
                bf.append(column);
                count++;
            }
            return bf.toString();
        case 3:
            List<String> rules = a.getRules();
            StringBuffer rulebf = new StringBuffer();
            int count2 = 0;
            for (String rule : rules) {
                if (count2 != 0) {
                    rulebf.append(",");
                }
                rulebf.append(rule);
                count2++;
            }
            return rulebf.toString();
        case 4:
            return a.getDescription();
        default:
            break;
    }
    return null;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 79 with Constraint

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

the class DataCompareEditorPart method fetchHashedCompareDataCompatible.

private List<HashedCompareData> fetchHashedCompareDataCompatible(Connection conn, SchemaInfo schemaInfo, long start, int rows) {
    // FIXME logic code move to core module
    Statement stmt = null;
    ResultSet rs = null;
    StringBuilder pkColumns = new StringBuilder();
    Constraint constraint = schemaInfo.getPK();
    if (constraint != null) {
        for (String column : constraint.getAttributes()) {
            if (pkColumns.length() > 0) {
                pkColumns.append(",");
            }
            pkColumns.append(QuerySyntax.escapeKeyword(column));
        }
    }
    String escapedTableName = QuerySyntax.escapeKeyword(schemaInfo.getClassname());
    StringBuilder sql = new StringBuilder();
    sql.append(" SELECT * FROM ").append(escapedTableName);
    sql.append(" ORDER BY ").append(pkColumns);
    sql.append(" FOR ORDERBY_NUM() BETWEEN ").append(start + 1);
    sql.append(" AND ").append(start + rows);
    List<HashedCompareData> result = new ArrayList<HashedCompareData>();
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery(sql.toString());
        ResultSetMetaData meta = rs.getMetaData();
        while (rs.next()) {
            StringBuilder hash = new StringBuilder();
            boolean isPk = true;
            List<String> pkColumnList = new ArrayList<String>();
            List<String> pkValueList = new ArrayList<String>();
            List<String> pkTypeList = new ArrayList<String>();
            // TODO : sort
            for (int j = 1, len = meta.getColumnCount(); j <= len; j++) {
                String columnName = meta.getColumnName(j);
                String columnType = DataType.isNumberType(meta.getColumnTypeName(j)) ? HashedCompareData.NUMBER_TYPE : HashedCompareData.STRING_TYPE;
                isPk = constraint.getAttributes().contains(columnName);
                if (isPk) {
                    pkColumnList.add(columnName);
                    pkValueList.add(rs.getString(j));
                    pkTypeList.add(columnType);
                } else {
                    String val = null;
                    if (DataType.isSetDataType(meta.getColumnTypeName(j))) {
                        String colType = FieldHandlerUtils.amendDataTypeByResult(rs, j, meta.getColumnTypeName(j));
                        val = (String) FieldHandlerUtils.getRsValueForExport(colType, (CUBRIDResultSetProxy) rs, j, "{NULL}");
                    } else {
                        val = rs.getString(j);
                    }
                    if (val == null) {
                        val = "{NULL}";
                    }
                    hash.append(StringUtil.md5(val));
                }
            }
            HashedCompareData data = new HashedCompareData(pkColumnList, pkValueList, pkTypeList, StringUtil.md5(hash.toString()));
            result.add(data);
        }
    } catch (Exception e) {
        printToConsoleOnWorkThread(StringUtil.NEWLINE, false);
        printToConsoleOnWorkThread(e.getMessage(), true);
        LOGGER.error(sql.toString(), e);
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    return result;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Constraint(com.cubrid.common.core.common.model.Constraint) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResultSetMetaData(java.sql.ResultSetMetaData) ResultSet(java.sql.ResultSet) HashedCompareData(com.cubrid.common.ui.compare.data.model.HashedCompareData)

Example 80 with Constraint

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

the class EditVirtualTableDialog method okPressed.

protected void okPressed() {
    if (!checkValid()) {
        return;
    }
    String message = (oldSchemaInfo == null) ? Messages.msgCreateTableConfirm : Messages.msgAlterTableConfirm;
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    SchemaInfo newSchemaInfo = getNewSchemaInfo();
    newSchemaInfo.removeInvalidPKAndIndex(true);
    newERTable.setName(tableNameText.getText().trim(), isPhysical);
    if (erSchema.isPhysicModel()) {
        newSchemaInfo.setDescription(tableDescText.getText().trim());
    }
    //remove empty column
    List<ERTableColumn> columns = newERTable.getColumns();
    for (int i = columns.size() - 1; i >= 0; i--) {
        if (StringUtil.isEmpty(columns.get(i).getName())) {
            columns.remove(i);
        }
    }
    //check
    ERSchema tmpErSchema = new ERSchema(erSchema.getName() + "_tmp", erSchema.getInput());
    Map<String, SchemaInfo> schemaInfos = erSchema.getAllSchemaInfo();
    schemaInfos.put(newSchemaInfo.getClassname(), newSchemaInfo);
    CubridTableParser tableParser = new CubridTableParser(tmpErSchema);
    tableParser.buildERTables(schemaInfos.values(), -1, -1, false);
    Map<String, Exception> failedTables = tableParser.getFailedTables();
    Map<String, List<Constraint>> removedFKs = tableParser.getRemovedFKConstraints();
    if (failedTables.size() > 0) {
        Set<String> tables = failedTables.keySet();
        String tableName = tables.iterator().next();
        CommonUITool.openErrorBox(failedTables.get(tableName).getMessage());
        return;
    }
    if (removedFKs.size() > 0) {
        Set<String> tables = removedFKs.keySet();
        String tableName = tables.iterator().next();
        List<Constraint> constraints = removedFKs.get(tableName);
        CommonUITool.openErrorBox("Foreign relation is error. Please check the relation of " + constraints.get(0).getName() + ", in table of " + tableName);
        return;
    }
    try {
        if (isTableNameChanged() && erSchema.isContainsTable(newERTable.getName(isPhysical), isPhysical)) {
            throw new Exception(Messages.bind(Messages.errExistTable, newERTable.getName(isPhysical)));
        }
        newERTable.checkValidate();
    } catch (Exception e) {
        CommonUITool.openErrorBox(e.getMessage());
        return;
    }
    super.okPressed();
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) Constraint(com.cubrid.common.core.common.model.Constraint) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ERSchema(com.cubrid.common.ui.er.model.ERSchema) ArrayList(java.util.ArrayList) List(java.util.List) 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