Search in sources :

Example 1 with MetaDocPartIndexColumn

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

the class ExclusiveWriteBackendTransactionImpl method copyMetaIndexColumns.

private List<Tuple2<String, Boolean>> copyMetaIndexColumns(MetaIdentifiedDocPartIndex fromMetaDocPartIndex, MutableMetaDocPartIndex toMetaDocPartIndex) {
    List<Tuple2<String, Boolean>> identifiers = new ArrayList<>();
    Iterator<? extends MetaDocPartIndexColumn> fromMetaDocPartIndexColumnIterator = fromMetaDocPartIndex.iteratorColumns();
    while (fromMetaDocPartIndexColumnIterator.hasNext()) {
        MetaDocPartIndexColumn fromMetaDocPartIndexColumn = fromMetaDocPartIndexColumnIterator.next();
        toMetaDocPartIndex.addMetaDocPartIndexColumn(fromMetaDocPartIndexColumn.getIdentifier(), fromMetaDocPartIndexColumn.getOrdering());
        identifiers.add(new Tuple2<>(fromMetaDocPartIndexColumn.getIdentifier(), fromMetaDocPartIndexColumn.getOrdering().isAscending()));
    }
    return identifiers;
}
Also used : Tuple2(org.jooq.lambda.tuple.Tuple2) ArrayList(java.util.ArrayList) MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)

Example 2 with MetaDocPartIndexColumn

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

the class SharedWriteBackendTransactionImpl method addField.

@Override
public void addField(MetaDatabase db, MetaCollection col, MutableMetaDocPart docPart, MetaField newField) throws UserException {
    Preconditions.checkState(!isClosed(), "This transaction is closed");
    getSqlInterface().getMetaDataWriteInterface().addMetaField(getDsl(), db, col, docPart, newField);
    getSqlInterface().getStructureInterface().addColumnToDocPartTable(getDsl(), db.getIdentifier(), docPart.getIdentifier(), newField.getIdentifier(), getSqlInterface().getDataTypeProvider().getDataType(newField.getType()));
    List<Tuple2<MetaIndex, List<String>>> missingIndexes = col.getMissingIndexesForNewField(docPart, newField);
    for (Tuple2<MetaIndex, List<String>> missingIndexEntry : missingIndexes) {
        MetaIndex missingIndex = missingIndexEntry.v1();
        List<String> identifiers = missingIndexEntry.v2();
        MutableMetaDocPartIndex docPartIndex = docPart.getOrCreatePartialMutableDocPartIndexForMissingIndexAndNewField(missingIndex, identifiers, newField);
        if (missingIndex.isMatch(docPart, identifiers, docPartIndex)) {
            List<Tuple2<String, Boolean>> columnList = new ArrayList<>(docPartIndex.size());
            for (String identifier : identifiers) {
                MetaDocPartIndexColumn docPartIndexColumn = docPartIndex.getMetaDocPartIndexColumnByIdentifier(identifier);
                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, docPartIndex.isUnique());
            LOGGER.info("Created index {} for table {} associated to logical index {}.{}.{}", identifiedDocPartIndex.getIdentifier(), docPart.getIdentifier(), db.getName(), col.getName(), missingIndex.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Tuple2(org.jooq.lambda.tuple.Tuple2) ArrayList(java.util.ArrayList) List(java.util.List) MutableMetaDocPartIndex(com.torodb.core.transaction.metainf.MutableMetaDocPartIndex) MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)

Example 3 with MetaDocPartIndexColumn

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

the class ExclusiveWriteBackendTransactionImpl method writeIndexColumns.

private void writeIndexColumns(MetaDatabase toMetaDb, MetaCollection toMetaColl, MetaDocPart toMetaDocPart, MetaIdentifiedDocPartIndex toMetaDocPartIndex) {
    Iterator<? extends MetaDocPartIndexColumn> toMetaDocPartIndexColumnIterator = toMetaDocPartIndex.iteratorColumns();
    while (toMetaDocPartIndexColumnIterator.hasNext()) {
        MetaDocPartIndexColumn toMetaDocPartIndexColumn = toMetaDocPartIndexColumnIterator.next();
        getSqlInterface().getMetaDataWriteInterface().addMetaDocPartIndexColumn(getDsl(), toMetaDb, toMetaColl, toMetaDocPart, toMetaDocPartIndex, toMetaDocPartIndexColumn);
    }
}
Also used : MetaDocPartIndexColumn(com.torodb.core.transaction.metainf.MetaDocPartIndexColumn)

Example 4 with MetaDocPartIndexColumn

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

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