Search in sources :

Example 6 with MetaDatabase

use of com.torodb.core.transaction.metainf.MetaDatabase in project torodb by torodb.

the class SqlWriteTorodTransaction method delete.

@Override
public void delete(String dbName, String colName, Cursor<Integer> cursor) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return;
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return;
    }
    getInternalTransaction().getBackendTransaction().deleteDids(db, col, cursor.getRemaining());
}
Also used : MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 7 with MetaDatabase

use of com.torodb.core.transaction.metainf.MetaDatabase 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 8 with MetaDatabase

use of com.torodb.core.transaction.metainf.MetaDatabase in project torodb by torodb.

the class SqlTorodTransaction method findByAttRefIn.

@Override
public TorodCursor findByAttRefIn(String dbName, String colName, AttributeReference attRef, Collection<KvValue<?>> values) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        LOGGER.trace("Db with name " + dbName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    if (values.isEmpty()) {
        LOGGER.trace("An empty list of values have been given as in condition. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    TableRef ref = extractTableRef(attRef);
    String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
    MetaDocPart docPart = col.getMetaDocPartByTableRef(ref);
    if (docPart == null) {
        LOGGER.trace("DocPart " + dbName + '.' + colName + '.' + ref + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    Multimap<MetaField, KvValue<?>> valuesMap = ArrayListMultimap.create();
    for (KvValue<?> value : values) {
        MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
        if (field != null) {
            valuesMap.put(field, value);
        }
    }
    return toToroCursor(getInternalTransaction().getBackendTransaction().findByFieldIn(db, col, docPart, valuesMap));
}
Also used : EmptyTorodCursor(com.torodb.torod.cursors.EmptyTorodCursor) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Example 9 with MetaDatabase

use of com.torodb.core.transaction.metainf.MetaDatabase in project torodb by torodb.

the class SqlTorodTransaction method findAll.

@Override
public TorodCursor findAll(String dbName, String colName) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        LOGGER.trace("Db with name " + dbName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    return toToroCursor(getInternalTransaction().getBackendTransaction().findAll(db, col));
}
Also used : EmptyTorodCursor(com.torodb.torod.cursors.EmptyTorodCursor) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Example 10 with MetaDatabase

use of com.torodb.core.transaction.metainf.MetaDatabase in project torodb by torodb.

the class SqlTorodTransaction method fetch.

@Override
public TorodCursor fetch(String dbName, String colName, Cursor<Integer> didCursor) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        LOGGER.trace("Db with name " + dbName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    return toToroCursor(getInternalTransaction().getBackendTransaction().fetch(db, col, didCursor));
}
Also used : EmptyTorodCursor(com.torodb.torod.cursors.EmptyTorodCursor) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection)

Aggregations

MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)16 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)16 TableRef (com.torodb.core.TableRef)6 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)6 MetaField (com.torodb.core.transaction.metainf.MetaField)5 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)4 MutableMetaCollection (com.torodb.core.transaction.metainf.MutableMetaCollection)3 MutableMetaDatabase (com.torodb.core.transaction.metainf.MutableMetaDatabase)3 KvValue (com.torodb.kvdocument.values.KvValue)3 Context (com.torodb.backend.ErrorHandler.Context)2 EmptyCursor (com.torodb.core.cursors.EmptyCursor)2 MetaIndex (com.torodb.core.transaction.metainf.MetaIndex)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Stream (java.util.stream.Stream)2 Nonnull (javax.annotation.Nonnull)2 Singleton (javax.inject.Singleton)2 DSLContext (org.jooq.DSLContext)2 Preconditions (com.google.common.base.Preconditions)1