Search in sources :

Example 1 with DBSIndexType

use of org.jkiss.dbeaver.model.struct.rdb.DBSIndexType in project dbeaver by dbeaver.

the class IndexCache method fetchObject.

@Nullable
@Override
protected GenericTableIndex fetchObject(JDBCSession session, GenericStructContainer owner, GenericTable parent, String indexName, JDBCResultSet dbResult) throws SQLException, DBException {
    boolean isNonUnique = GenericUtils.safeGetBoolean(indexObject, dbResult, JDBCConstants.NON_UNIQUE);
    String indexQualifier = GenericUtils.safeGetStringTrimmed(indexObject, dbResult, JDBCConstants.INDEX_QUALIFIER);
    long cardinality = GenericUtils.safeGetLong(indexObject, dbResult, JDBCConstants.INDEX_CARDINALITY);
    int indexTypeNum = GenericUtils.safeGetInt(indexObject, dbResult, JDBCConstants.TYPE);
    DBSIndexType indexType;
    switch(indexTypeNum) {
        case DatabaseMetaData.tableIndexStatistic:
            // Table index statistic. Not a real index.
            log.debug("Skip statistics index '" + indexName + "' in '" + DBUtils.getObjectFullName(parent, DBPEvaluationContext.DDL) + "'");
            return null;
        // break;
        case DatabaseMetaData.tableIndexClustered:
            indexType = DBSIndexType.CLUSTERED;
            break;
        case DatabaseMetaData.tableIndexHashed:
            indexType = DBSIndexType.HASHED;
            break;
        case DatabaseMetaData.tableIndexOther:
            indexType = DBSIndexType.OTHER;
            break;
        default:
            indexType = DBSIndexType.UNKNOWN;
            break;
    }
    if (CommonUtils.isEmpty(indexName)) {
        // [JDBC] Some drivers return empty index names
        indexName = parent.getName().toUpperCase(Locale.ENGLISH) + "_INDEX";
    }
    return owner.getDataSource().getMetaModel().createIndexImpl(parent, isNonUnique, indexQualifier, cardinality, indexName, indexType, true);
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) Nullable(org.jkiss.code.Nullable)

Example 2 with DBSIndexType

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

the class EditIndexPage method createContentsBeforeColumns.

@Override
protected void createContentsBeforeColumns(Composite panel) {
    UIUtils.createControlLabel(panel, EditorsMessages.dialog_struct_edit_index_label_type);
    final Combo typeCombo = new Combo(panel, SWT.DROP_DOWN | SWT.READ_ONLY);
    typeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    for (DBSIndexType indexType : indexTypes) {
        typeCombo.add(indexType.getName());
        if (selectedIndexType == null) {
            selectedIndexType = indexType;
        }
    }
    typeCombo.select(0);
    typeCombo.setEnabled(indexTypes.size() > 1);
    typeCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedIndexType = indexTypes.get(typeCombo.getSelectionIndex());
        }
    });
    if (supportUniqueIndexes) {
        final Button uniqueButton = UIUtils.createLabelCheckbox(panel, "Unique", false);
        uniqueButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                unique = uniqueButton.getSelection();
            }
        });
    }
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CCombo(org.eclipse.swt.custom.CCombo)

Example 3 with DBSIndexType

use of org.jkiss.dbeaver.model.struct.rdb.DBSIndexType 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 4 with DBSIndexType

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

