Search in sources :

Example 21 with MySQLTableColumn

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

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 22 with MySQLTableColumn

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

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 23 with MySQLTableColumn

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

the class MySQLTableColumnManager method createDatabaseObject.

@Override
protected MySQLTableColumn createDatabaseObject(final DBRProgressMonitor monitor, final DBECommandContext context, final Object container, Object copyFrom, Map<String, Object> options) throws DBException {
    MySQLTable table = (MySQLTable) container;
    MySQLTableColumn column;
    if (copyFrom instanceof DBSEntityAttribute) {
        column = new MySQLTableColumn(monitor, table, (DBSEntityAttribute) copyFrom);
    } else {
        column = new MySQLTableColumn(table);
        // $NON-NLS-1$
        DBSDataType columnType = findBestDataType(table.getDataSource(), "varchar");
        column.setName(getNewColumnName(monitor, context, table));
        final String typeName = columnType == null ? "integer" : columnType.getName().toLowerCase();
        // $NON-NLS-1$
        column.setTypeName(typeName);
        column.setMaxLength(columnType != null && columnType.getDataKind() == DBPDataKind.STRING ? 100 : 0);
        column.setValueType(columnType == null ? Types.INTEGER : columnType.getTypeID());
        column.setOrdinalPosition(table.getCachedAttributes().size() + 1);
        column.setFullTypeName(DBUtils.getFullTypeName(column));
    }
    return column;
}
Also used : DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) MySQLTable(org.jkiss.dbeaver.ext.mysql.model.MySQLTable)

Example 24 with MySQLTableColumn

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

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)

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