Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Index


        this.indices.put(index.getIndexName(), index);
        return index;
    }

    public <T extends Element> Index<T> getIndex(final String indexName, final Class<T> indexClass) {
        Index index = this.indices.get(indexName);
        if (null == index)
            return null;
        if (!indexClass.isAssignableFrom(index.getIndexClass()))
            throw ExceptionFactory.indexDoesNotSupportClass(indexName, indexClass);
        else
            return index;
    }
View Full Code Here


            return (CloseableIterable<T>) new RexsterEdgeIterable(this.graph.getGraphURI() + RexsterTokens.SLASH_INDICES_SLASH + RestHelper.encode(this.indexName) + RexsterTokens.QUESTION + RexsterTokens.KEY_EQUALS + key + RexsterTokens.AND + RexsterTokens.VALUE_EQUALS + RestHelper.uriCast(value), this.graph);
    }

    public boolean equals(final Object object) {
        if (object.getClass().equals(this.getClass())) {
            Index other = (Index) object;
            return other.getIndexClass().equals(this.getIndexClass()) && other.getIndexName().equals(this.getIndexName());
        } else {
            return false;
        }
    }
View Full Code Here

    public void exampleMetadataGetsCorrectIndices() throws IOException {
        TinkerMetadataReader.load(this.graph, TinkerMetadataReaderTest.class.getResourceAsStream("example-tinkergraph-metadata.dat"));

        Assert.assertEquals(2, this.graph.indices.size());

        Index idxAge = this.graph.getIndex("age", Vertex.class);
        CloseableIterable<Vertex> vertices = idxAge.get("age", 27);
        Assert.assertEquals(1, getIterableCount(vertices));
        vertices.close();

        Index idxWeight = this.graph.getIndex("weight", Edge.class);
        CloseableIterable<Edge> edges = idxWeight.get("weight", 0.5f);
        Assert.assertEquals(1, getIterableCount(edges));
        edges.close();
    }
View Full Code Here

            }

            assertTrue(ElementHelper.areEqual(e1, e2));
        }

        final Index idxAge = g2.getIndex("age", Vertex.class);
        assertEquals(g2.getVertex(1), idxAge.get("age", 29).iterator().next());
        assertEquals(g2.getVertex(2), idxAge.get("age", 27).iterator().next());

        final Index idxWeight = g2.getIndex("weight", Edge.class);
        assertEquals(g2.getEdge(7), idxWeight.get("weight", 0.5f).iterator().next());
        assertEquals(g2.getEdge(12), idxWeight.get("weight", 0.2f).iterator().next());

        final Iterator namesItty = g2.getVertices("name", "marko").iterator();
        assertEquals(g2.getVertex(1), namesItty.next());
        assertFalse(namesItty.hasNext());