the class SQLServerIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
    SQLServerTableIndex index = command.getObject();
    SQLServerTableBase indexTable = index.getTable();
    if (indexTable instanceof SQLServerTableType) {
        return;
    }
    if (index.isPersisted()) {
        try {
            String indexDDL = index.getObjectDefinitionText(monitor, DBPScriptObject.EMPTY_OPTIONS);
            if (!CommonUtils.isEmpty(indexDDL)) {
                actions.add(new SQLDatabasePersistAction(ModelMessages.model_jdbc_create_new_index, indexDDL));
                return;
            }
        } catch (DBException e) {
            log.warn("Can't extract index DDL", e);
        }
    }
    DBSIndexType indexType = index.getIndexType();
    String sqlServerIndexType = null;
    if (indexType == DBSIndexType.CLUSTERED) {
        sqlServerIndexType = "CLUSTERED";
    } else if (indexType == SQLServerConstants.INDEX_TYPE_NON_CLUSTERED) {
        sqlServerIndexType = "NONCLUSTERED";
    }
    StringBuilder ddl = new StringBuilder();
    ddl.append("CREATE ");
    if (index.isUnique()) {
        ddl.append("UNIQUE ");
    }
    if (sqlServerIndexType != null) {
        ddl.append(sqlServerIndexType).append(" ");
    }
    ddl.append("INDEX ").append(index.getName()).append(" ON ").append(indexTable.getFullyQualifiedName(DBPEvaluationContext.DDL)).append(" (");
    List<SQLServerTableIndexColumn> indexColumns = index.getAttributeReferences(monitor);
    if (indexColumns != null) {
        for (int i = 0; i < indexColumns.size(); i++) {
            if (i == 0) {
                ddl.append(DBUtils.getQuotedIdentifier(indexColumns.get(i)));
            } else {
                ddl.append(", ").append(DBUtils.getQuotedIdentifier(indexColumns.get(i)));
            }
        }
    } else {
        super.addObjectCreateActions(monitor, executionContext, actions, command, options);
        return;
    }
    ddl.append(")");
    actions.add(new SQLDatabasePersistAction("Create new SQL Server index", ddl.toString()));
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 5 with DBSIndexType

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

the class IndexCache method fetchObject.

@Nullable
@Override
protected GenericTableIndex fetchObject(JDBCSession session, GenericStructContainer owner, GenericTable parent, String indexName, JDBCResultSet dbResult) throws SQLException, DBException {
    boolean isNonUnique = GenericUtils.safeGetBoolean(indexObject, dbResult, JDBCConstants.NON_UNIQUE);
    String indexQualifier = GenericUtils.safeGetStringTrimmed(indexObject, dbResult, JDBCConstants.INDEX_QUALIFIER);
    long cardinality = GenericUtils.safeGetLong(indexObject, dbResult, JDBCConstants.INDEX_CARDINALITY);
    int indexTypeNum = GenericUtils.safeGetInt(indexObject, dbResult, JDBCConstants.TYPE);
    DBSIndexType indexType;
    switch(indexTypeNum) {
        case DatabaseMetaData.tableIndexStatistic:
            // Table index statistic. Not a real index.
            log.debug("Skip statistics index '" + indexName + "' in '" + DBUtils.getObjectFullName(parent, DBPEvaluationContext.DDL) + "'");
            return null;
        // indexType = DBSIndexType.STATISTIC; break;
        case DatabaseMetaData.tableIndexClustered:
            indexType = DBSIndexType.CLUSTERED;
            break;
        case DatabaseMetaData.tableIndexHashed:
            indexType = DBSIndexType.HASHED;
            break;
        case DatabaseMetaData.tableIndexOther:
            indexType = DBSIndexType.OTHER;
            break;
        default:
            indexType = DBSIndexType.UNKNOWN;
            break;
    }
    if (CommonUtils.isEmpty(indexName)) {
        // [JDBC] Some drivers return empty index names
        indexName = parent.getName().toUpperCase(Locale.ENGLISH) + "_INDEX";
    }
    return owner.getDataSource().getMetaModel().createIndexImpl(parent, isNonUnique, indexQualifier, cardinality, indexName, indexType, true);
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) Nullable(org.jkiss.code.Nullable)

Aggregations

DBSIndexType (org.jkiss.dbeaver.model.struct.rdb.DBSIndexType)10 Nullable (org.jkiss.code.Nullable)3 CCombo (org.eclipse.swt.custom.CCombo)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GenericTableIndexColumn (org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn)2 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)2 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)2 EditIndexPage (org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)2 ArrayList (java.util.ArrayList)1 DBException (org.jkiss.dbeaver.DBException)1 ExasolTableColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn)1 ExasolTableIndexColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableIndexColumn)1 GenericTableBase (org.jkiss.dbeaver.ext.generic.model.GenericTableBase)1 GenericTableIndex (org.jkiss.dbeaver.ext.generic.model.GenericTableIndex)1 HiveIndex (org.jkiss.dbeaver.ext.hive.model.HiveIndex)1