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