use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class CubridTableParser method addFKShip.
public void addFKShip(ERTable erTable, SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
String referencedTableName = getReferencedTableName(fkConstaint);
SchemaInfo referencedTable = getReferencedTable(fkConstaint);
List<String> referenceNames = getReferenceColumns(fkConstaint);
List<String> referredPkColumnNames = getReferredColumns(schemaInfo, fkConstaint);
boolean isSelfRef = false;
if (referencedTable == null) {
// If the referenced Table do not be added to the ERShema. Do not
// load it and do not build the relationship and delete the
// constraint
schemaInfo.removeFKConstraint(fkConstaint);
addEle2RemovedFKConstraints(schemaInfo.getClassname(), fkConstaint);
return;
}
if (StringUtil.isEqualNotIgnoreNull(referencedTableName, erTable.getName())) {
// self reference FK
isSelfRef = true;
}
if (referenceNames.size() != referredPkColumnNames.size()) {
throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
}
ERTable referencedT = erSchema.getTable(referencedTable.getClassname());
boolean needBuildRefedTable = false;
if (referencedT == null && !isSelfRef) {
referencedT = new ERTable(referencedTable, erSchema);
needBuildRefedTable = true;
} else {
// the referenceTable has been built, do not build again.
}
if (isSelfRef) {
erTable.setHasSelfFKRef(true);
return;
}
Relationship ship = new Relationship(fkConstaint.getName(), erTable, referencedT);
for (int i = 0; i < referenceNames.size(); i++) {
ship.addRelation(referenceNames.get(i), referredPkColumnNames.get(i));
}
erTable.addForeignKeyShipAndFire(ship);
if (needBuildRefedTable) {
buildERTable(referencedT, referencedTable);
boolean success = erSchema.addTable(referencedT);
if (success && !successTables.contains(referencedT)) {
successTables.add(referencedT);
}
}
referencedT.FireTargeted(ship);
return;
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class ERAttributeLabelProvider method getColumnImage.
public Image getColumnImage(Object element, int columnIndex) {
if (element == null) {
return null;
}
ERTableColumn erColumn = (ERTableColumn) element;
DBAttribute dbAttribute = erColumn.getAttr();
if (dbAttribute == null || dbAttribute.getInherit() == null || schema == null) {
return null;
}
String property = editorAdaptor.getColumnProperty(columnIndex);
if (StringUtil.isEqual(property, IAttributeColumn.COL_PK)) {
String attrName = dbAttribute.getName();
Constraint pk = schema.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
return PK_IMAGE;
}
return editableMode ? UNCHECK_IMAGE : null;
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL)) {
String attrName = dbAttribute.getName();
Constraint pk = schema.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
return DISABLED_CHECK_IMAGE;
}
if (dbAttribute.isNotNull()) {
return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
} else {
return editableMode ? UNCHECK_IMAGE : null;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
String attrName = dbAttribute.getName();
Constraint pk = schema.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
return DISABLED_CHECK_IMAGE;
}
if (dbAttribute.isUnique() && schema.isAttributeUnique(dbAttribute, supers)) {
return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
} else {
return editableMode ? UNCHECK_IMAGE : DISABLED_UNCHECK_IMAGE;
}
} else if (StringUtil.isEqual(property, IAttributeColumn.COL_SHARED)) {
if (dbAttribute.isShared()) {
return editableMode ? CHECK_IMAGE : DISABLED_CHECK_IMAGE;
} else {
return editableMode ? UNCHECK_IMAGE : null;
}
}
return null;
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class ColumnProposalDetailInfo method getColumnAdditionalInfo.
/**
* Get column proposal additional information
*
* @return String
*/
public String getColumnAdditionalInfo() {
StringBuilder additionalInfoBf = new StringBuilder();
additionalInfoBf.append(Messages.quickColInfoColumnName).append(": ").append(attributeInfo.getName()).append(StringUtil.NEWLINE);
additionalInfoBf.append(Messages.quickColInfoTableName).append(": ").append(schemaInfo.getClassname()).append(StringUtil.NEWLINE);
// boolean isClassAttr = attributeInfo.isClassAttribute();
// additionalInfoBf.append(
// com.cubrid.common.ui.cubrid.table.Messages.grpColumnType).append(
// ": ").append(isClassAttr ? "CLASS" : "INSTANCE").append(
// StringUtil.NEWLINE);
String dataType = attributeInfo.getType();
additionalInfoBf.append(Messages.quickColInfoDataType).append(": ").append(dataType).append(StringUtil.NEWLINE);
boolean isNotNull = attributeInfo.isNotNull();
additionalInfoBf.append(Messages.quickColInfoNotNull).append(": ").append(isNotNull ? "Y" : "N").append(StringUtil.NEWLINE);
boolean isUnique = attributeInfo.isUnique();
additionalInfoBf.append(Messages.quickColInfoUnique).append(": ").append(isUnique ? "Y" : "N").append(StringUtil.NEWLINE);
String defaultValue = attributeInfo.getDefault();
if (defaultValue != null && defaultValue.length() > 0) {
additionalInfoBf.append(Messages.quickColInfoDefaultValue).append(": ").append(defaultValue).append(StringUtil.NEWLINE);
}
SerialInfo autoInc = attributeInfo.getAutoIncrement();
if (autoInc != null) {
String currValue = autoInc.getCurrentValue();
String increValue = autoInc.getIncrementValue();
additionalInfoBf.append(Messages.quickColInfoAutoIncr).append(": (").append(currValue).append(",").append(increValue).append(")").append(StringUtil.NEWLINE);
}
List<Constraint> constraintList = schemaInfo.getConstraints();
boolean isPrimaryKey = false;
String foreignTable = null;
String indexType = null;
for (Constraint constraint : constraintList) {
if (constraint.getAttributes().contains(attributeInfo.getName()) || constraint.getClassAttributes().contains(attributeInfo.getName())) {
String type = constraint.getType();
if (Constraint.ConstraintType.PRIMARYKEY.getText().equals(type)) {
isPrimaryKey = true;
} else if (Constraint.ConstraintType.FOREIGNKEY.getText().equals(type)) {
foreignTable = constraint.getReferencedTable();
} else if (Constraint.ConstraintType.INDEX.getText().equals(type) || Constraint.ConstraintType.UNIQUE.getText().equals(type) || Constraint.ConstraintType.REVERSEINDEX.getText().equals(type) || Constraint.ConstraintType.REVERSEUNIQUE.getText().equals(type)) {
indexType = type;
}
break;
}
}
additionalInfoBf.append(Messages.quickColInfoPk).append(": ").append(isPrimaryKey ? "Y" : "N").append(StringUtil.NEWLINE);
if (foreignTable != null && foreignTable.trim().length() > 0) {
additionalInfoBf.append(Messages.lblFK).append(" REFERENCES ").append(foreignTable).append(StringUtil.NEWLINE);
}
if (indexType != null) {
additionalInfoBf.append(Messages.quickColInfoIndex).append(": ").append(indexType).append(StringUtil.NEWLINE);
}
return additionalInfoBf.toString();
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class TableEditorPart method deleteColumn.
private void deleteColumn() {
if (!CommonUITool.openConfirmBox(Messages.msgDeleteColumnConfirm)) {
return;
}
TableItem[] tblItems = columnsTable.getSelection();
if (tblItems.length > 0) {
DBAttribute attr = (DBAttribute) tblItems[0].getData();
List<DBAttribute> items = newSchemaInfo.getAttributes();
if (!items.contains(attr)) {
return;
}
}
TableItem[] selection = columnsTable.getSelection();
int selectionIndex = columnsTable.getSelectionIndex();
if (selection != null && selection.length >= 1) {
List<String> attrNames = new ArrayList<String>();
for (int m = 0; m < selection.length; m++) {
attrNames.add(m, selection[m].getText(1));
}
List<SchemaInfo> allSupers = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo);
Constraint pk = newSchemaInfo.getPK(allSupers);
List<String> pkAttributes = pk == null ? new ArrayList<String>() : pk.getAttributes();
boolean hasPk = false;
for (String pkAttribute : pkAttributes) {
if (attrNames.contains(pkAttribute)) {
hasPk = true;
break;
}
}
if (hasPk) {
if (attrNames.containsAll(pkAttributes)) {
newSchemaInfo.removeConstraintByName(pk.getName(), Constraint.ConstraintType.PRIMARYKEY.getText());
} else {
CommonUITool.openErrorBox(Messages.errColumnNotDropForPk);
return;
}
}
for (PartitionInfo partitionInfo : newSchemaInfo.getPartitionList()) {
String partitionExpr = partitionInfo.getPartitionExpr();
if (StringUtil.isNotEmpty(partitionExpr)) {
if (partitionExpr.startsWith("[") && partitionExpr.endsWith("]")) {
partitionExpr = partitionExpr.substring(1, partitionExpr.length() - 1);
if (attrNames.contains(partitionExpr)) {
CommonUITool.openErrorBox(Messages.errDropForPartitonColumn);
return;
}
} else {
if (attrNames.contains(partitionExpr)) {
CommonUITool.openErrorBox(Messages.errDropForPartitonColumn);
return;
}
}
}
}
for (TableItem selec : selection) {
DBAttribute oldAttribute = (DBAttribute) selec.getData();
if (oldAttribute == null) {
continue;
}
if (!oldAttribute.getInherit().equals(newSchemaInfo.getClassname())) {
CommonUITool.openErrorBox(Messages.errColumnNotDrop);
return;
}
if (oldAttribute.isClassAttribute()) {
newSchemaInfo.getClassAttributes().remove(oldAttribute);
} else {
newSchemaInfo.getAttributes().remove(oldAttribute);
// newSchemaInfo.removeUniqueByAttrName(selec.getText(1));
// For bug TOOLS-2390 After delete a column of a table,some
// related index doesn't been deleted.
newSchemaInfo.removeConstraintByAttrName(oldAttribute.getName());
indexTableView.setInput(newSchemaInfo);
fkTableView.setInput(newSchemaInfo);
}
SuperClassUtil.fireSuperClassChanged(database.getDatabaseInfo(), oldSchemaInfo, newSchemaInfo, newSchemaInfo.getSuperClasses());
String oldAttrName = oldAttribute.getName();
addDropAttrLog(oldAttrName, oldAttribute.isClassAttribute());
}
attrLabelProvider.setSchema(newSchemaInfo);
loadColumnData();
int itemCount = columnsTable.getItemCount();
columnsTable.select(selectionIndex < itemCount ? selectionIndex : selectionIndex - 1);
columnsTable.setFocus();
}
}
use of com.cubrid.common.core.common.model.Constraint in project cubrid-manager by CUBRID.
the class TableEditorPart method createFkIndexTabItem.
/**
* Create foreign key/Index tab item.
*
* @param tabFolder the object of TabFolder
*/
private void createFkIndexTabItem(final TabFolder tabFolder) {
final TabItem foreignKeyTabItem = new TabItem(tabFolder, SWT.NONE);
foreignKeyTabItem.setText(Messages.infoIndexesTab);
final Composite composite = new Composite(tabFolder, SWT.NONE);
GridLayout gridLayout = new GridLayout();
composite.setLayout(gridLayout);
foreignKeyTabItem.setControl(composite);
// create the fk table viewer
final Label fkLabel = new Label(composite, SWT.NONE);
fkLabel.setText(Messages.lblFK);
fkTableView = new TableViewer(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
fkTable = fkTableView.getTable();
final GridData gdFkTable = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
fkTable.setLayoutData(gdFkTable);
fkTable.setLinesVisible(true);
fkTable.setHeaderVisible(true);
TableColumn tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(100);
tblCol.setText(Messages.tblColumnFK);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(119);
tblCol.setText(Messages.tblColumnColumnName);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(93);
tblCol.setText(Messages.tblColumnForeignTable);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(143);
tblCol.setText(Messages.tblColumnForeignColumnName);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(84);
tblCol.setText(Messages.tblColumnUpdateRule);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(86);
tblCol.setText(Messages.tblColumnDeleteRule);
tblCol = new TableColumn(fkTable, SWT.NONE);
tblCol.setWidth(100);
tblCol.setText(Messages.tblColumnCacheColumn);
FKTableViewerContentProvider fkContentProvider = new FKTableViewerContentProvider();
FKTableViewerLabelProvider fkLabelProvider = new FKTableViewerLabelProvider(database.getDatabaseInfo());
fkTableView.setContentProvider(fkContentProvider);
fkTableView.setLabelProvider(fkLabelProvider);
fkTableView.setInput(newSchemaInfo);
CommonUITool.hackForYosemite(fkTableView.getTable());
final Composite fkBtnComposite = new Composite(composite, SWT.NONE);
final GridData gdBtnComposite = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
fkBtnComposite.setLayoutData(gdBtnComposite);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
fkBtnComposite.setLayout(gridLayout);
final GridData gdFKBTN = new GridData(SWT.LEFT, SWT.CENTER, false, false);
final Button addFKBTN = new Button(fkBtnComposite, SWT.NONE);
addFKBTN.setLayoutData(gdFKBTN);
addFKBTN.setText(Messages.btnAddFk);
addFKBTN.addSelectionListener(new AddFkBtnListenerOnFkIndexTab());
final Button editFKBTN = new Button(fkBtnComposite, SWT.NONE);
editFKBTN.setLayoutData(gdFKBTN);
editFKBTN.setEnabled(false);
editFKBTN.setText(Messages.btnEditFk);
editFKBTN.addSelectionListener(new EditFkBtnListenerOnFkIndexTab());
final Button deleteFKBTN = new Button(fkBtnComposite, SWT.NONE);
deleteFKBTN.setLayoutData(gdFKBTN);
deleteFKBTN.setEnabled(false);
deleteFKBTN.setText(Messages.btnDelFk);
deleteFKBTN.addSelectionListener(new DelFkBtnListenerOnFkIndexTab());
fkTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (database == null || database.getDatabaseInfo() == null || newSchemaInfo == null) {
return;
}
TableItem[] items = fkTable.getSelection();
if (items == null || items.length == 0) {
deleteFKBTN.setEnabled(false);
editFKBTN.setEnabled(false);
} else {
deleteFKBTN.setEnabled(true);
editFKBTN.setEnabled(items.length == 1);
for (TableItem item : items) {
String fkName = item.getText(0);
List<SchemaInfo> superList = SuperClassUtil.getSuperClasses(database.getDatabaseInfo(), newSchemaInfo.getSuperClasses());
if (newSchemaInfo.isInSuperClasses(superList, fkName)) {
deleteFKBTN.setEnabled(false);
editFKBTN.setEnabled(false);
}
}
}
}
});
// create index table view
final Label indexLabel = new Label(composite, SWT.NONE);
indexLabel.setText(Messages.lblIndexes);
indexTableView = new TableViewer(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
indexTable = indexTableView.getTable();
indexTable.setLinesVisible(true);
indexTable.setHeaderVisible(true);
final GridData gdIndexTable = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1);
indexTable.setLayoutData(gdIndexTable);
CommonUITool.hackForYosemite(indexTable);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(150);
tblCol.setText(Messages.tblColumnIndexName);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(78);
tblCol.setText(Messages.tblColumnIndexType);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(218);
tblCol.setText(Messages.tblColumnOnColumns);
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(282);
tblCol.setText(Messages.tblColumnIndexRule);
if (CompatibleUtil.isCommentSupports(database.getDatabaseInfo())) {
tblCol = new TableColumn(indexTable, SWT.NONE);
tblCol.setWidth(250);
tblCol.setText(Messages.tblColumnIndexMemo);
}
IndexTableViewerContentProvider indexContentProvider = new IndexTableViewerContentProvider();
IndexTableViewerLabelProvider indexLabelProvider = new IndexTableViewerLabelProvider();
indexTableView.setContentProvider(indexContentProvider);
indexTableView.setLabelProvider(indexLabelProvider);
indexTableView.setInput(newSchemaInfo);
indexTableView.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
StructuredSelection selected = (StructuredSelection) event.getSelection();
if (selected == null) {
return;
}
Constraint constraint = (Constraint) selected.getFirstElement();
openEditIndexDialog(constraint);
}
});
final Composite indexBtnComposite = new Composite(composite, SWT.NONE);
final GridData gdIndexBtnComposite = new GridData(SWT.RIGHT, SWT.CENTER, false, false);
indexBtnComposite.setLayoutData(gdIndexBtnComposite);
gridLayout = new GridLayout();
gridLayout.numColumns = 3;
indexBtnComposite.setLayout(gridLayout);
final GridData gdIndexBTN = new GridData(SWT.LEFT, SWT.CENTER, false, false);
final Button addIndexBTN = new Button(indexBtnComposite, SWT.NONE);
addIndexBTN.setLayoutData(gdIndexBTN);
addIndexBTN.setText(Messages.btnAddIndex);
addIndexBTN.addSelectionListener(new AddIndexBtnListenerOnFkIndexTab());
final Button editIndexBTN = new Button(indexBtnComposite, SWT.NONE);
editIndexBTN.setLayoutData(gdIndexBTN);
editIndexBTN.setEnabled(false);
editIndexBTN.setText(Messages.btnEditIndex);
editIndexBTN.addSelectionListener(new EditIndexBtnListenerOnFkIndexTab());
final Button deleteIndexBTN = new Button(indexBtnComposite, SWT.NONE);
deleteIndexBTN.setLayoutData(gdIndexBTN);
deleteIndexBTN.setEnabled(false);
deleteIndexBTN.setText(Messages.btnDelIndex);
deleteIndexBTN.addSelectionListener(new DelIndexBtnListenerOnFkIndexTab());
indexTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
TableItem[] items = indexTable.getSelection();
if (items == null || items.length == 0) {
deleteIndexBTN.setEnabled(false);
editIndexBTN.setEnabled(false);
} else {
deleteIndexBTN.setEnabled(true);
editIndexBTN.setEnabled(items.length == 1);
}
}
});
}
Aggregations