Search in sources :

Example 6 with ExasolTableColumn

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);
        }
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBEPersistAction(org.jkiss.dbeaver.model.edit.DBEPersistAction) ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 7 with ExasolTableColumn

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)));
}
Also used : ArrayList(java.util.ArrayList) ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 8 with ExasolTableColumn

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;
}
Also used : ArrayList(java.util.ArrayList) ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) ExasolTable(org.jkiss.dbeaver.ext.exasol.model.ExasolTable) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 9 with ExasolTableColumn

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;
    });
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) ExasolTableIndexColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableIndexColumn) EditIndexPage(org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)

Example 10 with ExasolTableColumn

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);
        }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ExasolTableColumn(org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

ExasolTableColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn)24 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)14 ArrayList (java.util.ArrayList)6 DBException (org.jkiss.dbeaver.DBException)4 ExasolTable (org.jkiss.dbeaver.ext.exasol.model.ExasolTable)4 ExasolTableIndexColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableIndexColumn)4 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)4 Matcher (java.util.regex.Matcher)2 ExasolTableBase (org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase)2 ExasolTablePartitionColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTablePartitionColumn)2 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)2 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)2 DBSIndexType (org.jkiss.dbeaver.model.struct.rdb.DBSIndexType)2 EditIndexPage (org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)2