Search in sources :

Example 11 with DBSIndexType

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

the class GenericTableIndexConfigurator method configureObject.

@Override
public GenericTableIndex configureObject(DBRProgressMonitor monitor, Object table, GenericTableIndex index) {
    GenericTableBase tableBase = (GenericTableBase) table;
    boolean supportUniqueIndexes = tableBase.supportUniqueIndexes();
    Collection<DBSIndexType> tableIndexTypes = tableBase.getTableIndexTypes();
    return new UITask<GenericTableIndex>() {

        @Override
        protected GenericTableIndex runTask() {
            EditIndexPage editPage = new EditIndexPage("Create index", index, tableIndexTypes, supportUniqueIndexes);
            if (!editPage.edit()) {
                return null;
            }
            index.setIndexType(editPage.getIndexType());
            StringBuilder idxName = new StringBuilder(64);
            idxName.append(CommonUtils.escapeIdentifier(index.getTable().getName()));
            int colIndex = 1;
            for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
                if (colIndex == 1) {
                    idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName()));
                }
                index.addColumn(new GenericTableIndexColumn(index, (GenericTableColumn) tableColumn, colIndex++, !Boolean.TRUE.equals(editPage.getAttributeProperty(tableColumn, EditIndexPage.PROP_DESC))));
            }
            idxName.append("_IDX");
            index.setName(DBObjectNameCaseTransformer.transformObjectName(index, idxName.toString()));
            index.setUnique(editPage.isUnique());
            return index;
        }
    }.execute();
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) GenericTableIndexColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn) GenericTableBase(org.jkiss.dbeaver.ext.generic.model.GenericTableBase) GenericTableIndex(org.jkiss.dbeaver.ext.generic.model.GenericTableIndex) EditIndexPage(org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)

Example 12 with DBSIndexType

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

the class HiveTable method getTableIndexTypes.

public Collection<DBSIndexType> getTableIndexTypes() {
    List<DBSIndexType> indexTypes = new ArrayList<>();
    indexTypes.add(new DBSIndexType("COMPACT", "Compact"));
    indexTypes.add(new DBSIndexType("BITMAP", "Bitmap"));
    return indexTypes;
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) ArrayList(java.util.ArrayList)

Example 13 with DBSIndexType

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

the class HiveIndexManager method addObjectCreateActions.

@Override
protected void addObjectCreateActions(DBRProgressMonitor monitor, DBCExecutionContext executionContext, List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
    HiveIndex tableIndex = (HiveIndex) command.getObject();
    DBSIndexType indexType = tableIndex.getIndexType();
    String indexName = tableIndex.getName();
    String tableName = tableIndex.getTable().getName();
    String hiveIndexType;
    List<GenericTableIndexColumn> indexColumns = tableIndex.getAttributeReferences(monitor);
    if (indexType.getId().equals("COMPACT")) {
        hiveIndexType = "\'COMPACT\'";
    } else {
        hiveIndexType = "\'BITMAP\'";
    }
    StringBuilder ddl = new StringBuilder();
    ddl.append("CREATE INDEX ").append(indexName).append(" ON TABLE ").append(tableName).append(" (");
    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)));
            }
        }
    }
    ddl.append(") AS ").append(hiveIndexType).append(" WITH DEFERRED REBUILD");
    actions.add(new SQLDatabasePersistAction("Create table index", ddl.toString()));
    actions.add(new SQLDatabasePersistAction("ALTER INDEX " + indexName + " ON " + tableName + " REBUILD"));
}
Also used : DBSIndexType(org.jkiss.dbeaver.model.struct.rdb.DBSIndexType) HiveIndex(org.jkiss.dbeaver.ext.hive.model.HiveIndex) GenericTableIndexColumn(org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn) SQLDatabasePersistAction(org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)

Example 14 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, GenericTableBase 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 15 with DBSIndexType

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

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)

Aggregations

DBSIndexType (org.jkiss.dbeaver.model.struct.rdb.DBSIndexType)16 Nullable (org.jkiss.code.Nullable)4 GenericTableIndexColumn (org.jkiss.dbeaver.ext.generic.model.GenericTableIndexColumn)4 SQLDatabasePersistAction (org.jkiss.dbeaver.model.impl.edit.SQLDatabasePersistAction)4 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)4 EditIndexPage (org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage)4 ArrayList (java.util.ArrayList)2 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 DBException (org.jkiss.dbeaver.DBException)2 ExasolTableColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableColumn)2 ExasolTableIndexColumn (org.jkiss.dbeaver.ext.exasol.model.ExasolTableIndexColumn)2 GenericTableBase (org.jkiss.dbeaver.ext.generic.model.GenericTableBase)2 GenericTableIndex (org.jkiss.dbeaver.ext.generic.model.GenericTableIndex)2 HiveIndex (org.jkiss.dbeaver.ext.hive.model.HiveIndex)2