Search in sources :

Example 1 with KvValue

use of com.torodb.kvdocument.values.KvValue in project torodb by torodb.

the class BaseArrayToArrayConverter method fromJsonValue.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public KvArray fromJsonValue(JsonArray value) {
    List<KvValue<?>> list = new ArrayList<>(value.size());
    for (JsonValue child : value) {
        ArrayConverter converter = valueToArrayConverterProvider.fromJsonValue(child);
        list.add(converter.fromJsonValue(child));
    }
    return new ListKvArray(list);
}
Also used : ListKvArray(com.torodb.kvdocument.values.heap.ListKvArray) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) KvValue(com.torodb.kvdocument.values.KvValue)

Example 2 with KvValue

use of com.torodb.kvdocument.values.KvValue in project torodb by torodb.

the class BaseArrayValueToJsonConverter method toValue.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public KvArray toValue(JsonArray value) {
    List<KvValue<?>> list = new ArrayList<>(value.size());
    for (JsonValue child : value) {
        ArrayConverter converter = valueToArrayConverterProvider.fromJsonValue(child);
        list.add(converter.fromJsonValue(child));
    }
    return new ListKvArray(list);
}
Also used : ListKvArray(com.torodb.kvdocument.values.heap.ListKvArray) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) ArrayConverter(com.torodb.backend.converters.array.ArrayConverter) KvValue(com.torodb.kvdocument.values.KvValue)

Example 3 with KvValue

use of com.torodb.kvdocument.values.KvValue in project torodb by torodb.

the class R2DTranslatorImpl method translate.

@Override
public List<ToroDocument> translate(Iterator<DocPartResult> docPartResultIt) {
    ImmutableList.Builder<ToroDocument> readedDocuments = ImmutableList.builder();
    Table<TableRef, Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartTable = HashBasedTable.<TableRef, Integer, Map<String, List<KvValue<?>>>>create();
    Table<TableRef, Integer, Map<String, List<KvValue<?>>>> childFieldDocPartTable = HashBasedTable.<TableRef, Integer, Map<String, List<KvValue<?>>>>create();
    int previousDepth = -1;
    while (docPartResultIt.hasNext()) {
        DocPartResult docPartResult = docPartResultIt.next();
        MetaDocPart metaDocPart = docPartResult.getMetaDocPart();
        TableRef tableRef = metaDocPart.getTableRef();
        if (previousDepth != -1 && previousDepth != tableRef.getDepth()) {
            Table<TableRef, Integer, Map<String, List<KvValue<?>>>> previousFieldChildDocPartTable = childFieldDocPartTable;
            childFieldDocPartTable = currentFieldDocPartTable;
            currentFieldDocPartTable = previousFieldChildDocPartTable;
            if (!tableRef.isRoot()) {
                currentFieldDocPartTable.clear();
            }
        }
        previousDepth = tableRef.getDepth();
        Map<Integer, Map<String, List<KvValue<?>>>> childFieldDocPartRow = childFieldDocPartTable.row(tableRef);
        Map<Integer, Map<String, List<KvValue<?>>>> currentFieldDocPartRow;
        if (tableRef.isRoot()) {
            currentFieldDocPartRow = null;
        } else {
            currentFieldDocPartRow = currentFieldDocPartTable.row(tableRef.getParent().get());
        }
        readResult(metaDocPart, tableRef, docPartResult, currentFieldDocPartRow, childFieldDocPartRow, readedDocuments);
    }
    return readedDocuments.build();
}
Also used : MetaDocPart(com.torodb.core.transaction.metainf.MetaDocPart) ImmutableList(com.google.common.collect.ImmutableList) ToroDocument(com.torodb.core.document.ToroDocument) DocPartResult(com.torodb.core.d2r.DocPartResult) HashMap(java.util.HashMap) Map(java.util.Map) TableRef(com.torodb.core.TableRef) KvValue(com.torodb.kvdocument.values.KvValue)

Example 4 with KvValue

use of com.torodb.kvdocument.values.KvValue in project torodb by torodb.

the class DefaultConsistencyHandler method loadConsistent.

private void loadConsistent() {
    try (BackendConnection conn = backendService.openConnection();
        BackendTransaction trans = conn.openReadOnlyTransaction()) {
        Optional<KvValue<?>> valueOpt = trans.readMetaInfo(CONSISTENCY_KEY);
        if (!valueOpt.isPresent()) {
            consistent = false;
            return;
        }
        KvValue<?> value = valueOpt.get();
        if (!value.getType().equals(BooleanType.INSTANCE)) {
            throw new IllegalStateException("Unexpected consistency value " + "found. Expected a boolean but " + valueOpt + " was " + "found");
        }
        consistent = ((KvBoolean) value).getPrimitiveValue();
    }
}
Also used : BackendConnection(com.torodb.core.backend.BackendConnection) BackendTransaction(com.torodb.core.backend.BackendTransaction) WriteBackendTransaction(com.torodb.core.backend.WriteBackendTransaction) KvValue(com.torodb.kvdocument.values.KvValue)

Example 5 with KvValue

use of com.torodb.kvdocument.values.KvValue 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)

Aggregations

KvValue (com.torodb.kvdocument.values.KvValue)9 TableRef (com.torodb.core.TableRef)4 MetaDocPart (com.torodb.core.transaction.metainf.MetaDocPart)4 MetaCollection (com.torodb.core.transaction.metainf.MetaCollection)3 MetaDatabase (com.torodb.core.transaction.metainf.MetaDatabase)3 MetaField (com.torodb.core.transaction.metainf.MetaField)3 ArrayList (java.util.ArrayList)3 EmptyCursor (com.torodb.core.cursors.EmptyCursor)2 DocPartResult (com.torodb.core.d2r.DocPartResult)2 ListKvArray (com.torodb.kvdocument.values.heap.ListKvArray)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Map (java.util.Map)2 JsonValue (javax.json.JsonValue)2 Tuple2 (org.jooq.lambda.tuple.Tuple2)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Multimap (com.google.common.collect.Multimap)1