Search in sources :

Example 1 with IndexedEntityRepresentation

use of org.neo4j.server.rest.repr.IndexedEntityRepresentation in project neo4j by neo4j.

the class DatabaseActionsTest method shouldNotIndexRelationshipWhenAnotherRelationshipAlreadyIndexed.

@Test
public void shouldNotIndexRelationshipWhenAnotherRelationshipAlreadyIndexed() throws Exception {
    graphdbHelper.createRelationshipIndex("myIndex");
    try (Transaction tx = graph.beginTx()) {
        long relationshipId = graphdbHelper.createRelationship("FOO");
        Pair<IndexedEntityRepresentation, Boolean> result = actions.getOrCreateIndexedRelationship("myIndex", "foo", "bar", relationshipId, null, null, null, null);
        assertThat(result.other(), is(true));
        assertThat(serialize(actions.getIndexedRelationships("myIndex", "foo", "bar")).size(), is(1));
        assertThat(actions.relationshipIsIndexed("myIndex", "foo", "bar", relationshipId), is(true));
        tx.success();
    }
    try (Transaction tx = graph.beginTx()) {
        long relationshipId = graphdbHelper.createRelationship("FOO");
        Pair<IndexedEntityRepresentation, Boolean> result = actions.getOrCreateIndexedRelationship("myIndex", "foo", "bar", relationshipId, null, null, null, null);
        assertThat(result.other(), is(false));
        assertThat(serialize(actions.getIndexedRelationships("myIndex", "foo", "bar")).size(), is(1));
        assertThat(actions.relationshipIsIndexed("myIndex", "foo", "bar", relationshipId), is(false));
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 2 with IndexedEntityRepresentation

use of org.neo4j.server.rest.repr.IndexedEntityRepresentation in project neo4j by neo4j.

the class DatabaseActionsTest method shouldIndexRelationshipOnlyOnce.

@Test
public void shouldIndexRelationshipOnlyOnce() throws Exception {
    long relationshipId = graphdbHelper.createRelationship("FOO");
    graphdbHelper.createRelationshipIndex("myIndex");
    try (Transaction tx = graph.beginTx()) {
        Pair<IndexedEntityRepresentation, Boolean> result = actions.getOrCreateIndexedRelationship("myIndex", "foo", "bar", relationshipId, null, null, null, null);
        assertThat(result.other(), is(true));
        assertThat(serialize(actions.getIndexedRelationships("myIndex", "foo", "bar")).size(), is(1));
        assertThat(actions.relationshipIsIndexed("myIndex", "foo", "bar", relationshipId), is(true));
        tx.success();
    }
    try (Transaction tx = graph.beginTx()) {
        Pair<IndexedEntityRepresentation, Boolean> result = actions.getOrCreateIndexedRelationship("myIndex", "foo", "bar", relationshipId, null, null, null, null);
        assertThat(result.other(), is(false));
        assertThat(serialize(actions.getIndexedRelationships("myIndex", "foo", "bar")).size(), is(1));
        assertThat(actions.relationshipIsIndexed("myIndex", "foo", "bar", relationshipId), is(true));
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 3 with IndexedEntityRepresentation

use of org.neo4j.server.rest.repr.IndexedEntityRepresentation in project neo4j by neo4j.

the class DatabaseActions method getIndexedNodes.

public ListRepresentation getIndexedNodes(String indexName, final String key, final String value) {
    if (!graphDb.index().existsForNodes(indexName)) {
        throw new NotFoundException();
    }
    Index<Node> index = graphDb.index().forNodes(indexName);
    final IndexRepresentation indexRepresentation = new NodeIndexRepresentation(indexName);
    final IndexHits<Node> indexHits = index.get(key, value);
    final IterableWrapper<Representation, Node> results = new IterableWrapper<Representation, Node>(indexHits) {

        @Override
        protected Representation underlyingObjectToObject(Node node) {
            return new IndexedEntityRepresentation(node, key, value, indexRepresentation);
        }
    };
    return new ListRepresentation(RepresentationType.NODE, results);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Node(org.neo4j.graphdb.Node) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PropertiesRepresentation(org.neo4j.server.rest.repr.PropertiesRepresentation) ScoredNodeRepresentation(org.neo4j.server.rest.repr.ScoredNodeRepresentation) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) ScoredRelationshipRepresentation(org.neo4j.server.rest.repr.ScoredRelationshipRepresentation) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) Representation(org.neo4j.server.rest.repr.Representation) IndexDefinitionRepresentation(org.neo4j.server.rest.repr.IndexDefinitionRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) RelationshipIndexRootRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRootRepresentation(org.neo4j.server.rest.repr.NodeIndexRootRepresentation) DatabaseRepresentation(org.neo4j.server.rest.repr.DatabaseRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 4 with IndexedEntityRepresentation

use of org.neo4j.server.rest.repr.IndexedEntityRepresentation in project neo4j by neo4j.

the class DatabaseActions method getIndexedRelationships.

public ListRepresentation getIndexedRelationships(String indexName, final String key, final String value) {
    if (!graphDb.index().existsForRelationships(indexName)) {
        throw new NotFoundException();
    }
    Index<Relationship> index = graphDb.index().forRelationships(indexName);
    final IndexRepresentation indexRepresentation = new RelationshipIndexRepresentation(indexName);
    IterableWrapper<Representation, Relationship> result = new IterableWrapper<Representation, Relationship>(index.get(key, value)) {

        @Override
        protected Representation underlyingObjectToObject(Relationship relationship) {
            return new IndexedEntityRepresentation(relationship, key, value, indexRepresentation);
        }
    };
    return new ListRepresentation(RepresentationType.RELATIONSHIP, result);
}
Also used : RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) Relationship(org.neo4j.graphdb.Relationship) StartNodeNotFoundException(org.neo4j.server.rest.domain.StartNodeNotFoundException) NotFoundException(org.neo4j.graphdb.NotFoundException) EndNodeNotFoundException(org.neo4j.server.rest.domain.EndNodeNotFoundException) PropertiesRepresentation(org.neo4j.server.rest.repr.PropertiesRepresentation) ScoredNodeRepresentation(org.neo4j.server.rest.repr.ScoredNodeRepresentation) NodeRepresentation(org.neo4j.server.rest.repr.NodeRepresentation) ScoredRelationshipRepresentation(org.neo4j.server.rest.repr.ScoredRelationshipRepresentation) PathRepresentation(org.neo4j.server.rest.repr.PathRepresentation) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation) Representation(org.neo4j.server.rest.repr.Representation) IndexDefinitionRepresentation(org.neo4j.server.rest.repr.IndexDefinitionRepresentation) WeightedPathRepresentation(org.neo4j.server.rest.repr.WeightedPathRepresentation) RelationshipIndexRootRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRootRepresentation) RelationshipIndexRepresentation(org.neo4j.server.rest.repr.RelationshipIndexRepresentation) RelationshipRepresentation(org.neo4j.server.rest.repr.RelationshipRepresentation) ValueRepresentation(org.neo4j.server.rest.repr.ValueRepresentation) IndexRepresentation(org.neo4j.server.rest.repr.IndexRepresentation) NodeIndexRootRepresentation(org.neo4j.server.rest.repr.NodeIndexRootRepresentation) DatabaseRepresentation(org.neo4j.server.rest.repr.DatabaseRepresentation) NodeIndexRepresentation(org.neo4j.server.rest.repr.NodeIndexRepresentation) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) IterableWrapper(org.neo4j.helpers.collection.IterableWrapper) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 5 with IndexedEntityRepresentation

