private void assignIDs(Collection<InternalRelation> addedEdges, InternalTitanTransaction tx) { for (InternalRelation edge : addedEdges) { if (edge.isRemoved()) continue; if (edge.hasID()) continue; for (int i = 0; i < edge.getArity(); i++) { InternalTitanVertex node = edge.getVertex(i); if (!node.hasID()) { assert node.isNew(); assignID(node); } } assert !edge.hasID(); assignID(edge); } }
@Override public TitanVertex addVertex() { verifyWriteAccess(); StandardVertex vertex = new StandardVertex(this, temporaryID.decrementAndGet(), ElementLifeCycle.New); vertex.addProperty(SystemKey.VertexState, (byte) 0); if (config.hasAssignIDsImmediately()) graph.assignID(vertex); vertexCache.add(vertex, vertex.getID()); return vertex; }
public TitanLabel makeEdgeLabel(EdgeLabelDefinition definition) { verifyOpen(); TitanLabelVertex label = new TitanLabelVertex(this, temporaryID.decrementAndGet(), ElementLifeCycle.New); addProperty(label, SystemKey.TypeName, definition.getName()); addProperty(label, SystemKey.RelationTypeDefinition, definition); addProperty(label, SystemKey.TypeClass, TitanTypeClass.LABEL); graph.assignID(label); vertexCache.add(label, label.getID()); typeCache.put(definition.getName(), label); return label; }
public TitanKey makePropertyKey(PropertyKeyDefinition definition) { verifyOpen(); TitanKeyVertex prop = new TitanKeyVertex(this, temporaryID.decrementAndGet(), ElementLifeCycle.New); addProperty(prop, SystemKey.TypeName, definition.getName()); addProperty(prop, SystemKey.PropertyKeyDefinition, definition); addProperty(prop, SystemKey.TypeClass, TitanTypeClass.KEY); graph.assignID(prop); Preconditions.checkArgument(prop.getID() > 0); vertexCache.add(prop, prop.getID()); typeCache.put(definition.getName(), prop); return prop; }
@Override public TitanEdge addEdge(TitanVertex outVertex, TitanVertex inVertex, TitanLabel label) { verifyWriteAccess(outVertex, inVertex); outVertex = ((InternalVertex) outVertex).it(); inVertex = ((InternalVertex) inVertex).it(); Preconditions.checkNotNull(label); Lock uniqueLock = FakeLock.INSTANCE; if (config.hasVerifyUniqueness() && (label.isUnique(Direction.OUT) || label.isUnique(Direction.IN))) uniqueLock = getUniquenessLock(outVertex, label, inVertex); uniqueLock.lock(); try { // Check uniqueness if (config.hasVerifyUniqueness()) { if (label.isUnique(Direction.OUT)) { Preconditions.checkArgument( Iterables.isEmpty( query(outVertex) .includeHidden() .type(label) .direction(Direction.OUT) .titanEdges()), "An edge with the given type already exists on the out-vertex"); } if (label.isUnique(Direction.IN)) { Preconditions.checkArgument( Iterables.isEmpty( query(inVertex).includeHidden().type(label).direction(Direction.IN).titanEdges()), "An edge with the given type already exists on the in-vertex"); } } StandardEdge edge = new StandardEdge( temporaryID.decrementAndGet(), label, (InternalVertex) outVertex, (InternalVertex) inVertex, ElementLifeCycle.New); if (config.hasAssignIDsImmediately()) graph.assignID(edge); connectRelation(edge); return edge; } finally { uniqueLock.unlock(); } }
public TitanProperty addPropertyInternal(TitanVertex vertex, TitanKey key, Object value) { verifyWriteAccess(vertex); vertex = ((InternalVertex) vertex).it(); Preconditions.checkNotNull(key); value = AttributeUtil.verifyAttribute(key, value); Lock uniqueLock = FakeLock.INSTANCE; if (config.hasVerifyUniqueness() && (key.isUnique(Direction.OUT) || key.isUnique(Direction.IN))) uniqueLock = getUniquenessLock(vertex, key, value); uniqueLock.lock(); try { // Check uniqueness if (config.hasVerifyUniqueness()) { if (key.isUnique(Direction.OUT)) { Preconditions.checkArgument( Iterables.isEmpty( query(vertex).includeHidden().type(key).direction(Direction.OUT).properties()), "An property with the given key already exists on the vertex and the property key is defined as out-unique"); } if (key.isUnique(Direction.IN)) { Preconditions.checkArgument( Iterables.isEmpty(getVertices(key, value)), "The given value is already used as a property and the property key is defined as in-unique"); } } StandardProperty prop = new StandardProperty( temporaryID.decrementAndGet(), key, (InternalVertex) vertex, value, ElementLifeCycle.New); if (config.hasAssignIDsImmediately()) graph.assignID(prop); connectRelation(prop); return prop; } finally { uniqueLock.unlock(); } }