2. 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) ?
3. 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
12. Science
Biology
Chemistry
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
13. Science
Biology
Work
Friends
Neighbor
Family Chemistry
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
14. Computers
Internet
Science
Biology
Work
Friends
Neighbor
Family Chemistry
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
15. Devices
Users
Software
Networks
Services
Computers
Internet
Science
Biology
Work
Friends
Neighbor
Family Chemistry
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
16. Devices
Users
Software
Networks
Services
Computers
Internet
Business Science
Biology
Work
Friends
Neighbor
Family Chemistry
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
17. Devices
Users
Software
Networks
Services
Computers
Internet
Business Science
ERP Biology
Work Geo
Friends
Retail
Neighbor
Family
Cloud Chemistry
Travel
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
18. Devices
Users
Software
Networks
Services
Computers
Internet
Art
Business Science
ERP Biology
Work Geo
Friends
Retail
Neighbor
Family
Cloud Chemistry
Travel
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
19. Devices Stories
Users
Software Creativity
Visuals
Networks
Services
Computers
Internet
Art
Business Science
ERP Biology
Work Geo
Friends
Retail
Neighbor
Family
Cloud Chemistry
Travel
Proteins
Reactions
Politics Environments
7
6 Genes
Society History
27. Java
N
D _I
N TE
E ME
PL
IM
Server RUN
S_A
S
Ruby
JS
S
_A
Python Java
NS
.net
RU
Spring
embedded
10
28. Java
N
D _I
N TE
E ME
PL
IM
Server RUN
S_A
S
Ruby
RU
JS
S
_A
NS
Python Java
_O
NS
.net
RU
N
Spring
embedded Heroku
10
29. Java
N
D _I
N TE
E ME
PL
IM
PROVIDES ACID
Server RUN
S_A
TX
S
Ruby
RU
JS
S
_A
NS
Python Java
_O
NS
.net
RU
N
Spring
embedded Heroku
10
30. 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
Ruby
RU
JS
S
_A
NS
Python Java
_O
NS
.net
RU
N
Spring
embedded Heroku
10
31. 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
O
Ruby
RU
ES_T
JS
S
_A
NS
Python Java
_O
NS
SC AL
.net
RU
N
Spring
34bn
embedded Heroku
Nodes 10
32. 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
O
Ruby
RU
ES_T
JS
S
_A
NS
Python Java
_O
NS
SC AL
.net
RU
N
Spring
34bn
embedded Heroku
Nodes 10
33. 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
O
Ruby
RU
ES_T
JS
S
_A
NS
Python Java
_O
NS
SC AL
.net
RU
N
Spring
34bn
embedded Heroku
Nodes 10
34. 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
O
Ruby
RU
E
ES_T
JS
MySQL
S
_A
NS
Python Java
_O
NS
SC AL
.net
RU
N
Spring
Mongo
34bn
embedded Heroku
Nodes 10
37. Whiteboard it - abstract
:User
PO
ST
ED
:Tweet
:User :Tweet
POSTED
38. Whiteboard it - abstract
:User
PO
ST
ED
TAGGED
:Tag
:Tweet TAGG
ED
:Tag
ED
G
AG
:User :Tweet T
POSTED
39. Whiteboard it - abstract
:User
PO
ST
ED
TAGGED
:Tag
:Tweet TAGG
ED
:Tag
NS
O ED
TI G
MEN AG
:User :Tweet T
POSTED
40. Whiteboard friendly - example
Attending the
#SDN #Neo4j
webinar by
@mesirii
Looking forward
to my #SDN webinar
41. Whiteboard friendly - example
@peterneubauer
PO
ST
ED
Attending the
#SDN #Neo4j
webinar by
@mesirii
Looking forward
@mesirii to my #SDN webinar
POSTED
42. 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
43. 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
44. 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
46. 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
47. 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
48. 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 getTag() {
return (String) underlyingNode.getProperty( “tag” );
}
public void setTag( final String tag ) {
underlyingNode.setProperty( “tag”, tag );
}
}
49. Spring Data Neo4j domain class
@NodeEntity
public class Tag {
@GraphId private Long id;
private String tag;
}
50. Spring Data Neo4j domain class
@NodeEntity
public class Tag {
@GraphId private Long id;
@Indexed(unique = true)
private String tag;
}
52. 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
54. 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
55. 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;
}
56. Compare to Core-API approach
@NodeEntity
class 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
57. 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
59. 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
60. 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
62. 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
63. Spring Data Neo4j Guidebook
“Good Relationships”
“I’m excited about Spring Data Neo4j.... Spring Data Neo4j makes working
with Neo4j amazingly easy, and therefore has the potential to make you
more 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
65. 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
66. 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 nc
GR AP a
n FrRegency
Sa tt
Hya
Presented by
33
67. 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
68. Thank You!
Feel free to reach out with questions on
•Twitter,
•Spring-Forums,
•Neo4j-Google-Group
•Stack-Overflow
35
Editor's Notes
\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