Search in sources :

Example 1 with MetaIndexField

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

the class SharedWriteBackendTransactionImpl method createIndex.

@Override
public void createIndex(MetaDatabase db, MutableMetaCollection col, MetaIndex index) throws UserException {
    Preconditions.checkState(!isClosed(), "This transaction is closed");
    Preconditions.checkArgument(!index.isUnique() || index.streamTableRefs().count() == 1, "composed unique indexes on fields of different subdocuments are not supported yet");
    getSqlInterface().getMetaDataWriteInterface().addMetaIndex(getDsl(), db, col, index);
    Iterator<? extends MetaIndexField> indexFieldIterator = index.iteratorFields();
    while (indexFieldIterator.hasNext()) {
        MetaIndexField field = indexFieldIterator.next();
        getSqlInterface().getMetaDataWriteInterface().addMetaIndexField(getDsl(), db, col, index, field);
    }
    createMissingDocPartIndexes(db, col, index);
}
Also used : MetaIndexField(com.torodb.core.transaction.metainf.MetaIndexField)

Example 2 with MetaIndexField

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

the class ExclusiveWriteBackendTransactionImpl method copyIndexFields.

private void copyIndexFields(MetaIndex fromMetaIndex, MetaDatabase toMetaDb, MetaCollection toMetaColl, MutableMetaIndex toMetaIndex) {
    Iterator<? extends MetaIndexField> fromMetaIndexFieldIterator = fromMetaIndex.iteratorFields();
    while (fromMetaIndexFieldIterator.hasNext()) {
        MetaIndexField fromMetaIndexField = fromMetaIndexFieldIterator.next();
        MetaIndexField toMetaIndexField = toMetaIndex.addMetaIndexField(fromMetaIndexField.getTableRef(), fromMetaIndexField.getName(), fromMetaIndexField.getOrdering());
        getSqlInterface().getMetaDataWriteInterface().addMetaIndexField(getDsl(), toMetaDb, toMetaColl, toMetaIndex, toMetaIndexField);
    }
}
Also used : MetaIndexField(com.torodb.core.transaction.metainf.MetaIndexField)

Example 3 with MetaIndexField

use of com.torodb.core.transaction.metainf.MetaIndexField 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

MetaIndexField (com.torodb.core.transaction.metainf.MetaIndexField)3 MetaDocPartIndexColumn (com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)1 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)1 MutableMetaDocPartIndex (com.torodb.core.transaction.metainf.MutableMetaDocPartIndex)1 ArrayList (java.util.ArrayList)1 Tuple2 (org.jooq.lambda.tuple.Tuple2)1