Spring Data Neo4j                                                          Michael Hunger - @mesirii                      ...
Twitter example          To become part of todays               Twitter-Graph
Twitter example        To become part of todays             Twitter-Graph    please tweet with #s2gx #neo4j
Twitter example        To become part of todays             Twitter-Graph    please tweet with #s2gx #neo4j               ...
Agenda     1. Connected Data, Graph Databases and Neo4j     2. Spring Data Neo4j     3. Twitter-Graph - Sample App     4. ...
The Evolution of Web Search 4
The Evolution of Web Search     Pre-1999     WWW Indexing 4
The Evolution of Web Search     Pre-1999       1999 - 2012     WWW Indexing    Google Invents                       PageRa...
The Evolution of Web Search     Pre-1999       1999 - 2012           2012-?     WWW Indexing    Google Invents   Google La...
The Evolution of Web Search     Pre-1999       1999 - 2012           2012-?     WWW Indexing    Google Invents   Google La...
The Evolution of Web Search     Pre-1999       1999 - 2012           2012-?     WWW Indexing    Google Invents   Google La...
The Evolution of Web Search     Pre-1999       1999 - 2012           2012-?     WWW Indexing    Google Invents   Google La...
The Evolution of Online Job Search 5
The Evolution of Online Job Search       2010-11      Resume Scoring      Atomic Data 5
The Evolution of Online Job Search       2010-11             2011-12      Resume Scoring     Social Job Search      Atomic...
The Evolution of Web Browsing 6
The Evolution of Web Browsing         Pre-2012        Explicit Browsing         Atomic Data 6
The Evolution of Web Browsing         Pre-2012               2012+        Explicit Browsing   Connected Browsing          ...
Other Markets In Evolution      Core Industries               Finance &   Datacom /                        Web / ISV      ...
Other Markets In EvolutionCore Industries             Finance & Datacom /               Life      Media &   Education,   G...
Everyone talks about graphs     4
Everyone talks about graphs   Facebook Open Graph      4
Everyone talks about graphs   Facebook Open Graph      4
Graph Databases
Connected data in a relational database 10
Connected data in a relational database 10
Connected data in a relational database            foo 10
Connected data in a relational database            foo                bar 10
Connected data in a relational database            foo     foo_bar    bar 10
Connected data in a relational database            foo     foo_bar    bar 10
Connected data in a relational database            foo     foo_bar    bar 10
Connected data in a relational database 10
Connected data in a relational database 10
Connected data in a relational database 10
Connected data in a relational database 10
Connected data in a relational database 10
Connected data in a relational database 10
The Property Graph model 11
The Property Graph model                                         Em                                       Joh             ...
The Property Graph model                                         Em                                       Joh             ...
The Property Graph model                                                Em                                       Joh      ...
The Property Graph model                                                     E                                            ...
Whiteboard friendliness4
Whiteboard friendliness                              Peter             Andreas                                      Alliso...
Whiteboard friendliness                                     Peter             Andreas   knows                  knows      ...
Whiteboard friendliness                                     Peter             Andreas   knows                  knows      ...
Great! But what about performance? 13
Great! But what about performance? 13
Great! But what about performance?• a sample social graph 13
Great! But what about performance?• a sample social graph  –with ~1,000 persons 13
Great! But what about performance?• a sample social graph  –with ~1,000 persons• average 50 friends per person 13
Great! But what about performance?• a sample social graph  –with ~1,000 persons• average 50 friends per person• pathExists...
Great! But what about performance?• a sample social graph   –with ~1,000 persons• average 50 friends per person• pathExist...
Great! But what about performance?• a sample social graph   –with ~1,000 persons• average 50 friends per person• pathExist...
Great! But what about performance?• a sample social graph   –with ~1,000 persons• average 50 friends per person• pathExist...
Great! But what about performance?• a sample social graph   –with ~1,000 persons• average 50 friends per person• pathExist...
Great! But what about performance?• a sample social graph   –with ~1,000 persons• average 50 friends per person• pathExist...
How do I query this graph?     // lookup starting point in an index     START user=node:User(name     start n=node:People(...
How do I query this graph?     // lookup starting point in an index     START user=node:User(name     start n=node:People(...
4
(Neo4j) -[:IS_A]-> (Graph Database)4
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:4
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph4
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Neo4j) -[:IS_A]-> (Graph Database)     - A Graph Database:        - a schema-free Property Graph        - perfect for com...
(Cypher) -[:IS_A]-> (Graph Query Language)     ๏ Declarative query language        • Describe what you want, not how      ...
(Neo4j) -[:LOVES]-> (Our Customers) 19
(Neo4j) -[:LOVES]-> (Our Customers) 19
Spring Data Neo4j
Spring Data Neo4j     ๏ Spring Data: VMWare/SpringSource initiative to give Spring         developers easy access to the e...
Spring Data Neo4j features• Annotation-based programming model• Spring Data Commons Repository support• Neo4j Query and Tr...
Classic Neo4j domain class public class Tag {     private final Node underlyingNode;     Tag( final Node node ) {         ...
Spring Data Neo4j domain class   @NodeEntity   public class Tag {       @GraphId private Long id;       private String nam...
Spring Data Neo4j domain class   @NodeEntity   public class Tag {       @GraphId private Long id;       @Indexed(unique = ...
Defining entity classes
Defining entity classes• @NodeEntity • Represents a node in the graph • Fields saved as properties on node • References st...
Defining entity classes
Defining entity classes• @RelationshipEntity • Represents a relationship in the graph • Fields saved as properties on rela...
Tweet domain class    @NodeEntity    public class Tweet {    @GraphId private Long id;    @Indexed(unique=true) Long tweet...
Interface based Repositories• based on Repository infrastructure in Spring Data Commons• just define the interface and the...
Repositoriesinterface TweetRepository extends GraphRepository<Tweet> {    Tweet findByTweetId(String id);    Collection<Tw...
Neo4j-Template (I)• well known Spring Template Pattern• Resource / Transaction Management• Convenience Methods• Nodes and ...
Neo4j-Server-Support  <bean id="restGraphDatabaseService"        class="org.sf.data.neo4j.rest.SpringRestGraphDatabase">  ...
Sample App     -uses Spring Social (minimally)     -Simple Domain: Tweets, Users, Tags        -connected Entities        -...
Whiteboard friendly - Abstract                      :Tweet                                 :Tweet
Whiteboard friendly - Abstract               :User                    PO                      ST                        ED...
Whiteboard friendly - Abstract               :User                    PO                      ST                        ED...
Whiteboard friendly - Abstract               :User                    PO                      ST                        ED...
Whiteboard friendly - Example                   Attending the                   #S2GX #SDN                    session by  ...
Whiteboard friendly - Example         @peterneubauer                   PO                     ST                       ED ...
Whiteboard friendly - Example         @peterneubauer                   PO                     ST                       ED ...
Whiteboard friendly - Example         @peterneubauer                   PO                     ST                       ED ...
Twitter - Graph Data Model4
Spring Data Neo4j - Sample Domain Class & Service4
Neo4j - Sample Graph Query    START tag1=node:Tag("tag:*obama*")    > MATCH tag1<-[:TAG]-tweet-[:sender]->user,           ...
Neo4j - Twitter Sample App        Code
Hubway Data Challenge - Import• Boston Bike Sharing Network• Import using Spring Data Neo4j• Visualization with Cypher & d...
Cineasts.net - a social movie databaseCheck Out: http://spring.neo4j.org/tutorial
Spring Data Neo4j Guidebook                       “Good Relationships”“I’m excited about Spring Data Neo4j.... makes worki...
Spring Data Neo4j Guidebook                       “Good Relationships”“I’m excited about Spring Data Neo4j.... makes worki...
O‘Reilly Spring Data Book    „Modern Data Access for Enterprise Java“  • book by the Spring Data project leads  • introduc...
How do I get started?4
How do I get started?๏ Documentation4
How do I get started?๏ Documentation    • http://spring.neo4j.org4
How do I get started?๏ Documentation    • http://spring.neo4j.org    • Dev-Notes4
How do I get started?๏ Documentation    • http://spring.neo4j.org    • Dev-Notes    • Spring Data Book4
How do I get started?๏ Documentation    • http://spring.neo4j.org    • Dev-Notes    • Spring Data Book    • Good Relations...
How do I get started?๏ Documentation    • http://spring.neo4j.org    • Dev-Notes    • Spring Data Book    • Good Relations...
How do I get started?๏ Documentation    • http://spring.neo4j.org    • Dev-Notes    • Spring Data Book    • Good Relations...
How do I get started?๏ Documentation     • http://spring.neo4j.org     • Dev-Notes     • Spring Data Book     • Good Relat...
How do I get started?๏ Documentation     • http://spring.neo4j.org     • Dev-Notes     • Spring Data Book     • Good Relat...
How do I get started?๏ Documentation     • http://spring.neo4j.org     • Dev-Notes     • Spring Data Book     • Good Relat...
GraphConnect Nov 6th 2012 San Francisco                                                            50%                    ...
Thank you !    Questions ?4
Upcoming SlideShare
Loading in...5
×

Spring Data Neo4j Intro SpringOne 2012

2,731

Published on

Graphs are everywhere. From websites adding social capabilities to Telcos providing personalized customer services, to innovative bioinformatics research, organizations are adopting graph databases as the best way to model and query connected data. If you can whiteboard, you can model your domain in a graph database.
In this session Emil Eifrem provides a close look at the graph model and offers best use cases for effective, cost-efficient data storage and accessibility.
Take Aways: Understand the model of a graph database and how it compares to document and relational databases Understand why graph databases are best suited for the storage, mapping and querying of connected data
Emil's presentation will be followed by a Hands-on Guide to Spring Data Neo4j. Spring Data Neo4j provides straightforward object persistence into the Neo4j graph database. Conceived by Rod Johnson and Neo Technology CEO Emil Eifrem, it is the founding project of the Spring Data effort. The library leverages a tight integration with the Spring Framework and the Spring Data infrastructure. Besides the easy to use object graph mapping it offers the powerful graph manipulation and query capabilities of Neo4j with a convenient API.
The talk introduces the different aspects of Spring Data Neo4j and shows applications in several example domains.
During the session we walk through the creation of a engaging sample application that starts with the setup and annotating the domain objects. We see the usage of Neo4jTemplate and the powerful repository abstraction. After deploying the application to a cloud PaaS we execute some interesting query use-cases on the collected data.

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,731
On Slideshare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
0
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Neo4j Query and Traversal support on dynamic fields and via repository methods\nNeo4j indexing support (includes unique indexes, fulltext and numeric range queries)\nEntity types stored in the graph (index or category-nodes)\nDynamic type projection (duck typing)\nCross-store support for partial JPA / graph entities\nSupport for JSR-303 (bean validation)\nSupport for the Neo4j Server (remote server and in server extension)\nNeo4jTemplate with exception translation, optional transaction management and more\n
  • \n
  • Jumping right into code\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Spring Data Neo4j Intro SpringOne 2012

    1. 1. Spring Data Neo4j Michael Hunger - @mesirii Emil Eifrem - @emileifrem Neo Technology #neo4j© 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission.
    2. 2. Twitter example To become part of todays Twitter-Graph
    3. 3. Twitter example To become part of todays Twitter-Graph please tweet with #s2gx #neo4j
    4. 4. Twitter example To become part of todays Twitter-Graph please tweet with #s2gx #neo4j ✓your attendance ✓questions ✓remarks ✓....
    5. 5. Agenda 1. Connected Data, Graph Databases and Neo4j 2. Spring Data Neo4j 3. Twitter-Graph - Sample App 4. Summary 5. Q & A
    6. 6. The Evolution of Web Search 4
    7. 7. The Evolution of Web Search Pre-1999 WWW Indexing 4
    8. 8. The Evolution of Web Search Pre-1999 1999 - 2012 WWW Indexing Google Invents PageRank 4
    9. 9. The Evolution of Web Search Pre-1999 1999 - 2012 2012-? WWW Indexing Google Invents Google Launches the PageRank Knowledge Graph 4
    10. 10. The Evolution of Web Search Pre-1999 1999 - 2012 2012-? WWW Indexing Google Invents Google Launches the PageRank Knowledge Graph Atomic Data 4
    11. 11. The Evolution of Web Search Pre-1999 1999 - 2012 2012-? WWW Indexing Google Invents Google Launches the PageRank Knowledge Graph Simple Atomic Data Connected Data 4
    12. 12. The Evolution of Web Search Pre-1999 1999 - 2012 2012-? WWW Indexing Google Invents Google Launches the PageRank Knowledge Graph Simple Rich Atomic Data Connected Data Connected Data 4
    13. 13. The Evolution of Online Job Search 5
    14. 14. The Evolution of Online Job Search 2010-11 Resume Scoring Atomic Data 5
    15. 15. The Evolution of Online Job Search 2010-11 2011-12 Resume Scoring Social Job Search Atomic Data Connected Data 5
    16. 16. The Evolution of Web Browsing 6
    17. 17. The Evolution of Web Browsing Pre-2012 Explicit Browsing Atomic Data 6
    18. 18. The Evolution of Web Browsing Pre-2012 2012+ Explicit Browsing Connected Browsing ? Atomic Data Connected Data 6
    19. 19. Other Markets In Evolution Core Industries Finance & Datacom / Web / ISV & Use Cases: Insurance Telecom Network /Cloud Mgmt MDM Social Geo 7
    20. 20. Other Markets In EvolutionCore Industries Finance & Datacom / Life Media & Education, Government, Web / ISV Logistics Aerospace, & Use Cases: Insurance Telecom Sciences Publishing Not-for- Gaming, ... Profit Network /Cloud Mgmt MDM Social GeoResource Auth & Access Control ContentManagementRecommend- ationsData CenterManagement FraudDetection, ... 7
    21. 21. Everyone talks about graphs 4
    22. 22. Everyone talks about graphs Facebook Open Graph 4
    23. 23. Everyone talks about graphs Facebook Open Graph 4
    24. 24. Graph Databases
    25. 25. Connected data in a relational database 10
    26. 26. Connected data in a relational database 10
    27. 27. Connected data in a relational database foo 10
    28. 28. Connected data in a relational database foo bar 10
    29. 29. Connected data in a relational database foo foo_bar bar 10
    30. 30. Connected data in a relational database foo foo_bar bar 10
    31. 31. Connected data in a relational database foo foo_bar bar 10
    32. 32. Connected data in a relational database 10
    33. 33. Connected data in a relational database 10
    34. 34. Connected data in a relational database 10
    35. 35. Connected data in a relational database 10
    36. 36. Connected data in a relational database 10
    37. 37. Connected data in a relational database 10
    38. 38. The Property Graph model 11
    39. 39. The Property Graph model Em Joh il a n knows knows Alli Tob Lar son ias knows s knows And And knows knows rea rés s knows knows knows Pet Miic Mc knows Ian er knows a a knows knows De Mic lia h ael 11
    40. 40. The Property Graph model Em Joh il a n knows knows Alli Tob Lar son ias knows s Nodes And knows And knows knows rea rés s knows knows knows Pet Miic Mc knows Ian er knows a a knows knows De Mic lia h ael 11
    41. 41. The Property Graph model Em Joh il a n knows knows Alli Tob Lar son ias knows s Nodes And knows And knows knows rea rés s knows knows knows Pet Miic Mc knows Ian er knows a a knows knows De Mic lia h ael Relationships 11
    42. 42. The Property Graph model E Joh Em mil Joh a a n il n knows knows knows knows AllAlliso iso n Tob Tobia knows Lar Lar s Nodes n ias s knows s knows knows An And And And knows knows knows knows dre re rés rés as as knows knows knows knows knowsknows Pet e Pe t Miic M M c Mi knows Ian Ian r er knows knows a ica a ca knows knows knows knows knows De D Mi c M lia el hae ich ia l ae Relationships l Properties (each a key+value) + Indexes (for easy look-ups) 11
    43. 43. Whiteboard friendliness4
    44. 44. Whiteboard friendliness Peter Andreas Allison Emil4
    45. 45. Whiteboard friendliness Peter Andreas knows knows knows Allison knows Emil4
    46. 46. Whiteboard friendliness Peter Andreas knows knows knows Allison knows Emil4
    47. 47. Great! But what about performance? 13
    48. 48. Great! But what about performance? 13
    49. 49. Great! But what about performance?• a sample social graph 13
    50. 50. Great! But what about performance?• a sample social graph –with ~1,000 persons 13
    51. 51. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person 13
    52. 52. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person• pathExists(a,b) limited to depth 4 13
    53. 53. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person• pathExists(a,b) limited to depth 4• caches warmed up to eliminate disk I/O 13
    54. 54. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person• pathExists(a,b) limited to depth 4• caches warmed up to eliminate disk I/O # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 13
    55. 55. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person• pathExists(a,b) limited to depth 4• caches warmed up to eliminate disk I/O # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 13
    56. 56. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person• pathExists(a,b) limited to depth 4• caches warmed up to eliminate disk I/O # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 13
    57. 57. Great! But what about performance?• a sample social graph –with ~1,000 persons• average 50 friends per person• pathExists(a,b) limited to depth 4• caches warmed up to eliminate disk I/O # persons query time Relational database 1,000 2000ms Neo4j 1,000 2ms Neo4j 1,000,000 2ms 14
    58. 58. How do I query this graph? // lookup starting point in an index START user=node:User(name start n=node:People(name ==‘Andreas’) ‘Andreas’) MATCH (user)-[:HAS_SENT]->(tweet)-[:TAGGED_BY]->(tag) RETURN tag And rea s
    59. 59. How do I query this graph? // lookup starting point in an index START user=node:User(name start n=node:People(name ==‘Andreas’) ‘Andreas’) MATCH (user)-[:HAS_SENT]->(tweet)-[:TAGGED_BY]->(tag) RETURN tag And rea s
    60. 60. 4
    61. 61. (Neo4j) -[:IS_A]-> (Graph Database)4
    62. 62. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database:4
    63. 63. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph4
    64. 64. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data4
    65. 65. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data - A Graph Database:4
    66. 66. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data - A Graph Database: - reliable with real ACID Transactions4
    67. 67. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data - A Graph Database: - reliable with real ACID Transactions - scalable: 34 billions nodes and relationships4
    68. 68. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data - A Graph Database: - reliable with real ACID Transactions - scalable: 34 billions nodes and relationships - fast with millons traversals / second4
    69. 69. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data - A Graph Database: - reliable with real ACID Transactions - scalable: 34 billions nodes and relationships - fast with millons traversals / second - Server with REST API, or Embeddable on the JVM4
    70. 70. (Neo4j) -[:IS_A]-> (Graph Database) - A Graph Database: - a schema-free Property Graph - perfect for complex, highly connected data - A Graph Database: - reliable with real ACID Transactions - scalable: 34 billions nodes and relationships - fast with millons traversals / second - Server with REST API, or Embeddable on the JVM - higher-performance with High-Availability (read scaling)4
    71. 71. (Cypher) -[:IS_A]-> (Graph Query Language) ๏ Declarative query language • Describe what you want, not how • Based on pattern matching ๏ Example: START tag=node:Tag(tag=”s12gx”), # index lookup MATCH sender-[:SENDER]->tweet-[:TAG]->tag WHERE new_friends.age > 18 RETURN sender.name, count(*) ORDER BY count(*) DESC LIMIT 104
    72. 72. (Neo4j) -[:LOVES]-> (Our Customers) 19
    73. 73. (Neo4j) -[:LOVES]-> (Our Customers) 19
    74. 74. Spring Data Neo4j
    75. 75. Spring Data Neo4j ๏ Spring Data: VMWare/SpringSource initiative to give Spring developers easy access to the emerging world of NOSQL ๏ Spring Data Neo4j is the integration library for Neo4j ๏ Simple programming model: annotation-based programming for applications with rich domains ๏ Always possible to drop down to core Neo4j-API ๏ simple and powerful repository abstraction ๏ two mapping modes ๏ Neo4j-Server support
    76. 76. Spring Data Neo4j features• Annotation-based programming model• Spring Data Commons Repository support• Neo4j Query and Traversal support – on dynamic fields and via repository methods• Neo4j indexing support (includes fulltext and numeric range queries)• Entity types stored in the graph database as well• Dynamic type projection (duck typing)• Cross-store support for partial JPA / graph entities• Support for JSR-303 (bean validation)• Support for the Neo4j Server (remote server and in server extension)• Neo4jTemplate with exception translation, optional transaction management and more 22
    77. 77. Classic Neo4j domain class public class Tag { private final Node underlyingNode; Tag( final Node node ) { underlyingNode = node; } public Node getUnderlyingNode() { return underlyingNode; } public final String getName() { return (String) underlyingNode.getProperty( “name” ); } public void setName( final String name ) { underlyingNode.setProperty( “name”, name ); } }
    78. 78. Spring Data Neo4j domain class @NodeEntity public class Tag { @GraphId private Long id; private String name; }
    79. 79. Spring Data Neo4j domain class @NodeEntity public class Tag { @GraphId private Long id; @Indexed(unique = true) private String name; }
    80. 80. Defining entity classes
    81. 81. Defining entity classes• @NodeEntity • Represents a node in the graph • Fields saved as properties on node • References stored as relationships between nodes • Instantiated using Java ‘new’ keyword, like any POJO • Also returned by lookup mechanisms • Type information stored in the graph
    82. 82. Defining entity classes
    83. 83. Defining entity classes• @RelationshipEntity • Represents a relationship in the graph • Fields saved as properties on relationship • Special fields for start- and end-nodes • Only returned by lookup methods
    84. 84. Tweet domain class @NodeEntity public class Tweet { @GraphId private Long id; @Indexed(unique=true) Long tweetId; String text; @Fetch User sender; // eager loading @RelatedTo(type="TAGGED") Collection<Tag> tags; @RelatedTo(type="MENTIONS") Set<User> mentions; @RelatedTo(type="SOURCE") Tweet source; }
    85. 85. Interface based Repositories• based on Repository infrastructure in Spring Data Commons• just define the interface and the namespace configuration• provide out-of-the-box support for –CRUD-Operations –Index-Lookups –Traversal-Execution –Annotated Graph-Queries (Cypher, Gremlin) –Derived Queries –Spatial Queries• extensible via custom methods with provided implementations 28
    86. 86. Repositoriesinterface TweetRepository extends GraphRepository<Tweet> { Tweet findByTweetId(String id); Collection<Tweet> findByTagsName(String name); @Query("start user=node({0}) match user<-[:SENDER]-tweet-[:TAGGED]->tag return distinct tag.name") Page<String> findUserTags(User user);}<neo4j:repositories base-package=“com.example.repositories„/>@Controllerpublic class TwitterController { @Autowired TweetRepository tweetRepository; @RequestMapping(value = "/tweet/{id}",...) public String show(Model model, @PathVariable String id) { Tweet tweet = tweetRepository.findByTweetId(id); model.addAttribute("tweet", tweet); return "/tweet/show"; }} 29
    87. 87. Neo4j-Template (I)• well known Spring Template Pattern• Resource / Transaction Management• Convenience Methods• Nodes and Entities handling & conversion• Fluent Query Result Handling• Works also via REST with Neo4j-Server• Exception Translation30
    88. 88. Neo4j-Server-Support <bean id="restGraphDatabaseService" class="org.sf.data.neo4j.rest.SpringRestGraphDatabase"> <constructor-arg value="http://localhost:7473/db/data" /> </bean> <neo4j:config graphDatabaseService="restGraphDatabaseService"/> • drop-in replacement for the embedded GraphDatabase • works transparently with POJO-Entity-Mapping and Neo4j-Template 31
    89. 89. Sample App -uses Spring Social (minimally) -Simple Domain: Tweets, Users, Tags -connected Entities -Repositories, Service -standalone App with -embedded Neo4j-Database -Neo4j-Server
    90. 90. Whiteboard friendly - Abstract :Tweet :Tweet
    91. 91. Whiteboard friendly - Abstract :User PO ST ED :Tweet :User :Tweet POSTED
    92. 92. Whiteboard friendly - Abstract :User PO ST ED :Tweet S ION NT ME :User :Tweet POSTED
    93. 93. Whiteboard friendly - Abstract :User PO ST ED TAGGED :Tag :Tweet TAGG ED :Tag S ION ED NT G ME G :User :Tweet TA POSTED
    94. 94. Whiteboard friendly - Example Attending the #S2GX #SDN session by @mesirii Looking forward to my #SDN session
    95. 95. Whiteboard friendly - Example @peterneubauer PO ST ED Attending the #S2GX #SDN session by @mesirii Looking forward to @mesirii POSTED my #SDN session
    96. 96. Whiteboard friendly - Example @peterneubauer PO ST ED Attending the #S2GX #SDN session by @mesirii S ION NT ME Looking forward to @mesirii POSTED my #SDN session
    97. 97. Whiteboard friendly - Example @peterneubauer PO ST ED Attending the TAGGED #S2GX #S2GX #SDN TAGG session by ED @mesirii #SDN S ION ED NT G ME Looking forward to TA G @mesirii POSTED my #SDN session
    98. 98. Twitter - Graph Data Model4
    99. 99. Spring Data Neo4j - Sample Domain Class & Service4
    100. 100. Neo4j - Sample Graph Query START tag1=node:Tag("tag:*obama*") > MATCH tag1<-[:TAG]-tweet-[:sender]->user, user<-[:sender]-tweet2-[:TAG]->tag2 > WHERE tag2.tag =~ "(?i).*romney.*" > RETURN count(*) as cnt, tag1.tag,tag2.tag +--------------------------------------+ > ORDER BY count(*) DESC | cnt | tag1.tag | tag2.tag | > LIMIT 10; +--------------------------------------+ | 440 | "obama" | "voteromney" | | 148 | "obama" | "romneyryan2012" | | 65 | "obama" | "romney" | | 56 | "voteobama" | "romneyryan" | | 42 | "voteobama" | "romney" | +--------------------------------------+ 5 rows 194 ms4
    101. 101. Neo4j - Twitter Sample App Code
    102. 102. Hubway Data Challenge - Import• Boston Bike Sharing Network• Import using Spring Data Neo4j• Visualization with Cypher & d3.js (Chord)http://bit.ly/neo_hubway 39
    103. 103. Cineasts.net - a social movie databaseCheck Out: http://spring.neo4j.org/tutorial
    104. 104. Spring Data Neo4j Guidebook “Good Relationships”“I’m excited about Spring Data Neo4j.... makes working with Neo4jamazingly easy, and therefore has the potential to make you more successfulas a developer.” Rod Johnson, founder of Spring- Spring Data Neo4j comes with a great Guide Book, featuring: - Forewords by Rod Johnson and Emil Eifrem - An easy to read, narrative tutorial walkthrough for cineasts.net - A comprehensive reference for all the details - Check it out: http://bit.ly/sd-book - Free e-book and printed
    105. 105. Spring Data Neo4j Guidebook “Good Relationships”“I’m excited about Spring Data Neo4j.... makes working with Neo4jamazingly easy, and therefore has the potential to make you more successfulas a developer.” Rod Johnson, founder of Spring- Spring Data Neo4j comes with a great Guide Book, featuring: - Forewords by Rod Johnson and Emil Eifrem - An easy to read, narrative tutorial walkthrough for cineasts.net - A comprehensive reference for all the details - Check it out: http://bit.ly/sd-book - Free e-book and printed
    106. 106. O‘Reilly Spring Data Book „Modern Data Access for Enterprise Java“ • book by the Spring Data project leads • introduction to Spring Data & SD-repositories • covers all subprojects • available in O‘Reilly OFPS and O‘Reilly store (e-book) • http://bit.ly/sd-book
    107. 107. How do I get started?4
    108. 108. How do I get started?๏ Documentation4
    109. 109. How do I get started?๏ Documentation • http://spring.neo4j.org4
    110. 110. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes4
    111. 111. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book4
    112. 112. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book • Good Relationships4
    113. 113. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book • Good Relationships๏ Get Neo4j4
    114. 114. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book • Good Relationships๏ Get Neo4j • http://neo4j.org/download4
    115. 115. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book • Good Relationships๏ Get Neo4j • http://neo4j.org/download๏ Participate • http://neo4j.org/forums • http://spring.neo4j.org/discussions4
    116. 116. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book • Good Relationships๏ Get Neo4j • http://neo4j.org/download๏ Participate • http://neo4j.org/forums • http://spring.neo4j.org/discussions • http://neo4j.meetup.com4
    117. 117. How do I get started?๏ Documentation • http://spring.neo4j.org • Dev-Notes • Spring Data Book • Good Relationships๏ Get Neo4j • http://neo4j.org/download๏ Participate • http://neo4j.org/forums • http://spring.neo4j.org/discussions • http://neo4j.meetup.com • a session like this one ;)4
    118. 118. GraphConnect Nov 6th 2012 San Francisco 50% dis CONNECT ABOUT | UPCOMING EVENTS | cou REGISTRATION | CONTACT nt a t our boo th WORLD’S LEADING GRAPH CONFERENCE SAN FRANCISCO 20124
    119. 119. Thank you ! Questions ?4

    ×