Search in sources :

Example 16 with MySQLTableColumn

use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn 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 17 with MySQLTableColumn

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

the class MySQLTableColumnManager method addObjectModifyActions.

@Override
protected void addObjectModifyActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options) {
    final MySQLTableColumn column = command.getObject();
    actionList.add(new SQLDatabasePersistAction("Modify column", // $NON-NLS-1$ //$NON-NLS-2$
    "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " MODIFY COLUMN " + getNestedDeclaration(monitor, column.getTable(), command, options)));
}
Also used : MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 18 with MySQLTableColumn

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

the class MySQLTableColumnManager method addObjectRenameActions.

@Override
protected void addObjectRenameActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectRenameCommand command, Map<String, Object> options) {
    final MySQLTableColumn column = command.getObject();
    actions.add(new SQLDatabasePersistAction("Rename column", "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " CHANGE " + DBUtils.getQuotedIdentifier(column.getDataSource(), command.getOldName()) + " " + getNestedDeclaration(monitor, column.getTable(), command, options)));
}
Also used : MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 19 with MySQLTableColumn

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

the class MySQLTableColumnManager method getNestedDeclaration.

@Override
public StringBuilder getNestedDeclaration(DBRProgressMonitor monitor, MySQLTableBase owner, DBECommandAbstract<MySQLTableColumn> command, Map<String, Object> options) {
    StringBuilder decl = super.getNestedDeclaration(monitor, owner, command, options);
    final MySQLTableColumn column = command.getObject();
    if (column.isAutoGenerated() && (CommonUtils.isEmpty(column.getExtraInfo()) || !column.getExtraInfo().toLowerCase(Locale.ENGLISH).contains(MySQLConstants.EXTRA_AUTO_INCREMENT))) {
        // $NON-NLS-1$
        decl.append(" AUTO_INCREMENT");
    }
    if (!CommonUtils.isEmpty(column.getComment())) {
        // $NON-NLS-1$
        decl.append(" COMMENT ").append(SQLUtils.quoteString(column, column.getComment()));
    }
    return decl;
}
Also used : MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)

Example 20 with MySQLTableColumn

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

MySQLTableColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)24 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)12 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)6 MySQLTableConstraint (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraint)4 MySQLDataSource (org.jkiss.dbeaver.ext.mysql.model.MySQLDataSource)2 MySQLTable (org.jkiss.dbeaver.ext.mysql.model.MySQLTable)2 MySQLTableConstraintColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableConstraintColumn)2 MySQLTableForeignKeyColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableForeignKeyColumn)2 MySQLTableIndexColumn (org.jkiss.dbeaver.ext.mysql.model.MySQLTableIndexColumn)2 DBSDataType (org.jkiss.dbeaver.model.struct.DBSDataType)2 DBSEntityConstraintType (org.jkiss.dbeaver.model.struct.DBSEntityConstraintType)2 EditConstraintPage (org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage)2 EditForeignKeyPage (org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage)2