use of com.torodb.core.transaction.metainf.MutableMetaDocPart in project torodb by torodb.
the class BatchMetaCollection method addMetaDocPart.
@Override
public BatchMetaDocPart addMetaDocPart(TableRef tableRef, String identifier) throws IllegalArgumentException {
MutableMetaDocPart delegateDocPart = delegate.addMetaDocPart(tableRef, identifier);
BatchMetaDocPart myDocPart = new BatchMetaDocPart(delegateDocPart, this::onDocPartChange, true);
docPartsByRef.put(myDocPart.getTableRef(), myDocPart);
changesOnBatch.add(myDocPart);
modifiedDocParts.add(myDocPart);
return myDocPart;
}
use of com.torodb.core.transaction.metainf.MutableMetaDocPart in project torodb by torodb.
the class ExclusiveWriteBackendTransactionImpl method copyMetaCollection.
private void copyMetaCollection(MetaDatabase fromDb, MetaCollection fromColl, MutableMetaDatabase toDb, MutableMetaCollection toColl) {
IdentifierFactory identifierFactory = getIdentifierFactory();
Iterator<? extends MetaIndex> fromMetaIndexIterator = fromColl.streamContainedMetaIndexes().iterator();
while (fromMetaIndexIterator.hasNext()) {
MetaIndex fromMetaIndex = fromMetaIndexIterator.next();
MutableMetaIndex toMetaIndex = toColl.addMetaIndex(fromMetaIndex.getName(), fromMetaIndex.isUnique());
getSqlInterface().getMetaDataWriteInterface().addMetaIndex(getDsl(), toDb, toColl, toMetaIndex);
copyIndexFields(fromMetaIndex, toDb, toColl, toMetaIndex);
}
Iterator<? extends MetaDocPart> fromMetaDocPartIterator = fromColl.streamContainedMetaDocParts().iterator();
while (fromMetaDocPartIterator.hasNext()) {
MetaDocPart fromMetaDocPart = fromMetaDocPartIterator.next();
MutableMetaDocPart toMetaDocPart = toColl.addMetaDocPart(fromMetaDocPart.getTableRef(), identifierFactory.toDocPartIdentifier(toDb, toColl.getName(), fromMetaDocPart.getTableRef()));
getSqlInterface().getMetaDataWriteInterface().addMetaDocPart(getDsl(), toDb, toColl, toMetaDocPart);
copyScalar(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
copyFields(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
copyIndexes(identifierFactory, fromMetaDocPart, toDb, toColl, toMetaDocPart);
int nextRid = ridGenerator.getDocPartRidGenerator(fromDb.getName(), fromColl.getName()).nextRid(fromMetaDocPart.getTableRef());
ridGenerator.getDocPartRidGenerator(toDb.getName(), toColl.getName()).setNextRid(toMetaDocPart.getTableRef(), nextRid - 1);
}
}
use of com.torodb.core.transaction.metainf.MutableMetaDocPart in project torodb by torodb.
the class SharedWriteBackendTransactionImpl method dropIndex.
@Override
public void dropIndex(MetaDatabase db, MutableMetaCollection col, MetaIndex index) {
Preconditions.checkState(!isClosed(), "This transaction is closed");
getSqlInterface().getMetaDataWriteInterface().deleteMetaIndex(getDsl(), db, col, index);
Iterator<TableRef> tableRefIterator = index.streamTableRefs().iterator();
while (tableRefIterator.hasNext()) {
TableRef tableRef = tableRefIterator.next();
MutableMetaDocPart docPart = col.getMetaDocPartByTableRef(tableRef);
if (docPart != null) {
Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexesIterator = docPart.streamIndexes().iterator();
while (docPartIndexesIterator.hasNext()) {
MetaIdentifiedDocPartIndex docPartIndex = docPartIndexesIterator.next();
if (index.isCompatible(docPart, docPartIndex)) {
boolean existsAnyOtherCompatibleIndex = col.streamContainedMetaIndexes().anyMatch(otherIndex -> otherIndex != index && otherIndex.isCompatible(docPart, docPartIndex));
if (!existsAnyOtherCompatibleIndex) {
dropIndex(db, col, docPart, docPartIndex);
LOGGER.info("Dropped index {} for table {}", docPartIndex.getIdentifier(), docPart.getIdentifier());
}
}
}
}
}
}
use of com.torodb.core.transaction.metainf.MutableMetaDocPart in project torodb by torodb.
the class CollectionMetaInfo method findMetaDocPart.
public MutableMetaDocPart findMetaDocPart(TableRef tableRef) {
MutableMetaDocPart metaDocPart = metaCollection.getMetaDocPartByTableRef(tableRef);
if (metaDocPart == null) {
String docPartIdentifier = identifierFactory.toDocPartIdentifier(metaDatabase, metaCollection.getName(), tableRef);
metaDocPart = metaCollection.addMetaDocPart(tableRef, docPartIdentifier);
}
return metaDocPart;
}
use of com.torodb.core.transaction.metainf.MutableMetaDocPart in project torodb by torodb.
the class SharedWriteBackendTransactionImpl method createMissingDocPartIndexes.
private void createMissingDocPartIndexes(MetaDatabase db, MutableMetaCollection col, MetaIndex index) throws UserException {
Iterator<TableRef> tableRefIterator = index.streamTableRefs().iterator();
while (tableRefIterator.hasNext()) {
TableRef tableRef = tableRefIterator.next();
MutableMetaDocPart docPart = col.getMetaDocPartByTableRef(tableRef);
if (docPart != null && index.isCompatible(docPart)) {
Iterator<List<String>> docPartIndexesFieldsIterator = index.iteratorMetaDocPartIndexesIdentifiers(docPart);
while (docPartIndexesFieldsIterator.hasNext()) {
List<String> identifiers = docPartIndexesFieldsIterator.next();
boolean containsExactDocPartIndex = docPart.streamIndexes().anyMatch(docPartIndex -> index.isMatch(docPart, identifiers, docPartIndex));
if (!containsExactDocPartIndex) {
createIndex(db, col, index, docPart, identifiers);
}
}
}
}
}
Aggregations