use of org.jkiss.dbeaver.model.data.DBDRowIdentifier in project dbeaver by serge-rider.
the class ValidateUniqueKeyUsageDialog method useAllColumns.
private static boolean useAllColumns(Shell shell, ResultSetViewer viewer) {
// Use all columns
final DBDRowIdentifier identifier = viewer.getVirtualEntityIdentifier();
DBVEntityConstraint constraint = (DBVEntityConstraint) identifier.getUniqueKey();
List<DBSEntityAttribute> uniqueColumns = new ArrayList<>();
for (DBDAttributeBinding binding : viewer.getModel().getAttributes()) {
if (binding.getEntityAttribute() != null) {
uniqueColumns.add(binding.getEntityAttribute());
}
}
if (uniqueColumns.isEmpty()) {
UIUtils.showErrorDialog(shell, "Use All Columns", "No valid columns found for unique key");
return false;
}
constraint.setAttributes(uniqueColumns);
try {
identifier.reloadAttributes(VoidProgressMonitor.INSTANCE, viewer.getModel().getAttributes());
} catch (DBException e) {
UIUtils.showErrorDialog(shell, "Use All Columns", "Can't reload unique columns", e);
return false;
}
return true;
}
use of org.jkiss.dbeaver.model.data.DBDRowIdentifier in project dbeaver by serge-rider.
the class ValidateUniqueKeyUsageDialog method validateUniqueKey.
public static boolean validateUniqueKey(@NotNull ResultSetViewer viewer, @NotNull DBCExecutionContext executionContext) {
final DBDRowIdentifier identifier = viewer.getVirtualEntityIdentifier();
if (identifier == null) {
// No key
return false;
}
if (!CommonUtils.isEmpty(identifier.getAttributes())) {
// Key already defined
return true;
}
if (executionContext.getDataSource().getContainer().getPreferenceStore().getBoolean(DBeaverPreferences.RS_EDIT_USE_ALL_COLUMNS)) {
if (useAllColumns(viewer.getControl().getShell(), viewer)) {
return true;
}
}
ValidateUniqueKeyUsageDialog dialog = new ValidateUniqueKeyUsageDialog(viewer, executionContext);
int result = dialog.open();
return result == IDialogConstants.OK_ID;
}
Aggregations