Intro to Spring Data Neo4j
Upcoming SlideShare
Loading in...5
×
 

Intro to Spring Data Neo4j

on

  • 6,309 views

These webinar slides provide a quick tour through graphs, graph databases, neo4j and spring data neo4j. The example app discussed is a twitter-graph.

These webinar slides provide a quick tour through graphs, graph databases, neo4j and spring data neo4j. The example app discussed is a twitter-graph.

Statistics

Views

Total Views
6,309
Views on SlideShare
5,609
Embed Views
700

Actions

Likes
1
Downloads
121
Comments
2

9 Embeds 700

http://blog.neo4j.org 527
http://www.springsource.org 77
http://localhost 56
http://www.neo4j.org.cn 33
http://5194400562660165576_4132686ef8fb8af872d8b2e720e47fbd594168c4.blogspot.com 2
https://twitter.com 2
http://neo4j.baobei.us 1
https://twimg0-a.akamaihd.net 1
http://www.linkedin.com 1
More...

Accessibility

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • Please excuse my hayfever\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Neo4j is a graph database. \n\nNodes, rels, key-value props on nodes and rels.\n
  • Neo4j is a graph database. \n\nNodes, rels, key-value props on nodes and rels.\n
  • Poll: Your exposure to Neo4j\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Poll: Your exposure to Neo4j\n
  • evolve data separately\n
  • evolve data separately\n
  • evolve data separately\n
  • evolve data separately\n
  • evolve data separately\n
  • evolve data separately\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

