Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Element


        @JavaHandler
        public BranchMetadata getBranchByName(String branchName) {
            Iterator<? extends Element> elements = gremlin().out("ownsBranch").has("name", branchName).iterator();

            if (elements.hasNext()) {
                Element element = elements.next();
                assert element instanceof Vertex;

                return frame((Vertex) element, BranchMetadata.class);
            } else {
                return null;
View Full Code Here


        this.allowNull = allowNull;
    }

    protected E processNextStart() {
        while (true) {
            Element e = this.starts.next();
            E value = (E) e.getProperty(this.key);
            if (this.allowNull || value != null)
                return value;
        }
    }
View Full Code Here

        this.predicate = predicate;
    }

    protected Element processNextStart() {
        while (true) {
            final Element s = this.starts.next();
            if (this.predicate.evaluate(s.getId(), this.id))
                return s;
        }
    }
View Full Code Here

        if (!elementType.equals(Tokens.VERTEX) && !elementType.equals(Tokens.EDGE)) {
            throw new IllegalArgumentException("the " + Tokens._TYPE + " element in the transaction must be either " + Tokens.VERTEX + " or " + Tokens.EDGE);
        }

        Element graphElementCreated = null;
        if (elementType.equals(Tokens.VERTEX)) {
            graphElementCreated = graph.getVertex(id);

            if (graphElementCreated != null) {
                throw new Exception("Vertex with id " + id + " already exists.");
            }

            graphElementCreated = graph.addVertex(id);

        } else if (elementType.equals(Tokens.EDGE)) {

            String inV = null;
            Object temp = elementAsJson.opt(Tokens._IN_V);
            if (null != temp)
                inV = temp.toString();
            String outV = null;
            temp = elementAsJson.opt(Tokens._OUT_V);
            if (null != temp)
                outV = temp.toString();
            String label = null;
            temp = elementAsJson.opt(Tokens._LABEL);
            if (null != temp)
                label = temp.toString();

            if (outV == null || inV == null || outV.isEmpty() || inV.isEmpty()) {
                throw new IllegalArgumentException("an edge must specify a " + Tokens._IN_V + " and " + Tokens._OUT_V);
            }

            graphElementCreated = graph.getEdge(id);

            if (graphElementCreated != null) {
                throw new Exception("Edge with id " + id + " already exists.");
            }

            // there is no edge but the in/out vertex params and label are present so
            // validate that the vertexes are present before creating the edge
            final Vertex out = graph.getVertex(outV);
            final Vertex in = graph.getVertex(inV);
            if (out != null && in != null) {
                // in/out vertexes are found so edge can be created
                graphElementCreated = graph.addEdge(id, out, in, label);
            } else {
                throw new Exception("the " + Tokens._IN_V + " or " + Tokens._OUT_V + " vertices could not be found.");
            }

        }

        if (graphElementCreated != null) {
            Iterator keys = elementAsJson.keys();
            while (keys.hasNext()) {
                String key = keys.next().toString();
                if (!key.startsWith(Tokens.UNDERSCORE)) {
                    graphElementCreated.setProperty(key, ElementHelper.getTypedPropertyValue(elementAsJson.getString(key)));
                }
            }
        }
    }
View Full Code Here

        if (!elementType.equals(Tokens.VERTEX) && !elementType.equals(Tokens.EDGE)) {
            throw new IllegalArgumentException("the " + Tokens._TYPE + " element in the transaction must be either " + Tokens.VERTEX + " or " + Tokens.EDGE);
        }

        Element graphElementUpdated = null;
        if (elementType.equals(Tokens.VERTEX)) {
            graphElementUpdated = graph.getVertex(id);
        } else if (elementType.equals(Tokens.EDGE)) {
            graphElementUpdated = graph.getEdge(id);
        }

        if (graphElementUpdated != null) {
            Iterator keys = elementAsJson.keys();
            while (keys.hasNext()) {
                String key = keys.next().toString();
                if (!key.startsWith(Tokens.UNDERSCORE)) {
                    graphElementUpdated.setProperty(key, ElementHelper.getTypedPropertyValue(elementAsJson.getString(key)));
                }
            }
        }
    }
