use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn in project dbeaver by serge-rider.
the class MySQLTableColumnManager method getNestedDeclaration.
@Override
public StringBuilder getNestedDeclaration(MySQLTableBase owner, DBECommandAbstract<MySQLTableColumn> command) {
StringBuilder decl = super.getNestedDeclaration(owner, command);
final MySQLTableColumn column = command.getObject();
if (!CommonUtils.isEmpty(column.getExtraInfo())) {
//$NON-NLS-1$
decl.append(" ").append(column.getExtraInfo());
}
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$ //$NON-NLS-2$
decl.append(" COMMENT '").append(escapeComment(column.getComment())).append("'");
}
return decl;
}
use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn in project dbeaver by serge-rider.
the class MySQLTableColumnManager method addObjectReorderActions.
@Override
protected void addObjectReorderActions(List<DBEPersistAction> actions, ObjectReorderCommand command) {
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(column.getTable(), command) + " " + order));
}
use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn in project dbeaver by dbeaver.
the class MySQLTableColumnManager method addObjectReorderActions.
@Override
protected void addObjectReorderActions(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(column.getTable(), command, options) + " " + order));
}
use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn 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;
});
}
use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableColumn in project dbeaver by serge-rider.
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;
});
}
Aggregations