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();
}
}
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();
}
}
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);
}
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);
}
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;
}
}
Aggregations