Exemplo n.º 1
0
  public TitanProperty setProperty(TitanVertex vertex, final TitanKey key, Object value) {
    Preconditions.checkNotNull(key);
    Preconditions.checkArgument(
        key.isUnique(Direction.OUT), "Not an out-unique key: %s", key.getName());

    Lock uniqueLock = FakeLock.INSTANCE;
    try {
      if (config.hasVerifyUniqueness()) {
        // Acquire uniqueness lock, remove and add
        uniqueLock = getUniquenessLock(vertex, key, value);
        uniqueLock.lock();
        vertex.removeProperty(key);
      } else {
        // Only delete in-memory
        InternalVertex v = (InternalVertex) vertex;
        for (InternalRelation r :
            v.it()
                .getAddedRelations(
                    new Predicate<InternalRelation>() {
                      @Override
                      public boolean apply(@Nullable InternalRelation p) {
                        return p.getType().equals(key);
                      }
                    })) {
          r.remove();
        }
      }
      return addPropertyInternal(vertex, key, value);
    } finally {
      uniqueLock.unlock();
    }
  }
Exemplo n.º 2
0
  @Override
  public long[] indexRetrieval(Object key, TitanKey pt, InternalTitanTransaction tx) {
    Preconditions.checkArgument(
        pt.isSimple(), "Currently, only simple properties are supported for index retrieval");
    Preconditions.checkArgument(
        pt.hasIndex(), "Cannot retrieve for given property key - it does not have an index");

    long[] vertices = null;

    Preconditions.checkArgument(
        pt.getDataType().isInstance(key),
        "Specified object is incompatible with property data type [" + pt.getName() + "]");

    for (int readAttempt = 0; readAttempt < maxReadRetryAttempts; readAttempt++) {
      try {
        if (pt.isUnique()) {
          ByteBuffer value =
              propertyIndex.get(getIndexKey(key), getKeyedIndexColumn(pt), tx.getTxHandle());
          if (value != null) {
            vertices = new long[1];
            vertices[0] = VariableLong.readPositive(value);
          }
        } else {
          ByteBuffer startColumn = VariableLong.positiveByteBuffer(pt.getID());
          List<Entry> entries =
              propertyIndex.getSlice(
                  getIndexKey(key),
                  startColumn,
                  ByteBufferUtil.nextBiggerBuffer(startColumn),
                  tx.getTxHandle());
          vertices = new long[entries.size()];
          int i = 0;
          for (Entry ent : entries) {
            vertices[i++] = VariableLong.readPositive(ent.getValue());
          }
        }

        break;
      } catch (StorageException e) {
        if (e instanceof TemporaryStorageException) {
          if (readAttempt < maxReadRetryAttempts - 1) temporaryStorageException(e);
          else throw readException(e, maxReadRetryAttempts);
        } else throw readException(e);
      }
    }

    if (vertices == null) return new long[0];
    else return vertices;
  }
Exemplo n.º 3
0
 @Override
 public TitanVertex getVertex(TitanKey key, Object attribute) {
   Preconditions.checkArgument(
       key.isUnique(Direction.IN), "Key is not uniquely associated to value [%s]", key.getName());
   return Iterables.getOnlyElement(getVertices(key, attribute), null);
 }