Package com.tinkerpop.blueprints.impls.orient

Examples of com.tinkerpop.blueprints.impls.orient.OrientVertex


                  toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), toExpr, context, iArgs);

                if (fromIds != null && toIds != null) {
                  // REMOVE ALL THE EDGES BETWEEN VERTICES
                  for (OIdentifiable fromId : fromIds) {
                    final OrientVertex v = graph.getVertex(fromId);
                    if (v != null)
                      for (Edge e : v.getEdges(Direction.OUT)) {
                        final OIdentifiable inV = ((OrientEdge) e).getInVertex();
                        if (inV != null && toIds.contains(inV.getIdentity()))
                          edges.add((OrientEdge) e);
                      }
                  }
                } else if (fromIds != null) {
                  // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
                  for (OIdentifiable fromId : fromIds) {
                    final OrientVertex v = graph.getVertex(fromId);
                    if (v != null)
                      edges.add((OrientEdge) v.getEdges(Direction.OUT));
                  }
                } else if (toIds != null) {
                  // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
                  for (OIdentifiable toId : toIds) {
                    final OrientVertex v = graph.getVertex(toId);
                    if (v != null) {
                      edges.add((OrientEdge) v.getEdges(Direction.IN));
                    }
                  }
                } else
                  throw new OCommandExecutionException("Invalid target: " + toIds);
View Full Code Here


      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    return OGraphCommandExecutorSQLFactory.runInTx(new OGraphCommandExecutorSQLFactory.GraphCallBack<ODocument>() {
      @Override
      public ODocument call(OrientBaseGraph graph) {
        final OrientVertex vertex = graph.addTemporaryVertex(clazz.getName());

        if (fields != null)
          // EVALUATE FIELDS
          for (Entry<String, Object> f : fields.entrySet()) {
            if (f.getValue() instanceof OSQLFunctionRuntime)
              fields.put(f.getKey(), ((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context));
          }

        OSQLHelper.bindParameters(vertex.getRecord(), fields, new OCommandParameters(iArgs), context);

        if (content != null)
          vertex.getRecord().merge(content, true, false);

        if (clusterName != null)
          vertex.save(clusterName);
        else
          vertex.save();

        return vertex.getRecord();
      }
    });
  }
