Search in sources :

Example 1 with SchemaElement

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

the class HugeGraph method mapElId2Name.

default List<String> mapElId2Name(Collection<Id> ids) {
    List<String> names = new ArrayList<>(ids.size());
    for (Id id : ids) {
        SchemaElement schema = this.edgeLabel(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 2 with SchemaElement

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

the class HugeGraph method mapIlId2Name.

default List<String> mapIlId2Name(Collection<Id> ids) {
    List<String> names = new ArrayList<>(ids.size());
    for (Id id : ids) {
        SchemaElement schema = this.indexLabel(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 3 with SchemaElement

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

the class HugeGraphAuthProxy method verifySchemaPermission.

private <V extends SchemaElement> V verifySchemaPermission(HugePermission actionPerm, boolean throwIfNoPerm, Supplier<V> schemaFetcher) {
    return verifyResPermission(actionPerm, throwIfNoPerm, () -> {
        String graph = this.hugegraph.name();
        SchemaElement elem = schemaFetcher.get();
        @SuppressWarnings("unchecked") ResourceObject<V> r = (ResourceObject<V>) ResourceObject.of(graph, elem);
        return r;
    });
}
Also used : SchemaElement(com.baidu.hugegraph.schema.SchemaElement)

Example 4 with SchemaElement

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

the class JsonSerializer method writeTaskWithSchema.

@Override
public String writeTaskWithSchema(SchemaElement.TaskWithSchema taskWithSchema) {
    StringBuilder builder = new StringBuilder();
    long id = taskWithSchema.task() == null ? 0L : taskWithSchema.task().asLong();
    SchemaElement schemaElement = taskWithSchema.schemaElement();
    String type;
    String schema;
    if (schemaElement instanceof PropertyKey) {
        type = "property_key";
        schema = this.writePropertyKey((PropertyKey) schemaElement);
    } else if (schemaElement instanceof IndexLabel) {
        type = "index_label";
        schema = this.writeIndexlabel((IndexLabel) schemaElement);
    } else {
        throw new HugeException("Invalid schema element '%s' in " + "TaskWithSchema, only support " + "[PropertyKey, IndexLabel]", schemaElement);
    }
    return builder.append("{\"").append(type).append("\": ").append(schema).append(", \"task_id\": ").append(id).append("}").toString();
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) HugeException(com.baidu.hugegraph.HugeException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 5 with SchemaElement

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

the class CachedSchemaTransaction method invalidateCache.

private final void invalidateCache(HugeType type, Id id) {
    // remove from id cache and name cache
    Id prefixedId = generateId(type, id);
    Object value = this.idCache.get(prefixedId);
    if (value != null) {
        this.idCache.invalidate(prefixedId);
        SchemaElement schema = (SchemaElement) value;
        Id prefixedName = generateId(schema.type(), schema.name());
        this.nameCache.invalidate(prefixedName);
    }
    // remove from optimized array cache
    this.arrayCaches.remove(type, id);
}
Also used : 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