Search in sources :

Example 6 with MetaIdentifiedDocPartIndex

use of com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex in project torodb by torodb.

the class ExclusiveWriteBackendTransactionImpl method copyIndexes.

private void copyIndexes(IdentifierFactory identifierFactory, MetaDocPart fromMetaDocPart, MetaDatabase toMetaDb, MetaCollection toMetaColl, MutableMetaDocPart toMetaDocPart) {
    Iterator<? extends MetaIdentifiedDocPartIndex> fromMetaDocPartIndexIterator = fromMetaDocPart.streamIndexes().iterator();
    while (fromMetaDocPartIndexIterator.hasNext()) {
        MetaIdentifiedDocPartIndex fromMetaDocPartIndex = fromMetaDocPartIndexIterator.next();
        MutableMetaDocPartIndex toMutableMetaDocPartIndex = toMetaDocPart.addMetaDocPartIndex(fromMetaDocPartIndex.isUnique());
        List<Tuple2<String, Boolean>> identifiers = copyMetaIndexColumns(fromMetaDocPartIndex, toMutableMetaDocPartIndex);
        MetaIdentifiedDocPartIndex toMetaDocPartIndex = toMutableMetaDocPartIndex.immutableCopy(identifierFactory.toIndexIdentifier(toMetaDb, toMetaDocPart.getIdentifier(), identifiers));
        getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndex(getDsl(), toMetaDb, toMetaColl, toMetaDocPart, toMetaDocPartIndex);
        writeIndexColumns(toMetaDb, toMetaColl, toMetaDocPart, toMetaDocPartIndex);
    }
}
Also used : MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Tuple2(org.jooq.lambda.tuple.Tuple2) MutableMetaDocPartIndex(com.torodb.core.transaction.metainf.MutableMetaDocPartIndex)

Example 7 with MetaIdentifiedDocPartIndex

use of com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex in project torodb by torodb.

the class SharedWriteBackendTransactionImpl method createIndex.

private void createIndex(MetaDatabase db, MetaCollection col, MetaIndex index, MutableMetaDocPart docPart, List<String> identifiers) throws UserException {
    MutableMetaDocPartIndex docPartIndex = docPart.addMetaDocPartIndex(index.isUnique());
    Iterator<? extends MetaIndexField> indexFieldIterator = index.iteratorMetaIndexFieldByTableRef(docPart.getTableRef());
    int position = 0;
    List<Tuple2<String, Boolean>> columnList = new ArrayList<>(identifiers.size());
    for (String identifier : identifiers) {
        MetaIndexField indexField = indexFieldIterator.next();
        MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.putMetaDocPartIndexColumn(position++, identifier, indexField.getOrdering());
        columnList.add(new Tuple2<>(docPartIndexColumn.getIdentifier(), docPartIndexColumn.getOrdering().isAscending()));
    }
    MetaIdentifiedDocPartIndex identifiedDocPartIndex = docPartIndex.immutableCopy(identifierFactory.toIndexIdentifier(db, docPart.getIdentifier(), columnList));
    getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndex(getDsl(), db, col, docPart, identifiedDocPartIndex);
    for (String identifier : identifiers) {
        MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.getMetaDocPartIndexColumnByIdentifier(identifier);
        getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndexColumn(getDsl(), db, col, docPart, identifiedDocPartIndex, docPartIndexColumn);
    }
    getSqlInterface().getStructureInterface().createIndex(getDsl(), identifiedDocPartIndex.getIdentifier(), db.getIdentifier(), docPart.getIdentifier(), columnList, index.isUnique());
    LOGGER.info("Created index {} for table {} associated to logical index {}.{}.{}", identifiedDocPartIndex.getIdentifier(), docPart.getIdentifier(), db.getName(), col.getName(), index.getName());
}
Also used : MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Tuple2(org.jooq.lambda.tuple.Tuple2) ArrayList(java.util.ArrayList) MutableMetaDocPartIndex(com.torodb.core.transaction.metainf.MutableMetaDocPartIndex) MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn) MetaIndexField(com.torodb.core.transaction.metainf.MetaIndexField)

Aggregations

MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)7 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)3 MutableMetaDocPartIndex (com.torodb.core.transaction.metainf.MutableMetaDocPartIndex)3 ArrayList (java.util.ArrayList)3 Tuple2 (org.jooq.lambda.tuple.Tuple2)3 TableRef (com.torodb.core.TableRef)2 MetaDocPartIndexColumn (com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)2 MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)2 Preconditions (com.google.common.base.Preconditions)1 Context (com.torodb.backend.ErrorHandler.Context)1 KvTable (com.torodb.backend.tables.KvTable)1 MetaDocPartTable (com.torodb.backend.tables.MetaDocPartTable)1 KvRecord (com.torodb.backend.tables.records.KvRecord)1 MetaDatabaseRecord (com.torodb.backend.tables.records.MetaDatabaseRecord)1 MetaInfoKey (com.torodb.core.backend.MetaInfoKey)1 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)1 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)1 MetaIndexField (com.torodb.core.transaction.metainf.MetaIndexField)1 MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1