use of org.jkiss.dbeaver.model.struct.DBSEntityReferrer in project dbeaver by serge-rider.
the class AssociationPart method setSelected.
/**
* Sets the width of the line when selected
*/
@Override
public void setSelected(int value) {
super.setSelected(value);
if (value != EditPart.SELECTED_NONE) {
((PolylineConnection) getFigure()).setLineWidth(2);
} else {
((PolylineConnection) getFigure()).setLineWidth(1);
}
if (getSource() == null || getTarget() == null) {
// This part seems to be deleted
return;
}
DBSEntityAssociation association = getAssociation().getObject();
if (association instanceof DBSEntityReferrer && association.getReferencedConstraint() instanceof DBSEntityReferrer) {
List<AttributePart> sourceAttributes = getEntityAttributes((EntityPart) getSource(), DBUtils.getEntityAttributes(VoidProgressMonitor.INSTANCE, (DBSEntityReferrer) association.getReferencedConstraint()));
List<AttributePart> targetAttributes = getEntityAttributes((EntityPart) getTarget(), DBUtils.getEntityAttributes(VoidProgressMonitor.INSTANCE, (DBSEntityReferrer) association));
Color columnColor = value != EditPart.SELECTED_NONE ? Display.getDefault().getSystemColor(SWT.COLOR_RED) : getViewer().getControl().getForeground();
for (AttributePart attr : sourceAttributes) {
attr.getFigure().setForegroundColor(columnColor);
}
for (AttributePart attr : targetAttributes) {
attr.getFigure().setForegroundColor(columnColor);
}
}
}
use of org.jkiss.dbeaver.model.struct.DBSEntityReferrer in project dbeaver by serge-rider.
the class SQLForeignKeyManager method getNestedDeclaration.
@Override
protected StringBuilder getNestedDeclaration(TABLE_TYPE owner, DBECommandAbstract<OBJECT_TYPE> command) {
OBJECT_TYPE foreignKey = command.getObject();
boolean legacySyntax = isLegacyForeignKeySyntax(owner);
// Create column
String constraintName = DBUtils.getQuotedIdentifier(foreignKey.getDataSource(), foreignKey.getName());
StringBuilder decl = new StringBuilder(40);
if (!legacySyntax || !foreignKey.isPersisted()) {
decl.append("CONSTRAINT ");
}
if (!legacySyntax) {
//$NON-NLS-1$
decl.append(constraintName).append(" ");
}
//$NON-NLS-1$
decl.append(foreignKey.getConstraintType().getName().toUpperCase(Locale.ENGLISH)).append(//$NON-NLS-1$
" (");
try {
// Get columns using void monitor
final Collection<? extends DBSEntityAttributeRef> columns = command.getObject().getAttributeReferences(VoidProgressMonitor.INSTANCE);
boolean firstColumn = true;
for (DBSEntityAttributeRef constraintColumn : CommonUtils.safeCollection(columns)) {
final DBSEntityAttribute attribute = constraintColumn.getAttribute();
//$NON-NLS-1$
if (!firstColumn)
decl.append(",");
firstColumn = false;
if (attribute != null) {
decl.append(DBUtils.getQuotedIdentifier(attribute));
}
}
} catch (DBException e) {
log.error("Can't obtain reference attributes", e);
}
final DBSEntityConstraint refConstraint = foreignKey.getReferencedConstraint();
//$NON-NLS-1$ //$NON-NLS-2$
decl.append(") REFERENCES ").append(refConstraint == null ? "<?>" : DBUtils.getObjectFullName(refConstraint.getParentObject(), DBPEvaluationContext.DDL)).append("(");
if (refConstraint instanceof DBSEntityReferrer) {
try {
boolean firstColumn = true;
List<? extends DBSEntityAttributeRef> columns = ((DBSEntityReferrer) refConstraint).getAttributeReferences(VoidProgressMonitor.INSTANCE);
for (DBSEntityAttributeRef constraintColumn : CommonUtils.safeCollection(columns)) {
//$NON-NLS-1$
if (!firstColumn)
decl.append(",");
firstColumn = false;
final DBSEntityAttribute attribute = constraintColumn.getAttribute();
if (attribute != null) {
decl.append(DBUtils.getQuotedIdentifier(attribute));
}
}
} catch (DBException e) {
log.error("Can't obtain ref constraint reference attributes", e);
}
}
//$NON-NLS-1$
decl.append(")");
if (foreignKey.getDeleteRule() != null && !CommonUtils.isEmpty(foreignKey.getDeleteRule().getClause())) {
//$NON-NLS-1$
decl.append(" ON DELETE ").append(foreignKey.getDeleteRule().getClause());
}
if (foreignKey.getUpdateRule() != null && !CommonUtils.isEmpty(foreignKey.getUpdateRule().getClause())) {
//$NON-NLS-1$
decl.append(" ON UPDATE ").append(foreignKey.getUpdateRule().getClause());
}
if (legacySyntax) {
//$NON-NLS-1$
decl.append(" CONSTRAINT ").append(constraintName);
}
return decl;
}
Aggregations