use of com.torodb.core.model.DefaultNamedToroIndex in project torodb by torodb.
the class ToroIndexConverter method from.
@Override
public NamedToroIndex from(String databaseObject) {
JsonReader reader = Json.createReader(new StringReader(databaseObject));
JsonObject object = reader.readObject();
IndexedAttributes.Builder builder = new IndexedAttributes.Builder();
JsonArray attsArray = object.getJsonArray(ATTS_KEY);
Set<Integer> descendingAttPos;
if (object.containsKey(DESCENDING)) {
JsonArray descArray = object.getJsonArray(DESCENDING);
descendingAttPos = Sets.newHashSetWithExpectedSize(descArray.size());
for (int i = 0; i < descArray.size(); i++) {
descendingAttPos.add(descArray.getInt(i));
}
} else {
descendingAttPos = Collections.emptySet();
}
for (int i = 0; i < attsArray.size(); i++) {
String att = attsArray.getString(i);
AttributeReference attRef = parseAttRef(att);
if (descendingAttPos.contains(i)) {
builder.addAttribute(attRef, IndexType.desc);
} else {
builder.addAttribute(attRef, IndexType.asc);
}
}
return new DefaultNamedToroIndex(object.getString(NAME_KEY), builder.build(), databaseName, collectionName, object.getBoolean(UNIQUE_KEY, false));
}
Aggregations