Search in sources :

Example 31 with TableRef

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

the class SqlTorodTransaction method findByAttRefInProjection.

@Override
public Cursor<Tuple2<Integer, KvValue<?>>> findByAttRefInProjection(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 EmptyCursor<>();
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        LOGGER.trace("Collection " + dbName + '.' + colName + " does not exist. An empty cursor is returned");
        return new EmptyCursor<>();
    }
    if (values.isEmpty()) {
        LOGGER.trace("An empty list of values have been given as in condition. An empty cursor is returned");
        return new EmptyCursor<>();
    }
    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 EmptyCursor<>();
    }
    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 getInternalTransaction().getBackendTransaction().findByFieldInProjection(db, col, docPart, valuesMap);
}
Also used : 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) EmptyCursor(com.torodb.core.cursors.EmptyCursor) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Example 32 with TableRef

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

the class SqlWriteTorodTransaction method deleteByAttRef.

@Override
public long deleteByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
    MetaDatabase db = getInternalTransaction().getMetaSnapshot().getMetaDatabaseByName(dbName);
    if (db == null) {
        return 0;
    }
    MetaCollection col = db.getMetaCollectionByName(colName);
    if (col == null) {
        return 0;
    }
    TableRef tableRef = extractTableRef(attRef);
    String lastKey = extractKeyName(attRef.getKeys().get(attRef.getKeys().size() - 1));
    MetaDocPart docPart = col.getMetaDocPartByTableRef(tableRef);
    if (docPart == null) {
        return 0;
    }
    MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
    if (field == null) {
        return 0;
    }
    Collection<Integer> dids = getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value).asDidCursor().getRemaining();
    getInternalTransaction().getBackendTransaction().deleteDids(db, col, dids);
    return dids.size();
}
Also used : MutableMetaDatabase(com.torodb.core.transaction.metainf.MutableMetaDatabase) MetaDatabase(com.torodb.core.transaction.metainf.MetaDatabase) MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) MetaField(com.torodb.core.transaction.metainf.MetaField) MutableMetaCollection(com.torodb.core.transaction.metainf.MutableMetaCollection) MetaCollection(com.torodb.core.transaction.metainf.MetaCollection) 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