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];
}
}
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];
}
}
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;
}
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;
}
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();
}
Aggregations