Search in sources :

Example 1 with DefaultNamedToroIndex

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));
}
Also used : DefaultNamedToroIndex(com.torodb.core.model.DefaultNamedToroIndex) IndexedAttributes(com.torodb.core.model.IndexedAttributes) AttributeReference(com.torodb.core.language.AttributeReference) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) JsonObject(javax.json.JsonObject) JsonArray(javax.json.JsonArray) StringReader(java.io.StringReader) JsonReader(javax.json.JsonReader)

Aggregations

AttributeReference (com.torodb.core.language.AttributeReference)1 DefaultNamedToroIndex (com.torodb.core.model.DefaultNamedToroIndex)1 IndexedAttributes (com.torodb.core.model.IndexedAttributes)1 StringReader (java.io.StringReader)1 JsonArray (javax.json.JsonArray)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObject (javax.json.JsonObject)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 JsonReader (javax.json.JsonReader)1