View Full Code Here

    // CREATE EDGES
    final List<ODocument> result = new ArrayList<ODocument>(sourceRIDs.size());

    for (OIdentifiable from : sourceRIDs) {
      final OrientVertex fromVertex = graph.getVertex(from);
      if (fromVertex == null)
        continue;

      final ORID oldVertex = fromVertex.getIdentity().copy();
      final ORID newVertex = fromVertex.moveTo(className, clusterName);

      if (fields != null)
        // EVALUATE FIELDS
        for (Entry<String, Object> f : fields.entrySet()) {
          if (f.getValue() instanceof OSQLFunctionRuntime)
            fields.put(f.getKey(), ((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context));
        }

      OSQLHelper.bindParameters(fromVertex.getRecord(), fields, new OCommandParameters(iArgs), context);

      if (merge != null)
        fromVertex.getRecord().merge(merge, true, false);

      // SAVE CHANGES
      fromVertex.save();

      // PUT THE MOVE INTO THE RESULT
      result.add(new ODocument().field("old", oldVertex, OType.LINK).field("new", newVertex, OType.LINK));
    }
View Full Code Here

    return new OrientVertexFuture(Orient.instance().getWorkers().submit(new Callable<OrientVertex>() {
      @Override
      public OrientVertex call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          OrientVertex v = (OrientVertex) getVertex(id);
          if (v != null) {
            // System.out.printf("\nVertex loaded key=%d, v=%s", id, v);
            for (int retry = 0;; retry++) {
              MERGE_RESULT result = mergeAndSaveRecord(retry, v.getRecord(), prop);
              switch (result) {
              case MERGED:
                return v;
              case ERROR:
                throw new ORecordDuplicatedException("Cannot create a new vertices", v.getIdentity());
              case RETRY:
                if (retry > maxRetries)
                  break;
              }
            }
          }

          v = g.addVertex(id, prop);

          // System.out.printf("\nCreated vertex key=%d, v=%s", id, v);

          verticesCreated.incrementAndGet();

          return v;

        } catch (ORecordDuplicatedException e) {
          System.out.printf("\n*** Vertex already exists key=%d, v=%s", id, e.getRid());

          // ALREADY EXISTS, TRY TO MERGE IT
          for (int retry = 0;; retry++) {
            indexUniqueException.incrementAndGet();

            if (OLogManager.instance().isDebugEnabled())
              OLogManager.instance().debug(this, "Vertex %s already created, merge it and retry again (retry=%d/%d)", id, retry,
                  maxRetries);

            final ODocument existent = e.getRid().getRecord();

            final MERGE_RESULT result = mergeAndSaveRecord(retry, existent, prop);

            switch (result) {
            case MERGED:
              OrientVertex v = (OrientVertex) getVertex(existent);
              return v;
            case RETRY:
              break;
            case ERROR:
              throw e;
View Full Code Here

    return new OrientVertexFuture(Orient.instance().getWorkers().submit(new Callable<OrientVertex>() {
      @Override
      public OrientVertex call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          OrientVertex v = g.addVertex(id, prop);

          verticesCreated.incrementAndGet();

          return v;
View Full Code Here

  }

  public OrientVertex getOrAddVertex(final Object id) {
    final OrientBaseGraph g = acquire();
    try {
      OrientVertex v = getFromCache(id);
      if (v != null)
        return v;

      v = g.addVertex(id);
View Full Code Here

    return new OrientVertexFuture(Orient.instance().getWorkers().submit(new Callable<OrientVertex>() {
      @Override
      public OrientVertex call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          final OrientVertex v = g.addVertex(id);

          verticesCreated.incrementAndGet();

          return v;
        } finally {
View Full Code Here

      return (Vertex) id;

    init();

    if (id instanceof OIdentifiable)
      return new OrientVertex((OrientBaseGraph) null, (OIdentifiable) id);

    OrientVertex v = getFromCache(id);
    if (v != null) {
      return v;
    }

    final OrientBaseGraph g = acquire();
View Full Code Here

      @Override
      public OrientEdge call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          // ASSURE ARE NOT REUSED FROM CACHE
          OrientVertex vOut = outVertex instanceof OrientVertexFuture ? ((OrientVertexFuture) outVertex).get()
              : (OrientVertex) outVertex;
          OrientVertex vIn = inVertex instanceof OrientVertexFuture ? ((OrientVertexFuture) inVertex).get()
              : (OrientVertex) inVertex;

          vOut.attach(g);
          vIn.attach(g);

          boolean reloaded = false;

          for (int retry = 0;; retry++) {
            try {

              final OrientEdge e = g.addEdge(id, vOut, vIn, label);

              addInCache(vOut.getProperty(keyFieldName), vOut);
              addInCache(vIn.getProperty(keyFieldName), vIn);

              edgesCreated.incrementAndGet();

              return e;
View Full Code Here

        final Set<OIdentifiable> toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), to, context, iArgs);

        // CREATE EDGES
        final List<Object> edges = new ArrayList<Object>();
        for (OIdentifiable from : fromIds) {
          final OrientVertex fromVertex = graph.getVertex(from);
          if (fromVertex == null)
            throw new OCommandExecutionException("Source vertex '" + from + "' not exists");

          for (OIdentifiable to : toIds) {
            final OrientVertex toVertex;
            if (from.equals(to)) {
              toVertex = fromVertex;
            } else {
              toVertex = graph.getVertex(to);
            }

            final String clsName = clazz.getName();

            if (fields != null)
              // EVALUATE FIELDS
              for (Entry<String, Object> f : fields.entrySet()) {
                if (f.getValue() instanceof OSQLFunctionRuntime)
                  fields.put(f.getKey(), ((OSQLFunctionRuntime) f.getValue()).getValue(to, null, context));
              }

            OrientEdge edge = null;
            for (int r = 0; r < retry; ++r) {
              try {
                edge = fromVertex.addEdge(null, toVertex, clsName, clusterName, fields);

                if (fields != null && !fields.isEmpty()) {
                  if (!edge.getRecord().getIdentity().isValid())
                    edge.convertToDocument();

                  OSQLHelper.bindParameters(edge.getRecord(), fields, new OCommandParameters(iArgs), context);
                }

                if (content != null) {
                  if (!edge.getRecord().getIdentity().isValid())
                    // LIGHTWEIGHT EDGE, TRANSFORM IT BEFORE
                    edge.convertToDocument();
                  edge.getRecord().merge(content, true, false);
                }

                edge.save(clusterName);

                // OK
                break;

              } catch (OConcurrentModificationException e) {
                if (r + 1 >= retry)
                  // NO RETRY; PROPAGATE THE EXCEPTION
                  throw e;

                // RETRY?
                if (wait > 0)
                  try {
                    Thread.sleep(wait);
                  } catch (InterruptedException e1) {
                  }

                // RELOAD LAST VERSION
                fromVertex.getRecord().reload(null, true);
                toVertex.getRecord().reload(null, true);
              }
            }

            edges.add(edge);
          }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.impls.orient.OrientVertex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.