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