View Full Code Here

            throw new IllegalArgumentException("the " + Tokens._TYPE + " element in the transaction must be either " + Tokens.VERTEX + " or " + Tokens.EDGE);
        }

        final JSONArray keysToDelete = elementAsJson.optJSONArray("_keys");

        Element graphElementDeleted = null;
        if (elementType.equals(Tokens.VERTEX)) {
            graphElementDeleted = graph.getVertex(id);
        } else if (elementType.equals(Tokens.EDGE)) {
            graphElementDeleted = graph.getEdge(id);
        }

        if (graphElementDeleted != null) {
            if (keysToDelete != null && keysToDelete.length() > 0) {
                // just delete keys from the element
                for (int ix = 0; ix < keysToDelete.length(); ix++) {
                    graphElementDeleted.removeProperty(keysToDelete.optString(ix));
                }
            } else {
                // delete the whole element
                if (elementType.equals(Tokens.VERTEX)) {
                    graph.removeVertex((Vertex) graphElementDeleted);
View Full Code Here

            packer.write(ValueFactory.createNilValue());
        } else if (object instanceof String || object instanceof Number || object instanceof Boolean) {
            packer.write(object);
        } else if (object instanceof Element) {
            try {
                final Element element = (Element) object;
                final Set<String> propertyKeys = element.getPropertyKeys();
                final int propertySize = propertyKeys.size();
                final boolean isVertex = !(element instanceof Edge);
                final int elementSize = (isVertex ? 2 : 5) + ((propertySize > 0) ? 1 : 0);

                packer.writeMapBegin(elementSize);
                packer.write(Tokens._ID);
                packer.write(serializeElementId(element));

                if (isVertex) {
                    packer.write(Tokens._TYPE);
                    packer.write(Tokens.VERTEX);
                } else {
                    final Edge edge = (Edge) element;
                    packer.write(Tokens._TYPE);
                    packer.write(Tokens.EDGE);
                    packer.write(Tokens._IN_V);
                    packer.write(serializeElementId(edge.getVertex(Direction.IN)));
                    packer.write(Tokens._OUT_V);
                    packer.write(serializeElementId(edge.getVertex(Direction.OUT)));
                    packer.write(Tokens._LABEL);
                    packer.write(edge.getLabel());
                }

                if (propertyKeys.size() > 0) {
                    packer.write(Tokens._PROPERTIES);
                    packer.writeMapBegin(propertySize);

                    final Iterator<String> itty = propertyKeys.iterator();
                    while (itty.hasNext()) {
                        final String propertyKey = itty.next();
                        packer.write(propertyKey);
                        serializeObject(element.getProperty(propertyKey), packer);
                    }

                    packer.writeMapEnd(false);
                }
                packer.writeMapEnd(false);
            } catch (Exception e) {
                // if a transaction gets closed and the element goes out of scope it may not serialize.  in these
                // cases the vertex will just be written as null.  this can happen during binding serialization.
                // specific case is doing this:
                // v = g.addVertex()
                // g.rollback()
                // in some graphs v will go out of scope, yet it is still on the bindings as a Vertex object.
                packer.writeNil();
            }
        } else if (object instanceof Map) {
            final Map map = (Map) object;
            packer.writeMapBegin(map.size());
            for (Object key : map.keySet()) {
                if(key instanceof Element) {
                    // restructure element -> x maps
                    // this is typical in Tree and Map returns where the key is an object value instead of a
                    // primitive.  MsgPack can't process keys that way so the data needs to be restructured
                    // so that it doesn't end up simply being toString'd
                    final Element element = (Element) key;
                    writeMapKey(element.getId(), packer);
                    final HashMap<String, Object> m = new HashMap<String, Object>();
                    m.put(Tokens._KEY, element);
                    m.put(Tokens._VALUE, map.get(key));
                    serializeObject(m, packer);
                } else {
View Full Code Here

            final Map map = (Map) object;
            for (Object key : map.keySet()) {
                // force an error here by passing in a null key to the JSONObject.  That way a good error message
                // gets back to the user.
                if (key instanceof Element) {
                    final Element element = (Element) key;
                    final HashMap<String, Object> m = new HashMap<String, Object>();
                    m.put(Tokens._KEY, this.prepareOutput(element));
                    m.put(Tokens._VALUE, this.prepareOutput(map.get(key)));

                    jsonObject.put(element.getId().toString(), new JSONObject(m));
                } else {
                    jsonObject.put(key == null ? null : key.toString(), this.prepareOutput(map.get(key)));
                }
            }
View Full Code Here

            return null;
        } else if (object instanceof String || object instanceof Number || object instanceof Boolean) {
            return object;
        } else if (object instanceof Element) {
            try {
                final Element element = (Element) object;
                final Set<String> propertyKeys = element.getPropertyKeys();
                final boolean isVertex = !(element instanceof Edge);

                HashMap<Object, Object> outMap = new HashMap<Object, Object>();
                outMap.put(Tokens._ID, serializeElementId(element));

                if (isVertex) {
                    outMap.put(Tokens._TYPE, Tokens.VERTEX);
                } else {
                    final Edge edge = (Edge) element;
                    outMap.put(Tokens._TYPE, Tokens.EDGE);
                    outMap.put(Tokens._IN_V, serializeElementId(edge.getVertex(Direction.IN)));
                    outMap.put(Tokens._OUT_V, serializeElementId(edge.getVertex(Direction.OUT)));
                    outMap.put(Tokens._LABEL, edge.getLabel());
                }

                if (propertyKeys.size() > 0) {
                    HashMap<Object, Object> propertyMap = new HashMap<Object, Object>();

                    final Iterator<String> itty = propertyKeys.iterator();
                    while (itty.hasNext()) {
                        final String propertyKey = itty.next();
                        propertyMap.put(propertyKey, convert(element.getProperty(propertyKey)));
                    }
                    outMap.put(Tokens._PROPERTIES, propertyMap);
                }

                return outMap;
            } catch (Exception e) {
                // if a transaction gets closed and the element goes out of scope it may not serialize.  in these
                // cases the vertex will just be written as null.  this can happen during binding serialization.
                // specific case is doing this:
                // v = g.addVertex()
                // g.rollback()
                // in some graphs v will go out of scope, yet it is still on the bindings as a Vertex object.
                return null;
            }
        } else if (object instanceof Map) {
            final Map map = (Map) object;
            HashMap<Object, Object> outMap = new HashMap<Object, Object>();
            for (Object key : map.keySet()) {
                if(key instanceof Element) {
                    // restructure element -> x maps
                    // this is typical in Tree and Map returns where the key is an object value instead of a
                    // primitive.  MsgPack can't process keys that way so the data needs to be restructured
                    // so that it doesn't end up simply being toString'd
                    final Element element = (Element) key;
                    final HashMap<String, Object> m = new HashMap<String, Object>();
                    m.put(Tokens._KEY, element);
                    m.put(Tokens._VALUE, map.get(key));
                    outMap.put(element.getId().toString(), convert(m));
                } else {
                    outMap.put(key, convert(map.get(key)));
                }
            }
            return outMap;
View Full Code Here

  }

  @Override
  public Vertex addVertex(final Object id) {
    Vertex result = null;
    Element chk = getElementCache().get(id);
    if (chk != null) {
      if (chk instanceof Vertex) {
        result = (Vertex) chk;
      } else {
        throw new IllegalStateException("Requested id of " + String.valueOf(id) + " is already in cache but is a "
            + chk.getClass().getName());
      }
    } else {
      Map<String, Object> delegate = addElementDelegate(id);
      if (delegate != null) {
        Object typeChk = delegate.get(org.openntf.domino.graph2.DElement.TYPE_FIELD);
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Element

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.