7
|
1 package models;
|
|
2
|
8
|
3 import scala.reflect.generic.Trees.This;
|
|
4
|
7
|
5 import com.tinkerpop.blueprints.Graph;
|
|
6 import com.tinkerpop.blueprints.Vertex;
|
|
7 import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
|
|
8
|
|
9 public class TPGraph {
|
|
10
|
|
11 private static TPGraph instance = new TPGraph();
|
|
12 private Object claimRootId;
|
|
13 private Object userRootId;
|
|
14
|
8
|
15 protected final String CHILD = "child";
|
|
16
|
7
|
17 private TPGraph() {
|
|
18
|
|
19 }
|
|
20
|
|
21 public static TPGraph getInstance() {
|
|
22 return instance;
|
|
23 }
|
|
24
|
|
25 private Graph graph;
|
|
26 private String path = null;
|
|
27
|
|
28 public void setPath(String path) {
|
|
29 this.path = path;
|
|
30 }
|
|
31
|
|
32 public Graph newGraph() {
|
|
33 if (path == null) {
|
|
34 graph = new TinkerGraph();
|
|
35 } else {
|
|
36 graph = new TinkerGraph(path);
|
|
37
|
|
38 }
|
|
39 return graph;
|
|
40 }
|
|
41
|
|
42 public Graph getGraph() {
|
|
43 return graph;
|
|
44 }
|
|
45
|
8
|
46 public void setClaimRootId(Object id) {
|
|
47 this.claimRootId = id;
|
7
|
48 }
|
|
49
|
8
|
50 public void setUserRootId(Object id) {
|
|
51 this.userRootId = id;
|
7
|
52 }
|
|
53
|
8
|
54 public Object getUserRootId() {
|
|
55 return userRootId;
|
|
56 }
|
|
57
|
|
58 public Vertex getClaimRootVertex() {
|
|
59 return graph.getVertex(userRootId);
|
7
|
60 }
|
|
61
|
8
|
62 public Vertex getUserRootVertex() {
|
|
63 return graph.getVertex(userRootId);
|
7
|
64 }
|
8
|
65
|
|
66 public void setLabelToRootUser(UserModel user) {
|
|
67 Vertex rootUser = getUserRootVertex();
|
|
68
|
|
69 /*
|
|
70 * rootUser ---child---> newUser
|
|
71 */
|
|
72 graph.addEdge(null, rootUser, user.getVertex(), CHILD);
|
|
73 }
|
|
74
|
|
75
|
7
|
76
|
|
77 public void shutdownGraph() {
|
|
78 graph.shutdown();
|
|
79 }
|
|
80
|
8
|
81
|
|
82
|
|
83
|
7
|
84
|
|
85
|
|
86 }
|