Search in sources :

Example 1 with MySQLTableConstraint

use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint in project dbeaver by serge-rider.

the class MySQLForeignKeyConfigurator method configureObject.

@Override
public MySQLTableForeignKey configureObject(DBRProgressMonitor monitor, Object table, MySQLTableForeignKey foreignKey) {
    return UITask.run(() -> {
        EditForeignKeyPage editPage = new EditForeignKeyPage(MySQLUIMessages.edit_foreign_key_manager_title, foreignKey, new DBSForeignKeyModifyRule[] { DBSForeignKeyModifyRule.NO_ACTION, DBSForeignKeyModifyRule.CASCADE, DBSForeignKeyModifyRule.RESTRICT, DBSForeignKeyModifyRule.SET_NULL, DBSForeignKeyModifyRule.SET_DEFAULT });
        if (!editPage.edit()) {
            return null;
        }
        foreignKey.setReferencedKey((MySQLTableConstraint) editPage.getUniqueConstraint());
        foreignKey.setDeleteRule(editPage.getOnDeleteRule());
        foreignKey.setUpdateRule(editPage.getOnUpdateRule());
        int colIndex = 1;
        for (EditForeignKeyPage.FKColumnInfo tableColumn : editPage.getColumns()) {
            foreignKey.addColumn(new MySQLTableForeignKeyColumn(foreignKey, (MySQLTableColumn) tableColumn.getOwnColumn(), colIndex++, (MySQLTableColumn) tableColumn.getRefColumn()));
        }
        return foreignKey;
    });
}
Also used : MySQLTableForeignKeyColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableForeignKeyColumn) EditForeignKeyPage(org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) MySQLTableConstraint(org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint)

Example 2 with MySQLTableConstraint

use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint 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)

Aggregations

MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)2 MySQLTableConstraint (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint)2 MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)1 MySQLTableConstraintColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)1 MySQLTableForeignKeyColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableForeignKeyColumn)1 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)1 DBSEntityConstraintType (org.jkiss.dbeaver.model.struct.DBSEntityConstraintType)1 EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)1 EditForeignKeyPage (org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage)1