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