Search in sources :

Example 6 with TableRef

use of com.torodb.core.TableRef in project torodb by torodb.

the class AbstractMetaDataReadInterface method getIndexSize.

@Override
public Long getIndexSize(@Nonnull DSLContext dsl, @Nonnull MetaDatabase database, @Nonnull MetaCollection collection, @Nonnull String indexName) {
    long result = 0;
    MetaIndex index = collection.getMetaIndexByName(indexName);
    Iterator<TableRef> tableRefIterator = index.streamTableRefs().iterator();
    while (tableRefIterator.hasNext()) {
        TableRef tableRef = tableRefIterator.next();
        MetaDocPart docPart = collection.getMetaDocPartByTableRef(tableRef);
        Iterator<? extends MetaIdentifiedDocPartIndex> docPartIndexIterator = docPart.streamIndexes().iterator();
        while (docPartIndexIterator.hasNext()) {
            MetaIdentifiedDocPartIndex docPartIndex = docPartIndexIterator.next();
            if (index.isCompatible(docPart, docPartIndex)) {
                long relatedIndexCount = collection.streamContainedMetaIndexes().filter(i -> i.isCompatible(docPart, docPartIndex)).count();
                String statement = getReadIndexSizeStatement(database.getIdentifier(), docPart.getIdentifier(), docPartIndex.getIdentifier());
                result += sqlHelper.executeStatementWithResult(dsl, statement, Context.FETCH).get(0).into(Long.class) / relatedIndexCount;
            }
        }
    }
    return result;
}
Also used : MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) KvTable(com.torodb.backend.tables.KvTable) Singleton(javax.inject.Singleton) Condition(org.jooq.Condition) MetaDocPartTable(com.torodb.backend.tables.MetaDocPartTable) MetaIndex(com.torodb.core.transaction.metainf.MetaIndex) Inject(javax.inject.Inject) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Context(com.torodb.backend.ErrorHandler.Context) Nonnull(javax.annotation.Nonnull) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) Record(org.jooq.Record) Iterator(java.util.Iterator) KvRecord(com.torodb.backend.tables.records.KvRecord) Collection(java.util.Collection) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) Result(org.jooq.Result) TableRef(com.torodb.core.TableRef) Stream(java.util.stream.Stream) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) MetaInfoKey(com.torodb.core.backend.MetaInfoKey) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) MetaDatabaseRecord(com.torodb.backend.tables.records.MetaDatabaseRecord) MetaIdentifiedDocPartIndex(com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) TableRef(com.torodb.core.TableRef)

Example 7 with TableRef

use of com.torodb.core.TableRef in project torodb by torodb.

the class AbstractMetaDataReadInterface method getForeignInternalFields.

@Override
public Collection<InternalField<?>> getForeignInternalFields(TableRef tableRef) {
    Preconditions.checkArgument(!tableRef.isRoot());
    TableRef parentTableRef = tableRef.getParent().get();
    if (parentTableRef.isRoot()) {
        return metaDocPartTable.FOREIGN_ROOT_FIELDS;
    } else if (parentTableRef.getParent().get().isRoot()) {
        return metaDocPartTable.FOREIGN_FIRST_FIELDS;
    }
    return metaDocPartTable.FOREIGN_FIELDS;
}
Also used : TableRef(com.torodb.core.TableRef)

Example 8 with TableRef

use of com.torodb.core.TableRef in project torodb by torodb.

the class TableRefImplTest method createTableRef.

private TableRef createTableRef(String... names) {
    TableRef tableRef = tableRefFactory.createRoot();
    for (String name : names) {
        try {
            int index = Integer.parseInt(name);
            tableRef = tableRefFactory.createChild(tableRef, index);
        } catch (NumberFormatException ex) {
            tableRef = tableRefFactory.createChild(tableRef, name);
        }
    }
    return tableRef;
}
Also used : TableRef(com.torodb.core.TableRef)

Example 9 with TableRef

use of com.torodb.core.TableRef in project torodb by torodb.

the class TableRefImplTest method rootArrayInArrayInArrayTest.

@Test
public void rootArrayInArrayInArrayTest() throws Exception {
    TableRef tableRef = createTableRef("array", "2", "3");
    Assert.assertEquals("$3", tableRef.getName());
    Assert.assertEquals(3, tableRef.getDepth());
    Assert.assertEquals(3, tableRef.getArrayDimension());
    Assert.assertEquals(false, tableRef.isRoot());
    Assert.assertEquals(true, tableRef.isInArray());
    Assert.assertEquals(true, tableRef.getParent().isPresent());
}
Also used : TableRef(com.torodb.core.TableRef) Test(org.junit.Test)

Example 10 with TableRef

use of com.torodb.core.TableRef in project torodb by torodb.

the class DefaultIdentifierFactory method append.

private void append(NameChain nameChain, TableRef tableRef) {
    if (tableRef.isRoot()) {
        return;
    }
    TableRef parentTableRef = tableRef.getParent().get();
    String name = tableRef.getName();
    if (tableRef.isInArray()) {
        while (parentTableRef.isInArray()) {
            parentTableRef = parentTableRef.getParent().get();
        }
        name = parentTableRef.getName() + arrayDimensionSeparator + tableRef.getArrayDimension();
        parentTableRef = parentTableRef.getParent().get();
    }
    append(nameChain, parentTableRef);
    nameChain.add(name);
}
Also used : TableRef(com.torodb.core.TableRef)

Aggregations

TableRef (com.torodb.core.TableRef)32 Test (org.junit.Test)13 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)6 DocPartResult (com.torodb.core.d2r.DocPartResult)5 ToroDocument (com.torodb.core.document.ToroDocument)5 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)5 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)5 R2DTranslator (com.torodb.core.d2r.R2DTranslator)4 MetaField (com.torodb.core.transaction.metainf.MetaField)4 KvDocument (com.torodb.kvdocument.values.KvDocument)4 KvArray (com.torodb.kvdocument.values.KvArray)3 KvValue (com.torodb.kvdocument.values.KvValue)3 MetaIdentifiedDocPartIndex (com.torodb.core.transaction.metainf.MetaIdentifiedDocPartIndex)2 MutableMetaCollection (com.torodb.core.transaction.metainf.MutableMetaCollection)2 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)2 MutableMetaDocPart (com.torodb.core.transaction.metainf.MutableMetaDocPart)2 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)2 ArrayList (java.util.ArrayList)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1