Search in sources :

Example 1 with DBSTableIndexColumn

use of org.jkiss.dbeaver.model.struct.rdb.DBSTableIndexColumn in project dbeaver by serge-rider.

the class SQLIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
    final TABLE_TYPE table = command.getObject().getTable();
    final OBJECT_TYPE index = command.getObject();
    // Create index
    final String indexName = DBUtils.getQuotedIdentifier(index.getDataSource(), index.getName());
    index.setName(indexName);
    StringBuilder decl = new StringBuilder(40);
    decl.append("CREATE ");
    if (index.isUnique()) {
        decl.append("UNIQUE ");
    }
    //$NON-NLS-1$
    decl.append("INDEX ").append(indexName).append(" ON ").append(//$NON-NLS-1$
    table.getFullyQualifiedName(DBPEvaluationContext.DDL)).append(//$NON-NLS-1$
    " (");
    try {
        // Get columns using void monitor
        boolean firstColumn = true;
        for (DBSTableIndexColumn indexColumn : CommonUtils.safeCollection(command.getObject().getAttributeReferences(VoidProgressMonitor.INSTANCE))) {
            //$NON-NLS-1$
            if (!firstColumn)
                decl.append(",");
            firstColumn = false;
            decl.append(indexColumn.getName());
            appendIndexColumnModifiers(decl, indexColumn);
        }
    } catch (DBException e) {
        log.error(e);
    }
    //$NON-NLS-1$
    decl.append(")");
    actions.add(new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_index, decl.toString()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSTableIndexColumn(org.jkiss.dbeaver.model.struct.rdb.DBSTableIndexColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Aggregations

DBException (org.jkiss.dbeaver.DBException)1 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)1 DBSTableIndexColumn (org.jkiss.dbeaver.model.struct.rdb.DBSTableIndexColumn)1