use of org.neo4j.server.rest.repr.RelationshipIndexRepresentation 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.RelationshipIndexRepresentation in project neo4j by neo4j.
the class DatabaseActions method addToRelationshipIndex.
public IndexedEntityRepresentation addToRelationshipIndex(String indexName, String key, String value, long relationshipId) {
Relationship relationship = graphDb.getRelationshipById(relationshipId);
Index<Relationship> index = graphDb.index().forRelationships(indexName);
index.add(relationship, key, value);
return new IndexedEntityRepresentation(relationship, key, value, new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
}
use of org.neo4j.server.rest.repr.RelationshipIndexRepresentation in project neo4j by neo4j.
the class DatabaseActions method getOrCreateIndexedRelationship.
public Pair<IndexedEntityRepresentation, Boolean> getOrCreateIndexedRelationship(String indexName, String key, String value, Long relationshipOrNull, Long startNode, String type, Long endNode, Map<String, Object> properties) throws BadInputException, RelationshipNotFoundException, NodeNotFoundException {
assertIsLegalIndexName(indexName);
Relationship result;
boolean created;
if (relationshipOrNull != null) {
if (startNode != null || type != null || endNode != null || properties != null) {
throw new InvalidArgumentsException("Either specify a relationship to index uniquely, " + "or the means for creating it.");
}
Relationship relationship = relationship(relationshipOrNull);
result = graphDb.index().forRelationships(indexName).putIfAbsent(relationship, key, value);
if (created = result == null) {
UniqueRelationshipFactory factory = new UniqueRelationshipFactory(indexName, relationship.getStartNode(), relationship.getEndNode(), relationship.getType().name(), properties);
UniqueEntity<Relationship> entity = factory.getOrCreateWithOutcome(key, value);
// when given a relationship id, return as created if that relationship was newly added to the index
created = entity.entity().getId() == relationship.getId() || entity.wasCreated();
result = entity.entity();
}
} else if (startNode == null || type == null || endNode == null) {
throw new InvalidArgumentsException("Either specify a relationship to index uniquely, " + "or the means for creating it.");
} else {
UniqueRelationshipFactory factory = new UniqueRelationshipFactory(indexName, node(startNode), node(endNode), type, properties);
UniqueEntity<Relationship> entity = factory.getOrCreateWithOutcome(key, value);
result = entity.entity();
created = entity.wasCreated();
}
return Pair.of(new IndexedEntityRepresentation(result, key, value, new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap())), created);
}
Aggregations