Search in sources :

Example 6 with SchemaElement

use of com.baidu.hugegraph.schema.SchemaElement in project incubator-hugegraph by apache.

the class CachedSchemaTransaction method getSchema.

@Override
@SuppressWarnings("unchecked")
protected <T extends SchemaElement> T getSchema(HugeType type, String name) {
    Id prefixedName = generateId(type, name);
    Object value = this.nameCache.get(prefixedName);
    if (value == null) {
        value = super.getSchema(type, name);
        if (value != null) {
            SchemaElement schema = (SchemaElement) value;
            this.updateCache(schema);
        }
    }
    return (T) value;
}
Also used : SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id)

Example 7 with SchemaElement

use of com.baidu.hugegraph.schema.SchemaElement in project incubator-hugegraph by apache.

the class CachedSchemaTransaction method getSchema.

@Override
@SuppressWarnings("unchecked")
protected <T extends SchemaElement> T getSchema(HugeType type, Id id) {
    // try get from optimized array cache
    if (id.number() && id.asLong() > 0L) {
        SchemaElement value = this.arrayCaches.get(type, id);
        if (value != null) {
            return (T) value;
        }
    }
    Id prefixedId = generateId(type, id);
    Object value = this.idCache.get(prefixedId);
    if (value == null) {
        value = super.getSchema(type, id);
        if (value != null) {
            SchemaElement schema = (SchemaElement) value;
            // update id cache, name cache and optimized array cache
            this.updateCache(schema);
        }
    } else {
        // update optimized array cache for the result from id cache
        this.arrayCaches.updateIfNeeded((SchemaElement) value);
    }
    return (T) value;
}
Also used : SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id)

Example 8 with SchemaElement

use of com.baidu.hugegraph.schema.SchemaElement in project incubator-hugegraph by apache.

the class HugeGraph method mapPkId2Name.

default List<String> mapPkId2Name(Collection<Id> ids) {
    List<String> names = new ArrayList<>(ids.size());
    for (Id id : ids) {
        SchemaElement schema = this.propertyKey(id);
        names.add(schema.name());
    }
    return names;
}
Also used : ArrayList(java.util.ArrayList) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id)

Example 9 with SchemaElement

use of com.baidu.hugegraph.schema.SchemaElement in project incubator-hugegraph by apache.

the class HugeGraph method mapVlId2Name.

default List<String> mapVlId2Name(Collection<Id> ids) {
    List<String> names = new ArrayList<>(ids.size());
    for (Id id : ids) {
        SchemaElement schema = this.vertexLabel(id);
        names.add(schema.name());
    }
    return names;
}
Also used : ArrayList(java.util.ArrayList) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id)

Aggregations

SchemaElement (com.baidu.hugegraph.schema.SchemaElement)9 Id (com.baidu.hugegraph.backend.id.Id)7 ArrayList (java.util.ArrayList)4 HugeException (com.baidu.hugegraph.HugeException)1 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)1 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)1