use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn in project dbeaver by serge-rider.
the class ExasolTableColumnManager method addObjectModifyActions.
// -----
// Alter
// -----
@Override
protected void addObjectModifyActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actionList, ObjectChangeCommand command, Map<String, Object> options) {
ExasolTableColumn exasolColumn = command.getObject();
Map<Object, Object> props = command.getProperties();
if (props.containsKey("defaultValue") || props.containsKey("dataType") || props.containsKey("scale") || props.containsKey("maxLength") || props.containsKey("autoGenerated") || props.containsKey("identityValue") || props.containsKey("required")) {
// build nullability string
String nullability = "";
if (exasolColumn.isOriRequired() != null && exasolColumn.isOriRequired() != exasolColumn.isRequired())
nullability = exasolColumn.isRequired() ? "NOT NULL" : "NULL";
final String deltaSQL = DBUtils.getQuotedIdentifier(exasolColumn) + " " + exasolColumn.getFormatType() + " " + (exasolColumn.getDefaultValue() == null ? "" : " DEFAULT " + exasolColumn.getDefaultValue()) + " " + formatIdentiy(exasolColumn.isAutoGenerated(), exasolColumn.getIdentityValue()) + " " + nullability;
if (!deltaSQL.isEmpty()) {
String sqlAlterColumn = String.format(SQL_ALTER, exasolColumn.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL), deltaSQL);
actionList.add(new SQLDatabasePersistAction(CMD_ALTER, sqlAlterColumn));
}
}
// Comment
DBEPersistAction commentAction = buildCommentAction(exasolColumn);
if (commentAction != null) {
actionList.add(commentAction);
}
if (command.getProperties().containsKey("distKey")) {
try {
actionList.addAll(modifyDistKey(monitor, exasolColumn));
} catch (DBException e) {
log.error("Failed to modify distkey settings", e);
}
}
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn in project dbeaver by serge-rider.
the class ExasolTableColumnManager method generateCreateDist.
private SQLDatabasePersistAction generateCreateDist(Collection<ExasolTableColumn> distKey) {
ExasolTable table = null;
Collection<String> names = new ArrayList<>();
for (ExasolTableColumn c : distKey) {
if (table == null)
table = (ExasolTable) c.getParentObject();
names.add(c.getName());
}
return new SQLDatabasePersistAction("Create Distribution Key", String.format(CREATE_DIST_KEY, table.getFullyQualifiedName(DBPEvaluationContext.DDL), CommonUtils.joinStrings(",", names)));
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn in project dbeaver by serge-rider.
the class ExasolTableColumnManager method modifyDistKey.
private Collection<SQLDatabasePersistAction> modifyDistKey(DBRProgressMonitor monitor, ExasolTableColumn exasolColumn) throws DBException {
ExasolTable table = (ExasolTable) exasolColumn.getParentObject();
Collection<ExasolTableColumn> distKey = table.getDistributionKey(monitor);
Collection<SQLDatabasePersistAction> commands = new ArrayList<SQLDatabasePersistAction>();
if (table.getAdditionalInfo(monitor).getHasDistKey(monitor)) {
commands.add(generateDropDist(exasolColumn));
}
if (!distKey.isEmpty())
commands.add(generateCreateDist(distKey));
return commands;
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn in project dbeaver by serge-rider.
the class ExasolIndexConfigurator method configureObject.
@Override
public ExasolTableIndex configureObject(DBRProgressMonitor monitor, Object container, ExasolTableIndex index) {
return UITask.run(() -> {
EditIndexPage editPage = new EditIndexPage("create index", index, Arrays.asList(new DBSIndexType("LOCAL", "LOCAL"), new DBSIndexType("GLOBAL", "GLOBAL")), false);
if (!editPage.edit()) {
return null;
}
index.setIndexType(editPage.getIndexType());
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
index.addColumn(new ExasolTableIndexColumn(index, (ExasolTableColumn) tableColumn, colIndex++));
}
index.setName(index.getIndexType().getName() + " INDEX " + index.getSimpleColumnString());
return index;
});
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn in project dbeaver by dbeaver.
the class ExasolTableColumnManager method addObjectCreateActions.
@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
final ExasolTableColumn exasolColumn = command.getObject();
// build nullability string
String nullability = exasolColumn.isRequired() ? "NOT NULL" : "NULL";
final String addSQL = DBUtils.getQuotedIdentifier(exasolColumn) + " " + exasolColumn.getFormatType() + " " + (exasolColumn.getDefaultValue() == null ? "" : " DEFAULT " + exasolColumn.getDefaultValue()) + " " + formatIdentiy(exasolColumn.isAutoGenerated(), exasolColumn.getIdentityValue()) + " " + nullability;
actions.add(new SQLDatabasePersistAction("Add column", "ALTER TABLE " + exasolColumn.getTable().getFullyQualifiedName(DBPEvaluationContext.DDL) + " ADD COLUMN " + addSQL + " "));
if (exasolColumn.isDistKey())
try {
modifyDistKey(monitor, exasolColumn);
} catch (DBException e) {
log.error("Failed to generate distribution key", e);
}
}
Aggregations