Search in sources :

Example 6 with MySQLTableColumn

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

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

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

the class MySQLTableColumnManager method addObjectReorderActions.

@Override
protected void addObjectReorderActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectReorderCommand command, Map<String, Object> options) {
    final MySQLTableColumn column = command.getObject();
    String order = "FIRST";
    if (column.getOrdinalPosition() > 0) {
        for (MySQLTableColumn col : command.getObject().getTable().getCachedAttributes()) {
            if (col.getOrdinalPosition() == column.getOrdinalPosition() - 1) {
                order = "AFTER " + DBUtils.getQuotedIdentifier(col);
                break;
            }
        }
    }
    actions.add(new SQLDatabasePersistAction("Reorder column", "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " CHANGE " + DBUtils.getQuotedIdentifier(command.getObject()) + " " + getNestedDeclaration(monitor, column.getTable(), command, options) + " " + order));
}
Also used : MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 8 with MySQLTableColumn

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

the class MySQLTableColumnManager method addObjectReorderActions.

@Override
protected void addObjectReorderActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectReorderCommand command, Map<String, Object> options) {
    final MySQLTableColumn column = command.getObject();
    String order = "FIRST";
    if (column.getOrdinalPosition() > 0) {
        for (MySQLTableColumn col : command.getObject().getTable().getCachedAttributes()) {
            if (col.getOrdinalPosition() == column.getOrdinalPosition() - 1) {
                order = "AFTER " + DBUtils.getQuotedIdentifier(col);
                break;
            }
        }
    }
    actions.add(new SQLDatabasePersistAction("Reorder column", "ALTER TABLE " + column.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " CHANGE " + DBUtils.getQuotedIdentifier(command.getObject()) + " " + getNestedDeclaration(monitor, column.getTable(), command, options) + " " + order));
}
Also used : MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 9 with MySQLTableColumn

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

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

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

the class MySQLIndexConfigurator method configureObject.

@Override
public MySQLTableIndex configureObject(DBRProgressMonitor monitor, Object parent, MySQLTableIndex index) {
    return UITask.run(() -> {
        MyEditIndexPage editPage = new MyEditIndexPage(index);
        if (!editPage.edit()) {
            return null;
        }
        StringBuilder idxName = new StringBuilder(64);
        idxName.append(CommonUtils.escapeIdentifier(index.getParentObject().getName()));
        int colIndex = 1;
        for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
            if (colIndex == 1) {
                // $NON-NLS-1$
                idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
            }
            Integer length = (Integer) editPage.getAttributeProperty(tableColumn, MyEditIndexPage.PROP_LENGTH);
            index.addColumn(new MySQLTableIndexColumn(index, (MySQLTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC)), false, length == null ? null : String.valueOf(length)));
        }
        // $NON-NLS-1$
        idxName.append("_IDX");
        index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
        index.setName(idxName.toString());
        index.setIndexType(editPage.getIndexType());
        index.setUnique(editPage.isUnique());
        return index;
    });
}
Also used : MySQLTableIndexColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableIndexColumn) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) MySQLTableColumn(org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn)

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