use of org.janusgraph.graphdb.relations.StandardEdge in project janusgraph by JanusGraph.
the class StandardJanusGraphTx method addEdge.
public JanusGraphEdge addEdge(JanusGraphVertex outVertex, JanusGraphVertex inVertex, EdgeLabel label) {
verifyWriteAccess(outVertex, inVertex);
outVertex = ((InternalVertex) outVertex).it();
inVertex = ((InternalVertex) inVertex).it();
Preconditions.checkNotNull(label);
Multiplicity multiplicity = label.multiplicity();
TransactionLock uniqueLock = getUniquenessLock(outVertex, (InternalRelationType) label, inVertex);
uniqueLock.lock(LOCK_TIMEOUT);
try {
// Check uniqueness
if (config.hasVerifyUniqueness()) {
if (multiplicity == Multiplicity.SIMPLE) {
if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).adjacent(inVertex).edges()))
throw new SchemaViolationException("An edge with the given label already exists between the pair of vertices and the label [%s] is simple", label.name());
}
if (multiplicity.isUnique(Direction.OUT)) {
if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).edges()))
throw new SchemaViolationException("An edge with the given label already exists on the out-vertex and the label [%s] is out-unique", label.name());
}
if (multiplicity.isUnique(Direction.IN)) {
if (!Iterables.isEmpty(query(inVertex).type(label).direction(Direction.IN).edges()))
throw new SchemaViolationException("An edge with the given label already exists on the in-vertex and the label [%s] is in-unique", label.name());
}
}
StandardEdge edge = new StandardEdge(IDManager.getTemporaryRelationID(temporaryIds.nextID()), label, (InternalVertex) outVertex, (InternalVertex) inVertex, ElementLifeCycle.New);
if (config.hasAssignIDsImmediately())
graph.assignID(edge);
connectRelation(edge);
return edge;
} finally {
uniqueLock.unlock();
}
}
use of org.janusgraph.graphdb.relations.StandardEdge in project janusgraph by JanusGraph.
the class StandardJanusGraphTx method addEdge.
public JanusGraphEdge addEdge(Long id, JanusGraphVertex outVertex, JanusGraphVertex inVertex, EdgeLabel label) {
verifyWriteAccess(outVertex, inVertex);
outVertex = ((InternalVertex) outVertex).it();
inVertex = ((InternalVertex) inVertex).it();
Preconditions.checkNotNull(label);
checkConnectionConstraintOrCreateConnectionConstraint(outVertex, inVertex, label);
Multiplicity multiplicity = label.multiplicity();
TransactionLock uniqueLock = getUniquenessLock(outVertex, (InternalRelationType) label, inVertex);
uniqueLock.lock(LOCK_TIMEOUT);
try {
// Check uniqueness
if (config.hasVerifyUniqueness()) {
if (multiplicity == Multiplicity.SIMPLE) {
if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).adjacent(inVertex).edges()))
throw new SchemaViolationException("An edge with the given label already exists between the pair of vertices and the label [%s] is simple", label.name());
}
if (multiplicity.isUnique(Direction.OUT)) {
if (!Iterables.isEmpty(query(outVertex).type(label).direction(Direction.OUT).edges()))
throw new SchemaViolationException("An edge with the given label already exists on the out-vertex and the label [%s] is out-unique", label.name());
}
if (multiplicity.isUnique(Direction.IN)) {
if (!Iterables.isEmpty(query(inVertex).type(label).direction(Direction.IN).edges()))
throw new SchemaViolationException("An edge with the given label already exists on the in-vertex and the label [%s] is in-unique", label.name());
}
}
long edgeId = id == null ? IDManager.getTemporaryRelationID(temporaryIds.nextID()) : id;
StandardEdge edge = new StandardEdge(edgeId, label, (InternalVertex) outVertex, (InternalVertex) inVertex, ElementLifeCycle.New);
if (config.hasAssignIDsImmediately() && id == null)
graph.assignID(edge);
connectRelation(edge);
return edge;
} finally {
uniqueLock.unlock();
}
}
use of org.janusgraph.graphdb.relations.StandardEdge in project janusgraph by JanusGraph.
the class ModificationDeserializer method parseRelation.
public static InternalRelation parseRelation(TransactionLogHeader.Modification modification, StandardJanusGraphTx tx) {
Change state = modification.state;
assert state.isProper();
long outVertexId = modification.outVertexId;
Entry relEntry = modification.relationEntry;
InternalVertex outVertex = tx.getInternalVertex(outVertexId);
// Special relation parsing, compare to {@link RelationConstructor}
RelationCache relCache = tx.getEdgeSerializer().readRelation(relEntry, false, tx);
assert relCache.direction == Direction.OUT;
InternalRelationType type = (InternalRelationType) tx.getExistingRelationType(relCache.typeId);
assert type.getBaseType() == null;
InternalRelation rel;
if (type.isPropertyKey()) {
if (state == Change.REMOVED) {
rel = new StandardVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), ElementLifeCycle.Removed);
} else {
rel = new CacheVertexProperty(relCache.relationId, (PropertyKey) type, outVertex, relCache.getValue(), relEntry);
}
} else {
assert type.isEdgeLabel();
InternalVertex otherVertex = tx.getInternalVertex(relCache.getOtherVertexId());
if (state == Change.REMOVED) {
rel = new StandardEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, ElementLifeCycle.Removed);
} else {
rel = new CacheEdge(relCache.relationId, (EdgeLabel) type, outVertex, otherVertex, relEntry);
}
}
if (state == Change.REMOVED && relCache.hasProperties()) {
// copy over properties
for (LongObjectCursor<Object> entry : relCache) {
rel.setPropertyDirect(tx.getExistingPropertyKey(entry.key), entry.value);
}
}
return rel;
}
Aggregations