1
+ package org .soujava .demos .arangodb .graph ;
2
+
3
+
4
+ import jakarta .enterprise .inject .se .SeContainer ;
5
+ import jakarta .enterprise .inject .se .SeContainerInitializer ;
6
+ import org .eclipse .jnosql .databases .tinkerpop .mapping .GraphTemplate ;
7
+
8
+ import java .util .List ;
9
+
10
+ import static org .apache .tinkerpop .gremlin .process .traversal .P .between ;
11
+ import static org .apache .tinkerpop .gremlin .process .traversal .P .gte ;
12
+ import static org .soujava .demos .arangodb .graph .Person .builder ;
13
+
14
+ public final class MarketingApp {
15
+
16
+
17
+ private MarketingApp () {
18
+ }
19
+
20
+ public static void main (String [] args ) {
21
+
22
+ try (SeContainer container = SeContainerInitializer .newInstance ().initialize ()) {
23
+ GraphTemplate graph = container .select (GraphTemplate .class ).get ();
24
+
25
+ Person banner = graph .insert (builder ().withAge (30 ).withName ("Banner" )
26
+ .withOccupation ("Developer" ).withSalary (3_000D ).build ());
27
+
28
+ Person natalia = graph .insert (builder ().withAge (32 ).withName ("Natalia" )
29
+ .withOccupation ("Developer" ).withSalary (5_000D ).build ());
30
+
31
+ Person rose = graph .insert (builder ().withAge (40 ).withName ("Rose" )
32
+ .withOccupation ("Design" ).withSalary (1_000D ).build ());
33
+
34
+ Person tony = graph .insert (builder ().withAge (22 ).withName ("tony" )
35
+ .withOccupation ("Developer" ).withSalary (4_500D ).build ());
36
+
37
+
38
+ graph .edge (tony , "knows" , rose ).add ("feel" , "love" );
39
+ graph .edge (tony , "knows" , natalia );
40
+
41
+ graph .edge (natalia , "knows" , rose );
42
+ graph .edge (banner , "knows" , rose );
43
+
44
+ List <Person > developers = graph .traversalVertex ()
45
+ .has ("salary" , gte (3_000D ))
46
+ .has ("age" , between (20 , 25 ))
47
+ .has ("occupation" , "Developer" )
48
+ .<Person >result ().toList ();
49
+
50
+ List <Person > peopleWhoDeveloperKnows = graph .traversalVertex ()
51
+ .has ("salary" , gte (3_000D ))
52
+ .has ("age" , between (20 , 25 ))
53
+ .has ("occupation" , "Developer" )
54
+ .out ("knows" )
55
+ .<Person >result ().toList ();
56
+
57
+ List <Person > both = graph .traversalVertex ()
58
+ .has ("salary" , gte (3_000D ))
59
+ .has ("age" , between (20 , 25 ))
60
+ .has ("occupation" , "Developer" )
61
+ .outE ("knows" )
62
+ .bothV ()
63
+ .<Person >result ()
64
+ .distinct ()
65
+ .toList ();
66
+
67
+ List <Person > couple = graph .traversalVertex ()
68
+ .has ("salary" , gte (3_000D ))
69
+ .has ("age" , between (20 , 25 ))
70
+ .has ("occupation" , "Developer" )
71
+ .outE ("knows" )
72
+ .has ("feel" , "love" )
73
+ .bothV ()
74
+ .<Person >result ()
75
+ .distinct ()
76
+ .toList ();
77
+
78
+ System .out .println ("Developers has salary greater than 3000 and age between 20 and 25: " + developers );
79
+ System .out .println ("Person who the Developers target know: " + peopleWhoDeveloperKnows );
80
+ System .out .println ("The person and the developers target: " + both );
81
+ System .out .println ("Developers to Valentine days: " + couple );
82
+
83
+ }
84
+ }
85
+
86
+ }
0 commit comments