View Full Code Here

                    if (vertexFound != null) {
                        jsonArray.put(GraphSONUtility.jsonFromElement(vertexFound, returnKeys, mode));
                    }
                }
            } else if (type.equals("index")) {
                Index idx = ((IndexableGraph)graph).getIndex(key, Vertex.class);

                for (int ix = 0; ix < values.length(); ix++) {
                    CloseableIterable<Vertex> verticesFound = idx.get(key, ElementHelper.getTypedPropertyValue(values.optString(ix)));
                    for (Vertex vertex : verticesFound) {
                        jsonArray.put(GraphSONUtility.jsonFromElement(vertex, returnKeys, mode));
                    }
                    verticesFound.close();
                }
View Full Code Here

                    if (edgeFound != null) {
                        jsonArray.put(GraphSONUtility.jsonFromElement(edgeFound, returnKeys, mode));
                    }
                }
            } else if (type.equals("index")) {
                Index idx = ((IndexableGraph)graph).getIndex(key, Edge.class);

                for (int ix = 0; ix < values.length(); ix++) {
                    CloseableIterable<Edge> edgesFound = idx.get(key, ElementHelper.getTypedPropertyValue(values.optString(ix)));
                    for (Edge edge : edgesFound) {
                        jsonArray.put(GraphSONUtility.jsonFromElement(edge, returnKeys, mode));
                    }
                    edgesFound.close();
                }
View Full Code Here

    public Response getElementsFromIndexRexsterTypedJson(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName) {
        return this.getElementsFromIndex(graphName, indexName, true);
    }

    private Response getElementsFromIndex(final String graphName, final String indexName, final boolean showTypes) {
        final Index index = this.getIndexFromGraph(graphName, indexName);
        final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);

        String key = null;
        Object value = null;

        final JSONObject theRequestObject = this.getRequestObject();

        Object temp = theRequestObject.opt(Tokens.KEY);
        if (null != temp)
            key = temp.toString();

        temp = theRequestObject.opt(Tokens.VALUE);
        if (null != temp)
            value = ElementHelper.getTypedPropertyValue(temp.toString());

        final Long start = RequestObjectHelper.getStartOffset(theRequestObject);
        final Long end = RequestObjectHelper.getEndOffset(theRequestObject);
        final Set<String> returnKeys = RequestObjectHelper.getReturnKeys(theRequestObject);
        final GraphSONMode mode = showTypes ? GraphSONMode.EXTENDED : GraphSONMode.NORMAL;

        long counter = 0l;

        if (null != index && key != null && value != null) {
            final CloseableIterable<Element> indexElements = (CloseableIterable<Element>) index.get(key, value);
            try {

                final JSONArray elementArray = new JSONArray();
                for (Element element : indexElements) {
                    if (counter >= start && counter < end) {
View Full Code Here

    @GET
    @Path("/{indexName}/count")
    @Produces({MediaType.APPLICATION_JSON, RexsterMediaType.APPLICATION_REXSTER_JSON, RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON})
    @Timed(name = "http.rest.indices.count.get", absolute = true)
    public Response getIndexCount(@PathParam("graphname") final String graphName, @PathParam("indexName") final String indexName) {
        final Index index = this.getIndexFromGraph(graphName, indexName);
        final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);

        String key = null;
        Object value = null;

        final JSONObject theRequestObject = this.getRequestObject();

        Object temp = theRequestObject.opt(Tokens.KEY);
        if (temp != null) {
            key = temp.toString();
        }

        temp = theRequestObject.opt(Tokens.VALUE);
        if (temp != null) {
            value = ElementHelper.getTypedPropertyValue(temp.toString());
        }

        if (index != null && key != null && value != null) {
            try {
                final long count = index.count(key, value);

                this.resultObject.put(Tokens.TOTAL_SIZE, count);
                this.resultObject.put(Tokens.QUERY_TIME, this.sh.stopWatch());

            } catch (JSONException ex) {
View Full Code Here

            value = ElementHelper.getTypedPropertyValue(temp.toString());
        temp = theRequestObject.opt(Tokens.ID);
        if (null != temp)
            id = temp.toString();

        final Index index = this.getIndexFromGraph(graphName, indexName);
        final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);
        final IndexableGraph graph = (IndexableGraph) rag.getGraph();

        if (null == index) {
            final String msg = "Could not find index [" + indexName + "] on graph [" + graphName + "]";
            logger.info(msg);

            final JSONObject error = generateErrorObject(msg);
            throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(error).build());
        }

        if (key == null && value == null && id == null) {
            try {
                graph.dropIndex(indexName);
                rag.tryCommit();
            } catch (Exception ex) {
                logger.error(ex);

                rag.tryRollback();

                final JSONObject error = generateErrorObjectJsonFail(ex);
                throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
            }
        } else if (null != index & key != null && value != null && id != null) {
            try {
                if (index.getIndexClass().equals(Vertex.class))
                    index.remove(key, value, graph.getVertex(id));
                else
                    index.remove(key, value, graph.getEdge(id));

                rag.tryCommit();
                this.resultObject.put(Tokens.QUERY_TIME, this.sh.stopWatch());

            } catch (JSONException ex) {
View Full Code Here

            indexParameters = new Parameter[idxParamsList.size()];
            idxParamsList.toArray(indexParameters);
        }

        final Index index = this.getIndexFromGraph(graphName, indexName);
        final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);
        final IndexableGraph graph = (IndexableGraph) rag.getGraph();

        if (null != index) {
            final String msg = "Index [" + indexName + "] on graph [" + graphName + "] already exists";
            logger.info(msg);

            final JSONObject error = generateErrorObject(msg);
            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
        } else {
            // create an index
            if (null != clazz) {
                final Class c;
                if (clazz.equals(Tokens.VERTEX))
                    c = Vertex.class;
                else if (clazz.equals(Tokens.EDGE))
                    c = Edge.class;
                else {
                    final JSONObject error = generateErrorObject("Index class must be either vertex or edge");
                    throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
                }

                final Index newIndex;
                try {
                    newIndex = graph.createIndex(indexName, c, indexParameters);
                    rag.tryCommit();
                } catch (Exception e) {
                    logger.info(e.getMessage());
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Index

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.