use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class TableSerializer method writeVertexProperty.
@Override
public BackendEntry writeVertexProperty(HugeVertexProperty<?> prop) {
HugeVertex vertex = prop.element();
TableBackendEntry entry = newBackendEntry(vertex);
if (vertex.hasTtl()) {
entry.ttl(vertex.ttl());
entry.column(HugeKeys.EXPIRED_TIME, vertex.expiredTime());
}
entry.subId(IdGenerator.of(prop.key()));
entry.column(HugeKeys.ID, this.writeId(vertex.id()));
entry.column(HugeKeys.LABEL, vertex.schemaLabel().id().asLong());
this.formatProperty(prop, entry.row());
return entry;
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class BinaryScatterSerializer method readVertex.
@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry bytesEntry) {
if (bytesEntry == null) {
return null;
}
BinaryBackendEntry entry = this.convertEntry(bytesEntry);
// Parse label
final byte[] VL = this.formatSyspropName(entry.id(), HugeKeys.LABEL);
BackendColumn vl = entry.column(VL);
VertexLabel vertexLabel = VertexLabel.NONE;
if (vl != null) {
Id labelId = BytesBuffer.wrap(vl.value).readId();
vertexLabel = graph.vertexLabelOrNone(labelId);
}
// Parse id
Id id = entry.id().origin();
HugeVertex vertex = new HugeVertex(graph, id, vertexLabel);
// Parse all properties and edges of a Vertex
for (BackendColumn col : entry.columns()) {
this.parseColumn(col, vertex);
}
return vertex;
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class GraphTransaction method addVertexProperty.
@Watched(prefix = "graph")
public <V> void addVertexProperty(HugeVertexProperty<V> prop) {
// NOTE: this method can also be used to update property
HugeVertex vertex = prop.element();
E.checkState(vertex != null, "No owner for updating property '%s'", prop.key());
// Add property in memory for new created vertex
if (vertex.fresh()) {
// The owner will do property update
vertex.setProperty(prop);
return;
}
// Check is updating property of added/removed vertex
E.checkArgument(!this.addedVertices.containsKey(vertex.id()) || this.updatedVertices.containsKey(vertex.id()), "Can't update property '%s' for adding-state vertex", prop.key());
E.checkArgument(!vertex.removed() && !this.removedVertices.containsKey(vertex.id()), "Can't update property '%s' for removing-state vertex", prop.key());
// Check is updating primary key
List<Id> primaryKeyIds = vertex.schemaLabel().primaryKeys();
E.checkArgument(!primaryKeyIds.contains(prop.propertyKey().id()), "Can't update primary key: '%s'", prop.key());
// Do property update
this.lockForUpdateProperty(vertex.schemaLabel(), prop, () -> {
// Update old vertex to remove index (without new property)
this.indexTx.updateVertexIndex(vertex, true);
// Update(add) vertex property
this.propertyUpdated(vertex, prop, vertex.setProperty(prop));
});
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class GraphTransaction method prepareAdditions.
protected void prepareAdditions(Map<Id, HugeVertex> addedVertices, Map<Id, HugeEdge> addedEdges) {
if (this.checkCustomVertexExist) {
this.checkVertexExistIfCustomizedId(addedVertices);
}
if (this.removeLeftIndexOnOverwrite) {
this.removeLeftIndexIfNeeded(addedVertices);
}
// Do vertex update
for (HugeVertex v : addedVertices.values()) {
assert !v.removed();
v.committed();
this.checkAggregateProperty(v);
// Check whether passed all non-null properties
if (!this.graphMode().loading()) {
this.checkNonnullProperty(v);
}
// Add vertex entry
this.doInsert(this.serializer.writeVertex(v));
// Update index of vertex(only include props)
this.indexTx.updateVertexIndex(v, false);
this.indexTx.updateLabelIndex(v, false);
}
// Do edge update
for (HugeEdge e : addedEdges.values()) {
assert !e.removed();
e.committed();
// Skip edge if its owner has been removed
if (this.removingEdgeOwner(e)) {
continue;
}
this.checkAggregateProperty(e);
// Add edge entry of OUT and IN
this.doInsert(this.serializer.writeEdge(e));
this.doInsert(this.serializer.writeEdge(e.switchOwner()));
// Update index of edge
this.indexTx.updateEdgeIndex(e, false);
this.indexTx.updateLabelIndex(e, false);
}
}
use of com.baidu.hugegraph.structure.HugeVertex in project incubator-hugegraph by apache.
the class GraphTransaction method queryVerticesByIds.
protected Iterator<Vertex> queryVerticesByIds(Object[] vertexIds, boolean adjacentVertex, boolean checkMustExist) {
Query.checkForceCapacity(vertexIds.length);
// NOTE: allowed duplicated vertices if query by duplicated ids
List<Id> ids = InsertionOrderUtil.newList();
Map<Id, HugeVertex> vertices = new HashMap<>(vertexIds.length);
IdQuery query = new IdQuery(HugeType.VERTEX);
for (Object vertexId : vertexIds) {
HugeVertex vertex;
Id id = HugeVertex.getIdValue(vertexId);
if (id == null || this.removedVertices.containsKey(id)) {
// The record has been deleted
continue;
} else if ((vertex = this.addedVertices.get(id)) != null || (vertex = this.updatedVertices.get(id)) != null) {
if (vertex.expired()) {
continue;
}
// Found from local tx
vertices.put(vertex.id(), vertex);
} else {
// Prepare to query from backend store
query.query(id);
}
ids.add(id);
}
if (!query.empty()) {
// Query from backend store
query.mustSortByInput(false);
Iterator<HugeVertex> it = this.queryVerticesFromBackend(query);
QueryResults.fillMap(it, vertices);
}
return new MapperIterator<>(ids.iterator(), id -> {
HugeVertex vertex = vertices.get(id);
if (vertex == null) {
if (checkMustExist) {
throw new NotFoundException("Vertex '%s' does not exist", id);
} else if (adjacentVertex) {
assert !checkMustExist;
// Return undefined if adjacentVertex but !checkMustExist
vertex = HugeVertex.undefined(this.graph(), id);
} else {
// Return null
assert vertex == null;
}
}
return vertex;
});
}
Aggregations