use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.
the class SQLServerUniqueKeyConfigurator method configureObject.
@Override
public SQLServerTableUniqueKey configureObject(DBRProgressMonitor monitor, Object container, SQLServerTableUniqueKey primaryKey) {
return UITask.run(() -> {
EditConstraintPage editPage = new EditConstraintPage("Create constraint", primaryKey, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY });
if (!editPage.edit()) {
return null;
}
primaryKey.setConstraintType(editPage.getConstraintType());
primaryKey.setName(editPage.getConstraintName());
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
primaryKey.addColumn(new SQLServerTableUniqueKeyColumn(primaryKey, (SQLServerTableColumn) tableColumn, colIndex++));
}
return primaryKey;
});
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute 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;
});
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute 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;
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.
the class PostgreConstraintConfigurator method configureObject.
@Override
public PostgreTableConstraint configureObject(DBRProgressMonitor monitor, Object parent, PostgreTableConstraint constraint) {
return UITask.run(() -> {
EditConstraintPage editPage = new EditConstraintPage(PostgreMessages.edit_constraint_page_add_constraint, constraint, new DBSEntityConstraintType[] { DBSEntityConstraintType.PRIMARY_KEY, DBSEntityConstraintType.UNIQUE_KEY, DBSEntityConstraintType.CHECK });
if (!editPage.edit()) {
return null;
}
constraint.setName(editPage.getConstraintName());
constraint.setConstraintType(editPage.getConstraintType());
if (constraint.getConstraintType().isCustom()) {
constraint.setSource(editPage.getConstraintExpression());
} else {
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
constraint.addColumn(new PostgreTableConstraintColumn(constraint, (PostgreAttribute) tableColumn, colIndex++));
}
}
return constraint;
});
}
use of org.jkiss.dbeaver.model.struct.DBSEntityAttribute in project dbeaver by dbeaver.
the class AttributesSelectorPage method fillAttributes.
private void fillAttributes(final DBSEntity entity) {
final List<DBSEntityAttribute> attrList = new ArrayList<>();
AbstractJob loadJob = new AbstractJob("Load entity attributes") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
monitor.beginTask("Load attributes", 1);
try {
for (DBSEntityAttribute attr : CommonUtils.safeCollection(entity.getAttributes(monitor))) {
if (isShowHiddenAttributes() || !DBUtils.isHiddenObject(attr) || DBUtils.isRowIdAttribute(attr)) {
attrList.add(attr);
}
}
} catch (DBException e) {
return GeneralUtils.makeErrorStatus("Error loading attributes", e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
loadJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
UIUtils.syncExec(() -> {
for (DBSEntityAttribute attribute : attrList) {
TableItem columnItem = new TableItem(columnsTable, SWT.NONE);
AttributeInfo col = new AttributeInfo(attribute);
attributes.add(col);
DBNDatabaseNode attributeNode = DBWorkbench.getPlatform().getNavigatorModel().findNode(attribute);
if (attributeNode != null) {
columnItem.setImage(0, DBeaverIcons.getImage(attributeNode.getNodeIcon()));
}
fillAttributeColumns(attribute, col, columnItem);
columnItem.setData(col);
if (isColumnSelected(attribute)) {
columnItem.setChecked(true);
handleItemSelect(columnItem, false);
}
}
UIUtils.packColumns(columnsTable);
updateToggleButton();
});
}
});
loadJob.schedule();
}
Aggregations