Intro to Spring Data Neo4j Intro to Spring Data Neo4j Presentation Transcript

  • Spring Data Neo4j 2.1 IntroductionMichael Hunger, Neo Technology
  • Me & You ? ๏ Me: Michael Hunger, Neo Technology • Neo4j Community Team • Spring Data Neo4j Project Lead • Neo4j Cloud Hosting • michael.hunger@neotechnology.com / @mesirii ๏ You: • Java & Spring ! • Enterprise ? • NOSQL ? • Cloud (CF, Heroku) ?
  • About the Webinar ๏ Graphs are EveryWhere ๏ Graph Database ๏ Intro Neo4j ๏ Sample App - Twitter Graph • Domain Model • Code ๏ Resources, Books, GraphConnect ๏ Questions answered during webinar and Q & A at the end ๏ All your questions will be answered in a follow up blog post, don‘t hesitate to ask
  • To become part of todays Twitter-Graph
  • To become part of todays Twitter-Graphplease tweet with #neo4j #sdn
  • To become part of todays Twitter-Graphplease tweet with #neo4j #sdn •your attendance •questions •remarks •....
  • Graphs areeverywhere 5
  • 76
  • Science76
  • ScienceBiologyChemistry 7 6
  • ScienceBiologyChemistry Proteins Reactions Environments 7 6 Genes
  • Science Biology Chemistry Proteins Reactions Politics Environments 7 6 GenesSociety History
  • Science Biology Work FriendsNeighbor Family Chemistry Proteins Reactions Politics Environments 7 6 Genes Society History
  • Computers Internet Science Biology Work FriendsNeighbor Family Chemistry Proteins Reactions Politics Environments 7 6 Genes Society History
  • Devices Users Software Networks Services Computers Internet Science Biology Work FriendsNeighbor Family Chemistry Proteins Reactions Politics Environments 7 6 Genes Society History
  • Devices Users Software Networks Services Computers Internet Business Science Biology Work FriendsNeighbor Family Chemistry Proteins Reactions Politics Environments 7 6 Genes Society History
  • Devices Users Software Networks Services Computers Internet Business Science ERP Biology Work Geo Friends RetailNeighbor Family Cloud Chemistry Travel Proteins Reactions Politics Environments 7 6 Genes Society History
  • Devices Users Software Networks Services Computers Internet Art Business Science ERP Biology Work Geo Friends RetailNeighbor Family Cloud Chemistry Travel Proteins Reactions Politics Environments 7 6 Genes Society History
  • Devices Stories Users Software Creativity Visuals Networks Services Computers Internet Art Business Science ERP Biology Work Geo Friends RetailNeighbor Family Cloud Chemistry Travel Proteins Reactions Politics Environments 7 6 Genes Society History
  • A Graph Database Node Node
  • A Graph Database Typed relationship Node Node
  • A Graph Database Typed relationship Node Node key: value key: value
  • Neo4j Intro
  • 9
  • 10
  • Java N D _I N TE E ME PL IM10
  • Java N D _I N TE E ME PL IM Server RUN S_A SRuby JS S _APython Java NS .net RUSpring embedded 10
  • Java N D _I N TE E ME PL IM Server RUN S_A SRuby RU JS S _A NSPython Java _O NS .net RU NSpring embedded Heroku 10
  • Java N D _I N TE E ME PL IM PROVIDES ACID Server RUN S_A TX SRuby RU JS S _A NSPython Java _O NS .net RU NSpring embedded Heroku 10
  • Java Lucene N D _I TE Index N ME ES E T PL RA G IM TE IN PROVIDES ACID Server RUN S_A TX SRuby RU JS S _A NSPython Java _O NS .net RU NSpring embedded Heroku 10
  • Java Lucene N D _I TE Index N ME ES E T PL RA G IM TE IN PROVIDES ACID Server RUN S_A TX S ORuby RU ES_T JS S _A NSPython Java _O NS SC AL .net RU NSpring 34bn embedded Heroku Nodes 10
  • Java Lucene 1 M/s N D _I TE Index N ALS ME ES VERS E T PL RA G IM TE TRA IN PROVIDES ACID Server RUN S_A TX S ORuby RU ES_T JS S _A NSPython Java _O NS SC AL .net RU NSpring 34bn embedded Heroku Nodes 10
  • Java Lucene 1 M/s Master/ N D _I Slave TE Index N ALS ME HIG H_A ES VERS E VA T PL IL. RA G IM TE TRA IN PROVIDES ACID Server RUN S_A TX S ORuby RU ES_T JS S _A NSPython Java _O NS SC AL .net RU NSpring 34bn embedded Heroku Nodes 10
  • Java Lucene 1 M/s Master/ N D _I Slave TE Index N ALS ME HIG H_A ES VERS E VA T PL IL. RA G IM TE TRA IN PROVIDES ACID Server RUN S_A LI CE TX S NS ED _L IK ORuby RU E ES_T JS MySQL S _A NSPython Java _O NS SC AL .net RU NSpring Mongo 34bn embedded Heroku Nodes 10
  • IntroducingThe Twitter-Graph Domain Model
  • Whiteboard it - abstract :Tweet :Tweet
  • Whiteboard it - abstract :User PO ST ED :Tweet :User :Tweet POSTED
  • Whiteboard it - abstract :User PO ST ED TAGGED :Tag :Tweet TAGG ED :Tag ED G AG :User :Tweet T POSTED
  • Whiteboard it - abstract :User PO ST ED TAGGED :Tag :Tweet TAGG ED :Tag NS O ED TI G MEN AG :User :Tweet T POSTED
  • Whiteboard friendly - example Attending the #SDN #Neo4j webinar by @mesirii Looking forward to my #SDN webinar
  • Whiteboard friendly - example @peterneubauer PO ST ED Attending the #SDN #Neo4j webinar by @mesirii Looking forward@mesirii to my #SDN webinar POSTED
  • Whiteboard friendly - example @peterneubauer PO ST ED TAGGED #Neo4j Attending the #SDN #Neo4j TAGG webinar by ED @mesirii #SDN ED G Looking forward TAG@mesirii to my #SDN webinar POSTED
  • Whiteboard friendly - example @peterneubauer PO ST ED TAGGED #Neo4j Attending the #SDN #Neo4j TAGG webinar by ED @mesirii #SDN NS O ED TI G MEN Looking forward TAG@mesirii to my #SDN webinar POSTED
  • Cypher Query Language๏ Declarative query language • Describe what you want, not how • Based on pattern matching๏ Examples: START peter=node:User(userName=”peterneubauer”) # index lookup MATCH peter-[:POSTED]->tweet-[:MENTIONS]->user WHERE user.country = ”SE” and not peter-[:FOLLOWS]-user RETURN user START tag=node:Tag(tag = ”Neo4j”) MATCH tag<-[:TAGGED]-tweet-[:TAGGED]->co_tag RETURN co_tag.tag, COUNT(*) as cnt ORDER cnt DESC LIMIT 10 14
  • Spring Data Neo4j 2.1
  • Spring Data๏ Spring Data: VMWare/SpringSource initiative to give Spring developers easy access to the emerging world of NOSQL๏ Build on top of common infrastructure๏ Spring Data Neo4j is the integration library for Neo4j๏ http://springsource.org/spring-data๏ Support for other NOSQL approaches • Redis • MongoDB • Hadoop • GemFire
  • Spring Data Neo4j ๏ The brain child of Rod Johnson & Emil Eifrém • Wrote functional initial prototype • Developed by Neo Technology and SpringSource teams ๏ Uses annotations to define graph entities ๏ Entity state backed by graph database ๏ Two modes of Object Graph Mapping • simple POJO Graph Mapping • advanced, seamless AspectJ backed Mapping ๏ SD-Repositories support ๏ Neo4j Server Support
  • Classic Neo4j domain classpublic class Tag { private final Node underlyingNode; Tag( final Node node ) { underlyingNode = node; } public Node getUnderlyingNode() { return underlyingNode; } public final String getTag() { return (String) underlyingNode.getProperty( “tag” ); } public void setTag( final String tag ) { underlyingNode.setProperty( “tag”, tag ); }}
  • Spring Data Neo4j domain class@NodeEntitypublic class Tag { @GraphId private Long id; private String tag;}
  • Spring Data Neo4j domain class@NodeEntitypublic class Tag { @GraphId private Long id; @Indexed(unique = true) private String tag;}
  • Defining entity classes
  • 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
  • Defining entity classes
  • 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
  • Tweet domain class@NodeEntitypublic 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;}
  • Compare to Core-API approach@NodeEntityclass Tweet { ... public Collecti on<Tag> getTags final List<Tag> () { tags = new Link for ( Relations edList<Tag>(); hip rel : under RelTypes.TAGGED lyingNode.getRe , Direction.OUT lationships( movies.add( new GOING ) ) { Tag( rel.getEnd Old } Node() ) ); return tags; } @RelatedTo(type="TAGGED") gs; New private Collection<Tag> ta
  • 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 24
  • Repositoriesinterface TweetRepository extends GraphRepository<Tweet> { Tweet findByTweetId(String id); Collection<Tweet> findByTagsTag(String tag);}<neo4j:repositories base-package=“org.neo4j.twitter_graph.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"; }} 25
  • 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 Translation 26
  • REST-Client-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 27
  • Coding the Twitter-Graph 28
  • Todays Coding Exercise๏ uses Spring Social (minimally)๏ Simple Domain: Tweets, Users, Tags • connected Entities • Repositories, Service๏ standalone App with • embedded Neo4j-Database • (local Neo4j-Server) 29
  • Spring Data Neo4j Guidebook “Good Relationships”“I’m excited about Spring Data Neo4j.... Spring Data Neo4j makes workingwith Neo4j amazingly easy, and therefore has the potential to make youmore successful as a developer.” Rod Johnson, founder of Spring๏ Spring Data Neo4j comes with a great Guide Book, featuring: • Forewords by Rod Johnson and Emil Eifrem • Ancineasts.net narrative tutorial walkthrough for easy to read, • A comprehensive reference for all the details • Check it out: http://bit.ly/sdn-book • Free e-book and printed 30
  • http://cineasts.net Check Out: http://spring.neo4j.org/tutorial
  • O‘Reilly Spring Data Book „Modern Data Access for Enterprise Java“ • upcoming 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-ofps 32
  • y wh ere ver ect e E onn s Ar aph .Share. 2 Gr ate C v no , 201 In ber 5-6 CT NEisco No vem HCON ncGR AP a n FrRegency Sa tt Hya Presented by 33
  • Continue here ๏ See the Spring Data Neo4j site for more info: http://spring.neo4j.org ๏ Again, don’t miss our guidebook on Spring Data Neo4j published by InfoQ also printed http://bit.ly/sdn-book ๏ All about Neo4j: ๏ local Neo4j meetup groups http://neo4j.org http://neo4j.meetup.com ๏ Neo4j & SDN videos and webinars: http://video.neo4j.org ๏ Spring Data Forum at http://spring.neo4j.org/discussions ๏ Neo4j Google Group • http://neo4j.org/forums
  • Thank You!Feel free to reach out with questions on•Twitter,•Spring-Forums,•Neo4j-Google-Group•Stack-Overflow 35