Search in sources :

Example 1 with DBDRowIdentifier

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) ArrayList(java.util.ArrayList) DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBDRowIdentifier(org.jkiss.dbeaver.model.data.DBDRowIdentifier)

Example 2 with DBDRowIdentifier

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;
}
Also used : DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) DBDRowIdentifier(org.jkiss.dbeaver.model.data.DBDRowIdentifier)

Aggregations

DBDRowIdentifier (org.jkiss.dbeaver.model.data.DBDRowIdentifier)2 DBVEntityConstraint (org.jkiss.dbeaver.model.virtual.DBVEntityConstraint)2 ArrayList (java.util.ArrayList)1 DBException (org.jkiss.dbeaver.DBException)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)1