Search in sources :

Example 6 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by dbeaver.

the class ResultSetViewer method editEntityIdentifier.

boolean editEntityIdentifier(DBRProgressMonitor monitor) throws DBException {
    DBDRowIdentifier virtualEntityIdentifier = getVirtualEntityIdentifier();
    if (virtualEntityIdentifier == null) {
        log.warn("No virtual identifier");
        return false;
    }
    DBVEntityConstraint constraint = (DBVEntityConstraint) virtualEntityIdentifier.getUniqueKey();
    EditConstraintPage page = new EditConstraintPage("Define virtual unique identifier", constraint);
    if (!page.edit()) {
        return false;
    }
    Collection<DBSEntityAttribute> uniqueAttrs = page.getSelectedAttributes();
    constraint.setAttributes(uniqueAttrs);
    virtualEntityIdentifier = getVirtualEntityIdentifier();
    if (virtualEntityIdentifier == null) {
        log.warn("No virtual identifier defined");
        return false;
    }
    virtualEntityIdentifier.reloadAttributes(monitor, model.getAttributes());
    persistConfig();
    return true;
}
Also used : EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Example 7 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by serge-rider.

the class EditVirtualEntityDialog method createUniqueKeysPage.

private void createUniqueKeysPage(TabFolder tabFolder) {
    uniqueConstraint = vEntity.getBestIdentifier();
    if (uniqueConstraint == null) {
        return;
    }
    TabItem ukItem = new TabItem(tabFolder, SWT.NONE);
    ukItem.setText("Virtual Unique Key");
    ukItem.setImage(DBeaverIcons.getImage(DBIcon.TREE_UNIQUE_KEY));
    ukItem.setData(InitPage.UNIQUE_KEY);
    editUniqueKeyPage = new EditConstraintPage("Define unique identifier", uniqueConstraint);
    editUniqueKeyPage.createControl(tabFolder);
    ukItem.setControl(editUniqueKeyPage.getControl());
}
Also used : EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)

Example 8 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by serge-rider.

the class OracleConstraintConfigurator method configureObject.

@Override
public OracleTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, OracleTableConstraint constraint) {
    return UITask.run(() -> {
        EditConstraintPage editPage = new EditConstraintPage(OracleUIMessages.edit_oracle_constraint_manager_dialog_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        constraint.setSearchCondition(editPage.getConstraintExpression());
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            constraint.addColumn(new OracleTableConstraintColumn(constraint, (OracleTableColumn) tableColumn, colIndex++));
        }
        return constraint;
    });
}
Also used : DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) OracleTableColumn(org.jkiss.dbeaver.ext.oracle.model.OracleTableColumn) OracleTableConstraintColumn(org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraintColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) OracleTableConstraint(org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraint)

Example 9 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by serge-rider.

the class MySQLConstraintConfigurator method configureObject.

@Override
public MySQLTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableConstraint constraint) {
    MySQLDataSource dataSource = constraint.getDataSource();
    return UITask.run(() -> {
        EditConstraintPage editPage;
        if (dataSource.supportsCheckConstraints()) {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        } else {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        }
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (editPage.getConstraintType() == DBSEntityConstraintType.CHECK && dataSource.supportsCheckConstraints()) {
            constraint.setCheckClause(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new MySQLTableConstraintColumn(constraint, (MySQLTableColumn) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint) MySQLTableConstraintColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)

Example 10 with EditConstraintPage

use of org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage in project dbeaver by dbeaver.

the class MySQLConstraintConfigurator method configureObject.

@Override
public MySQLTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableConstraint constraint) {
    MySQLDataSource dataSource = constraint.getDataSource();
    return UITask.run(() -> {
        EditConstraintPage editPage;
        if (dataSource.supportsCheckConstraints()) {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
        } else {
            editPage = new EditConstraintPage(MySQLUIMessages.edit_constraint_manager_title, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
        }
        if (!editPage.edit()) {
            return null;
        }
        constraint.setName(editPage.getConstraintName());
        constraint.setConstraintType(editPage.getConstraintType());
        if (editPage.getConstraintType() == DBSEntityConstraintType.CHECK && dataSource.supportsCheckConstraints()) {
            constraint.setCheckClause(editPage.getConstraintExpression());
        } else {
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                constraint.addColumn(new MySQLTableConstraintColumn(constraint, (MySQLTableColumn) tableColumn, colIndex++));
            }
        }
        return constraint;
    });
}
Also used : MySQLDataSource(org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) DBSEntityConstraintType(org.jkiss.dbeaver.model.struct.DBSEntityConstraintType) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) EditConstraintPage(org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint) MySQLTableConstraintColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)

Aggregations

EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)14 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 SQLServerTableColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableColumn)2 SQLServerTableUniqueKeyColumn (org.jkiss.dbeaver.ext.mssql.model.SQLServerTableUniqueKeyColumn)2 MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)2 MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)2 MySQLTableConstraint (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint)2 MySQLTableConstraintColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)2 OracleTableColumn (org.jkiss.dbeaver.ext.oracle.model.OracleTableColumn)2 OracleTableConstraint (org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraint)2 OracleTableConstraintColumn (org.jkiss.dbeaver.ext.oracle.model.OracleTableConstraintColumn)2 PostgreAttribute (org.jkiss.dbeaver.ext.postgresql.model.PostgreAttribute)2 PostgreTableConstraint (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraint)2 PostgreTableConstraintColumn (org.jkiss.dbeaver.ext.postgresql.model.PostgreTableConstraintColumn)2 DBSEntityConstraintType (org.jkiss.dbeaver.model.struct.DBSEntityConstraintType)2