Search in sources :

Example 1 with EmptyTorodCursor

use of com.torodb.torod.cursors.EmptyTorodCursor in project torodb by torodb.

the class SqlTorodTransaction method findByAttRef.

@Override
public TorodCursor findByAttRef(String dbName, String colName, AttributeReference attRef, KvValue<?> value) {
    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();
    }
    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();
    }
    MetaField field = docPart.getMetaFieldByNameAndType(lastKey, FieldType.from(value.getType()));
    if (field == null) {
        LOGGER.trace("Field " + dbName + '.' + colName + '.' + ref + '.' + lastKey + " does not exist. An empty cursor is returned");
        return new EmptyTorodCursor();
    }
    return toToroCursor(getInternalTransaction().getBackendTransaction().findByField(db, col, docPart, field, value));
}
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)

Example 2 with EmptyTorodCursor

use of com.torodb.torod.cursors.EmptyTorodCursor 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 3 with EmptyTorodCursor

use of com.torodb.torod.cursors.EmptyTorodCursor 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 4 with EmptyTorodCursor

use of com.torodb.torod.cursors.EmptyTorodCursor 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)4 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)4 EmptyTorodCursor (com.torodb.torod.cursors.EmptyTorodCursor)4 TableRef (com.torodb.core.TableRef)2 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)2 MetaField (com.torodb.core.transaction.metainf.MetaField)2 KvValue (com.torodb.kvdocument.values.KvValue)1