From a5782df946c22ea1b0f6ceacfbbb820e7c682aa0 Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Wed, 19 Oct 2011 11:09:47 +0200 Subject: [PATCH] developer notes cheat sheet as HTML --- developer_notes.html | 232 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 developer_notes.html diff --git a/developer_notes.html b/developer_notes.html new file mode 100644 index 000000000..a416199d8 --- /dev/null +++ b/developer_notes.html @@ -0,0 +1,232 @@ + + + Spring Data Neo4j - Developer Notes + + + + + + +

Developer Notes

+
+ Spring Data Neo4j Logo +
+
+

Neo4j - [IS_A] -> Property Graph

+ +

Nodes with key-value properties are connected by typed, directed relationships with properties.

+ + TODO put in a pretty picture + +

Cypher is a query language:

+
+start movie=(id) match movie<-[:ACTS_IN]-actor
+where actor.age > 20 return movie, actor.name
+order by movie.title 
+

Traversals walk the graph in the prescribed way

+
+TraversalDescription actors = Traversal.description()
+  .relationships("ACTS_IN").filter(returnAllButStartNode());
+
+for (Node actors : actors.traverse(movie))
+ ...
+ +

Transactional: TX needed for write operations

+
+Transaction tx=graphDatabaseService.beginTx();
+try {
+  ... graph operations ...
+  tx.success();
+} catch(Exception e) {
+  tx.failure();
+} finally {
+  tx.finish();
+}
+       
+
+
+

Maven Dependency

+ +
+   <dependency>
+       <groupId>org.springframework.data</groupId>
+       <artifactId>spring-data-neo4j[-aspects]</artifactId>
+       <version>2.0.0.RC1</version>
+   </dependency>
+
+
+ +
+

Spring-Config

+ +
<beans ...
+ xmlns:neo4j="http://www.swf.org/schema/data/neo4j"
+   xsi:schemaLocation=
+   "http://www.sfw.org/schema/data/neo4j" ...>
+
+...
+<neo4j:config store-dir="graph.db"/>
+<neo4j:repositories base-package="com.example.repositories"/>
+...
+</beans>
+

Testing

+
<neo4j:config graphDatabaseService="gds"/>
+<bean id="gds" class=”...ImpermanentGraphDatabase/>
+

REST

+ +
<neo4j:config graphDatabaseService="rds"/>
+<bean id="rds" class=”...SpringRestGraphDatabase/>
+
+
+

Entity - Annotations

+ +
+
+

Example

+
+@NodeEntity
+public class Movie {
+
+   @GraphId Long id;
+
+   @Indexed(fulltext = true, indexName = "search")
+   String title;
+
+   Person director;
+
+   @RelatedTo(type="ACTS_IN", direction = INCOMING)
+   Set<Person> actors;
+
+   @RelatedToVia(type = "RATED")
+   Iterable<Rating> ratings;
+   
+   @Query("start movie=node({self}) match
+           movie-->genre<--similar return similar")
+   Iterable<Movie> similarMovies;
+}
+
+
+

Repositories

+ +
+interface MovieRepository extends GraphRepository<Movie> {
+ @Query("start movie={0} match m<-[rating:RATED]-user
+       return rating")
+ Iterable<Rating> getRatings(Movie movie);
+ // Co-Actors
+ Iterable<Person> findByActorsMoviesActorName(name)
+}
+
+<neo4j:repositories base-package="com.example.dao"/>
+ + +
+
+

Neo4jTemplate

+ +
+
+

AspectJ - ActiveRecordMixin

+ adds the following methods, when implementing the NodeBacked interface +
+getPersistentState()
+relateTo(target, ...),
+getRelationshipTo(...)
+persist(),
+remove(),
+detach()
+...
+
+
+

Roo Add-on

+ +
+roo> addon search graph
+roo> addon install id --searchResultId 01
+roo> project --topLevelPackage net.cineasts
+roo> graph setup --provider NEO4J --databaseLocation cineasts
+roo> graph entity --class ~.model.Movie
+roo> field string title
+roo> graph entity --class ~.model.Actor
+roo> field string name
+roo> graph relationship --to Movie --from Actor
+  --fieldName movies --type ACTS_IN --cardinality ONE_TO_MANY
+roo> controller all --package ~.web
+
+
+

Libraries

+

spring-data-neo4j

+ Provides Repository based Object <-> Graph Mapping that copies data from and to the graph database. +

spring-data-neo4j-aspects

+ Provides transparent property and relationship mapping inside of transactions with live read- and write-through to the graph database. +

spring-data-neo4j-cross-store

+ Allows to partially store properties and relationships of JPA entities in the graph database. +

spring-data-neo4j-rest

+ Provides transparent remote access to Neo4j-Server via its REST Api (uses org.neo4j:neo4j-rest-graphdb) +
+
+

AspectJ - STS / eclipse setup

+ +
+
+

Links

+ +
+
+ +
+ + \ No newline at end of file