Search in sources :

Example 6 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeEdge method onUpdateProperty.

@Watched(prefix = "edge")
@Override
protected <V> void onUpdateProperty(Cardinality cardinality, HugeProperty<V> prop) {
    if (prop != null) {
        assert prop instanceof HugeEdgeProperty;
        HugeEdgeProperty<V> edgeProp = (HugeEdgeProperty<V>) prop;
        GraphTransaction tx = this.tx();
        if (tx != null) {
            assert this.fresh();
            tx.addEdgeProperty(edgeProp);
        } else {
            this.graph().addEdgeProperty(edgeProp);
        }
    }
}
Also used : GraphTransaction(com.baidu.hugegraph.backend.tx.GraphTransaction) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 7 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeEdge method ensureFilledProperties.

@Watched(prefix = "edge")
@Override
protected boolean ensureFilledProperties(boolean throwIfNotExist) {
    if (this.isPropLoaded()) {
        this.updateToDefaultValueIfNone();
        return true;
    }
    // Skip query if there is no any property key in schema
    if (this.schemaLabel().properties().isEmpty()) {
        this.propLoaded();
        return true;
    }
    // Seems there is no scene to be here
    Iterator<Edge> edges = this.graph().edges(this.id());
    Edge edge = QueryResults.one(edges);
    if (edge == null && !throwIfNotExist) {
        return false;
    }
    E.checkState(edge != null, "Edge '%s' does not exist", this.id);
    this.copyProperties((HugeEdge) edge);
    this.updateToDefaultValueIfNone();
    return true;
}
Also used : Edge(org.apache.tinkerpop.gremlin.structure.Edge) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 8 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeElement method setProperty.

@Watched(prefix = "element")
public <V> HugeProperty<?> setProperty(HugeProperty<V> prop) {
    if (this.properties == EMPTY_MAP) {
        this.properties = CollectionFactory.newIntObjectMap();
    }
    PropertyKey pkey = prop.propertyKey();
    E.checkArgument(this.properties.containsKey(intFromId(pkey.id())) || this.properties.size() < MAX_PROPERTIES, "Exceeded the maximum number of properties");
    return this.properties.put(intFromId(pkey.id()), prop);
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 9 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeVertex method edges.

@Watched(prefix = "vertex")
@Override
public Iterator<Edge> edges(Direction tinkerpopDir, String... edgeLabels) {
    Directions direction = Directions.convert(tinkerpopDir);
    // NOTE: get edges from memory if load all edges when loading vertex.
    if (this.existsEdges()) {
        return this.getEdges(direction, edgeLabels);
    }
    Id[] edgeLabelIds = this.graph().mapElName2Id(edgeLabels);
    Query query = GraphTransaction.constructEdgesQuery(this.id(), direction, edgeLabelIds);
    return this.graph().edges(query);
}
Also used : Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 10 with Watched

use of com.baidu.hugegraph.perf.PerfUtil.Watched in project incubator-hugegraph by apache.

the class HugeVertex method properties.

@Watched(prefix = "vertex")
// (VertexProperty<V>) prop
@SuppressWarnings("unchecked")
@Override
public <V> Iterator<VertexProperty<V>> properties(String... keys) {
    // TODO: Compatible with TinkerPop properties() (HugeGraph-742)
    this.ensureFilledProperties(true);
    // Capacity should be about the following size
    int propsCapacity = keys.length == 0 ? this.sizeOfProperties() : keys.length;
    List<VertexProperty<V>> props = new ArrayList<>(propsCapacity);
    if (keys.length == 0) {
        for (HugeProperty<?> prop : this.getProperties()) {
            assert prop instanceof VertexProperty;
            props.add((VertexProperty<V>) prop);
        }
    } else {
        for (String key : keys) {
            Id pkeyId;
            try {
                pkeyId = this.graph().propertyKey(key).id();
            } catch (IllegalArgumentException ignored) {
                continue;
            }
            HugeProperty<?> prop = this.getProperty(pkeyId);
            if (prop == null) {
                // Not found
                continue;
            }
            assert prop instanceof VertexProperty;
            props.add((VertexProperty<V>) prop);
        }
    }
    return props.iterator();
}
Also used : ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)65 Id (com.baidu.hugegraph.backend.id.Id)30 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)9 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)8 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)7 ArrayList (java.util.ArrayList)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)5 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)5 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)4 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)4 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)4 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)4 Query (com.baidu.hugegraph.backend.query.Query)4 SchemaJob (com.baidu.hugegraph.job.schema.SchemaJob)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4