use of org.neo4j.server.rest.repr.IndexedEntityRepresentation in project neo4j by neo4j.

the class TransactionWrappedDatabaseActions method addToNodeIndex.

@Override
public IndexedEntityRepresentation addToNodeIndex(String indexName, String key, String value, long nodeId) {
    try (Transaction transaction = graph.beginTx()) {
        IndexedEntityRepresentation indexedEntityRepresentation = super.addToNodeIndex(indexName, key, value, nodeId);
        transaction.success();
        return indexedEntityRepresentation;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexedEntityRepresentation(org.neo4j.server.rest.repr.IndexedEntityRepresentation)

Aggregations

IndexedEntityRepresentation (org.neo4j.server.rest.repr.IndexedEntityRepresentation)11 Transaction (org.neo4j.graphdb.Transaction)5 Test (org.junit.Test)4 NodeIndexRepresentation (org.neo4j.server.rest.repr.NodeIndexRepresentation)4 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)4 RelationshipIndexRepresentation (org.neo4j.server.rest.repr.RelationshipIndexRepresentation)4 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)4 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 NotFoundException (org.neo4j.graphdb.NotFoundException)2 IterableWrapper (org.neo4j.helpers.collection.IterableWrapper)2 EndNodeNotFoundException (org.neo4j.server.rest.domain.EndNodeNotFoundException)2 StartNodeNotFoundException (org.neo4j.server.rest.domain.StartNodeNotFoundException)2 ConstraintDefinitionRepresentation (org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation)2 DatabaseRepresentation (org.neo4j.server.rest.repr.DatabaseRepresentation)2 IndexDefinitionRepresentation (org.neo4j.server.rest.repr.IndexDefinitionRepresentation)2 IndexRepresentation (org.neo4j.server.rest.repr.IndexRepresentation)2 InvalidArgumentsException (org.neo4j.server.rest.repr.InvalidArgumentsException)2 ListRepresentation (org.neo4j.server.rest.repr.ListRepresentation)2 NodeIndexRootRepresentation (org.neo4j.server.rest.repr.NodeIndexRootRepresentation)2