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);
}
}
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());
}
Aggregations