Skip to content

Instantly share code, notes, and snippets.

@timeu
Created May 13, 2013 09:48
Show Gist options
  • Save timeu/5567247 to your computer and use it in GitHub Desktop.
Save timeu/5567247 to your computer and use it in GitHub Desktop.
Spring Data Neo4j configuration
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg index="0" value="${neo4j.host}" />
</bean>
<bean id="typeRepresentationStrategyFactory" class="org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory">
<constructor-arg index="0" ref="graphDatabaseService"/>
<constructor-arg index="1" value="Noop"/>
</bean>
<neo4j:repositories base-package="com.xxx.domain" />
@NodeEntity
public class Term extends BaseGraphOntologyEntity{
@Indexed(unique=true)
private String id;
private String name;
private String definition;
private String synonyms;
@RelatedToVia(type="is_a",direction=Direction.INCOMING)
private Set<IsATerm> is_a_children;
@RelatedToVia(type="is_a",direction=Direction.OUTGOING)
Set<IsATerm> is_a_parents;
@RelatedToVia(type="part_of",direction = Direction.INCOMING)
Set<PartOfTerm> part_of_children;
@RelatedToVia(type="part_of",direction = Direction.OUTGOING)
Set<PartOfTerm> part_of_parents;
}
public interface TermRepository extends GraphRepository<Term> {
public Term findById(String id);
@Query("START n=node:Term(id={0}),m =node:Term(id={1}) match p = shortestPath(n-[*]->m) RETURN p")
public EndResult<EntityPath<Term,Term>> findShortestPath(String start,String end);
}
@Test
public void testFindShortestPath() {
EndResult<EntityPath<Term,Term>> endResult = repository.findShortestPath("TO:0000166","TO:0000387");
EntityPath<Term,Term> path = endResult.single();
List<Long> idsInPath = Lists.newArrayList();
for (Node node : path.nodes()) {
idsInPath.add(node.getId());
}
long[] checkIds = {909,784,1096,13,907,174};
assertEquals(6,idsInPath.size());
assertArrayEquals(checkIds, Longs.toArray(idsInPath));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment