Biblioteca Java - Blame information for rev 18
Subversion Repositories:
(root)/Frameworks and Technologies/Neo4J Samples/Neo4JTutorial/src/main/java/com/linkscreens/graphsin/repository/AlbumNode.java
Rev | Author | Line No. | Line |
---|---|---|---|
18 | mihai | 1 | package com.linkscreens.graphsin.repository; |
2 | import org.neo4j.graphdb.GraphDatabaseService; | ||
3 | import org.neo4j.graphdb.Node; | ||
4 | import org.neo4j.graphdb.Path; | ||
5 | import org.neo4j.graphdb.traversal.Evaluators; | ||
6 | import org.neo4j.graphdb.traversal.TraversalDescription; | ||
7 | import org.neo4j.graphdb.traversal.Traverser; | ||
8 | import org.neo4j.graphdb.traversal.Uniqueness; | ||
9 | import org.neo4j.helpers.collection.IterableWrapper; | ||
10 | |||
11 | |||
12 | public class AlbumNode { | ||
13 | public static final String TITLE = "title"; | ||
14 | public static final String ID = "id"; | ||
15 | |||
16 | private final Node underlyingNode; | ||
17 | |||
18 | public AlbumNode( Node album) { | ||
19 | this.underlyingNode = album; | ||
20 | } | ||
21 | |||
22 | private GraphDatabaseService graphDb() | ||
23 | { | ||
24 | return underlyingNode.getGraphDatabase(); | ||
25 | } | ||
26 | |||
27 | protected Node getUnderlyingNode() | ||
28 | { | ||
29 | return underlyingNode; | ||
30 | } | ||
31 | |||
32 | public String getId(){ | ||
33 | return (String)underlyingNode.getProperty( ID ); | ||
34 | } | ||
35 | |||
36 | public String getTitle() | ||
37 | { | ||
38 | return (String)underlyingNode.getProperty( TITLE ); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public int hashCode() | ||
43 | { | ||
44 | return underlyingNode.hashCode(); | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public boolean equals( Object o ) | ||
49 | { | ||
50 | return o instanceof AlbumNode && | ||
51 | underlyingNode.equals( ( (AlbumNode)o ).getUnderlyingNode() ); | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | public String toString() | ||
56 | { | ||
57 | return "Album[" + getTitle() + "]"; | ||
58 | } | ||
59 | |||
60 | private IterableWrapper<MediaItemNode, Path> createCreateMediaItemsFromPath( | ||
61 | Traverser iterableToWrap ) | ||
62 | { | ||
63 | return new IterableWrapper<MediaItemNode, Path>( iterableToWrap ) | ||
64 | { | ||
65 | @Override | ||
66 | protected MediaItemNode underlyingObjectToObject( Path path ) | ||
67 | { | ||
68 | return new MediaItemNode( path.endNode() ); | ||
69 | } | ||
70 | }; | ||
71 | } | ||
72 | |||
73 | public void addMediaItemInAlbum(MediaItemNode item){ | ||
74 | underlyingNode.createRelationshipTo( item.getUnderlyingNode(), RelTypes.HAS_MEDIAITEM ); | ||
75 | } | ||
76 | |||
77 | public Iterable<MediaItemNode> getMediaItems(){ | ||
78 | TraversalDescription travDesc = graphDb().traversalDescription() | ||
79 | .breadthFirst() | ||
80 | .relationships( RelTypes.HAS_MEDIAITEM ) | ||
81 | .uniqueness( Uniqueness.NODE_GLOBAL ) | ||
82 | .evaluator( Evaluators.toDepth( 1 ) ) | ||
83 | .evaluator( Evaluators.excludeStartPosition() ); | ||
84 | |||
85 | return createCreateMediaItemsFromPath( travDesc.traverse( underlyingNode ) ); | ||
86 | |||
87 | } | ||
88 | |||
89 | |||
90 | } |