Skip to content

Commit 7c4955c

Browse files
committedJan 2, 2025·
chore: update person structure
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
1 parent 836ca75 commit 7c4955c

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package org.soujava.demos.arangodb.graph;
2+
3+
4+
import jakarta.nosql.Column;
5+
import jakarta.nosql.Entity;
6+
import jakarta.nosql.Id;
7+
8+
import java.util.Objects;
9+
10+
11+
@Entity
12+
public class Person {
13+
14+
@Id
15+
private String id;
16+
17+
@Column
18+
private String name;
19+
20+
@Column
21+
private int age;
22+
23+
@Column
24+
private String occupation;
25+
26+
@Column
27+
private Double salary;
28+
29+
30+
public String getId() {
31+
return id;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
39+
public int getAge() {
40+
return age;
41+
}
42+
43+
/**
44+
* @deprecated default constructor
45+
*/
46+
Person() {
47+
}
48+
49+
Person(String name, int age, String occupation, Double salary) {
50+
this.name = name;
51+
this.age = age;
52+
this.salary = salary;
53+
this.occupation = occupation;
54+
}
55+
56+
@Override
57+
public boolean equals(Object o) {
58+
if (this == o) {
59+
return true;
60+
}
61+
if (!(o instanceof Person person)) {
62+
return false;
63+
}
64+
return Objects.equals(id, person.id);
65+
}
66+
67+
@Override
68+
public int hashCode() {
69+
return Objects.hashCode(id);
70+
}
71+
72+
@Override
73+
public String toString() {
74+
return "Person{" + "id=" + id +
75+
", name='" + name + '\'' +
76+
", age=" + age +
77+
", occupation='" + occupation + '\'' +
78+
", salary=" + salary +
79+
'}';
80+
}
81+
82+
public static PersonBuilder builder() {
83+
return new PersonBuilder();
84+
}
85+
86+
public static class PersonBuilder {
87+
88+
private String name;
89+
90+
private int age;
91+
92+
private String occupation;
93+
94+
private Double salary;
95+
96+
97+
public PersonBuilder withName(String name) {
98+
this.name = name;
99+
return this;
100+
}
101+
102+
public PersonBuilder withAge(int age) {
103+
this.age = age;
104+
return this;
105+
}
106+
107+
public PersonBuilder withOccupation(String occupation) {
108+
this.occupation = occupation;
109+
return this;
110+
}
111+
112+
public PersonBuilder withSalary(Double salary) {
113+
this.salary = salary;
114+
return this;
115+
}
116+
117+
public Person build() {
118+
return new Person(name, age, occupation, salary);
119+
}
120+
}
121+
122+
}

0 commit comments

Comments
 (0)
Please sign in to comment.