示例#1
0
 @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();
   }
 }
示例#2
0
 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();
   }
 }