use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by serge-rider.
the class EditForeignKeyPage method handleUniqueKeySelect.
private void handleUniqueKeySelect() {
curConstraint = null;
fkColumns.clear();
ownColumns = null;
columnsTable.removeAll();
if (curConstraints.isEmpty() || uniqueKeyCombo.getSelectionIndex() < 0) {
return;
}
curConstraint = curConstraints.get(uniqueKeyCombo.getSelectionIndex());
try {
// Read column nodes with void monitor because we already cached them above
for (DBSEntityAttributeRef pkColumn : curConstraint.getAttributeReferences(VoidProgressMonitor.INSTANCE)) {
FKColumnInfo fkColumnInfo = new FKColumnInfo(pkColumn.getAttribute());
// Try to find matched column in own table
Collection<? extends DBSEntityAttribute> tmpColumns = ownTable.getAttributes(VoidProgressMonitor.INSTANCE);
ownColumns = tmpColumns == null ? Collections.<DBSTableColumn>emptyList() : new ArrayList<>(ownTable.getAttributes(VoidProgressMonitor.INSTANCE));
if (!CommonUtils.isEmpty(ownColumns)) {
for (DBSEntityAttribute ownColumn : ownColumns) {
if (ownColumn.getName().equals(pkColumn.getAttribute().getName()) && ownTable != pkColumn.getAttribute().getParentObject()) {
fkColumnInfo.ownColumn = ownColumn;
break;
}
}
}
fkColumns.add(fkColumnInfo);
TableItem item = new TableItem(columnsTable, SWT.NONE);
if (fkColumnInfo.ownColumn != null) {
item.setText(0, fkColumnInfo.ownColumn.getName());
item.setImage(0, getColumnIcon(fkColumnInfo.ownColumn));
item.setText(1, fkColumnInfo.ownColumn.getFullTypeName());
}
item.setText(2, pkColumn.getAttribute().getName());
item.setImage(2, getColumnIcon(pkColumn.getAttribute()));
item.setText(3, pkColumn.getAttribute().getFullTypeName());
item.setData(fkColumnInfo);
}
} catch (DBException e) {
UIUtils.showErrorDialog(getShell(), CoreMessages.dialog_struct_edit_fk_error_load_constraint_columns_title, CoreMessages.dialog_struct_edit_fk_error_load_constraint_columns_message, e);
}
UIUtils.packColumns(columnsTable, true);
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by serge-rider.
the class DBVUtils method findAttributeTransformers.
@Nullable
public static DBDAttributeTransformer[] findAttributeTransformers(@NotNull DBDAttributeBinding binding, @Nullable Boolean custom) {
DBPDataSource dataSource = binding.getDataSource();
DBPDataSourceContainer container = dataSource.getContainer();
List<? extends DBDAttributeTransformerDescriptor> tdList = container.getPlatform().getValueHandlerRegistry().findTransformers(dataSource, binding.getAttribute(), custom);
if (tdList == null || tdList.isEmpty()) {
return null;
}
boolean filtered = false;
DBSEntityAttribute entityAttribute = binding.getEntityAttribute();
if (entityAttribute != null) {
DBVEntity vEntity = findVirtualEntity(entityAttribute.getParentObject(), false);
if (vEntity != null) {
DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(binding, false);
if (vAttr != null) {
final DBVTransformSettings transformSettings = getTransformSettings(vAttr, false);
if (transformSettings != null) {
filtered = transformSettings.filterTransformers(tdList);
}
}
}
}
if (!filtered) {
// Leave only default transformers
for (int i = 0; i < tdList.size(); ) {
if (tdList.get(i).isCustom() || !tdList.get(i).isApplicableByDefault()) {
tdList.remove(i);
} else {
i++;
}
}
}
if (tdList.isEmpty()) {
return null;
}
DBDAttributeTransformer[] result = new DBDAttributeTransformer[tdList.size()];
for (int i = 0; i < tdList.size(); i++) {
result[i] = tdList.get(i).getInstance();
}
return result;
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by serge-rider.
the class ComplexTypeAttributeTransformer method createNestedTypeBindings.
static void createNestedTypeBindings(DBCSession session, DBDAttributeBinding attribute, List<Object[]> rows, DBSEntity dataType) throws DBException {
List<DBDAttributeBinding> nestedBindings = new ArrayList<>();
for (DBSEntityAttribute nestedAttr : CommonUtils.safeCollection(dataType.getAttributes(session.getProgressMonitor()))) {
DBDAttributeBindingType nestedBinding = new DBDAttributeBindingType(attribute, nestedAttr);
nestedBinding.lateBinding(session, rows);
nestedBindings.add(nestedBinding);
}
if (!nestedBindings.isEmpty()) {
attribute.setNestedBindings(nestedBindings);
}
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute 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