Search in sources :

Example 1 with MutableMetaDocPart

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;
}
Also used : MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart)

Example 2 with MutableMetaDocPart

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);
    }
}
Also used : MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) MutableMetaIndex(com.torodb.core.transaction.metainf.MutableMetaIndex) IdentifierFactory(com.torodb.core.d2r.IdentifierFactory)

Example 3 with MutableMetaDocPart

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());
                    }
                }
            }
        }
    }
}
Also used : MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) TableRef(com.torodb.core.TableRef)

Example 4 with MutableMetaDocPart

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;
}
Also used : MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart)

Example 5 with MutableMetaDocPart

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);
                }
            }
        }
    }
}
Also used : MutableMetaDocPart(com.torodb.core.transaction.metainf.MutableMetaDocPart) ArrayList(java.util.ArrayList) List(java.util.List) TableRef(com.torodb.core.TableRef)

Aggregations

MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)7 TableRef (com.torodb.core.TableRef)2 IdentifierFactory (com.torodb.core.d2r.IdentifierFactory)1 ImmutableMetaCollection (com.torodb.core.transaction.metainf.ImmutableMetaCollection)1 ImmutableMetaSnapshot (com.torodb.core.transaction.metainf.ImmutableMetaSnapshot)1 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)1 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)1 MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)1 MutableMetaIndex (com.torodb.core.transaction.metainf.MutableMetaIndex)1 MutableMetaSnapshot (com.torodb.core.transaction.metainf.MutableMetaSnapshot)1 WrapperMutableMetaSnapshot (com.torodb.core.transaction.metainf.WrapperMutableMetaSnapshot)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Tuple2 (org.jooq.lambda.tuple.Tuple2)1 Test (org.junit.Test)1