Search in sources :

Example 1 with DBVEntityConstraint

use of org.jkiss.dbeaver.model.virtual.DBVEntityConstraint 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 DBVEntityConstraint

use of org.jkiss.dbeaver.model.virtual.DBVEntityConstraint in project dbeaver by serge-rider.

the class ValidateUniqueKeyUsageDialog method useAllColumns.

private static boolean useAllColumns(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()) {
        DBWorkbench.getPlatformUI().showError("Use All Columns", "No valid columns found for unique key");
        return false;
    }
    constraint.setAttributes(uniqueColumns);
    constraint.setUseAllColumns(true);
    try {
        identifier.reloadAttributes(new VoidProgressMonitor(), viewer.getModel().getAttributes());
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError("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) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBDRowIdentifier(org.jkiss.dbeaver.model.data.DBDRowIdentifier)

Example 3 with DBVEntityConstraint

use of org.jkiss.dbeaver.model.virtual.DBVEntityConstraint in project dbeaver by dbeaver.

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()) {
        DBUserInterface.getInstance().showError("Use All Columns", "No valid columns found for unique key");
        return false;
    }
    constraint.setAttributes(uniqueColumns);
    try {
        identifier.reloadAttributes(new VoidProgressMonitor(), viewer.getModel().getAttributes());
    } catch (DBException e) {
        DBUserInterface.getInstance().showError("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) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBDRowIdentifier(org.jkiss.dbeaver.model.data.DBDRowIdentifier)

Example 4 with DBVEntityConstraint

use of org.jkiss.dbeaver.model.virtual.DBVEntityConstraint in project dbeaver by serge-rider.

the class VirtualUniqueKeyEditAction method isEnabled.

@Override
public boolean isEnabled() {
    DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
    DBVEntityConstraint vConstraint = vEntity == null ? null : vEntity.getBestIdentifier();
    return vConstraint != null && (define != vConstraint.hasAttributes());
}
Also used : DBVEntityConstraint(org.jkiss.dbeaver.model.virtual.DBVEntityConstraint) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Aggregations

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