1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.connector.store.jpa.model.simple;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.NamedQueries;
32 import javax.persistence.NamedQuery;
33 import javax.persistence.Table;
34 import org.hibernate.annotations.Index;
35
36
37
38
39
40
41 @Entity
42 @org.hibernate.annotations.Table( appliesTo = "MODE_SUBGRAPH_NODES", indexes = @Index( name = "QUERYID_INX", columnNames = {
43 "QUERY_ID", "UUID", "DEPTH"} ) )
44 @Table( name = "MODE_SUBGRAPH_NODES" )
45 @NamedQueries( {
46 @NamedQuery( name = "SubgraphNodeEntity.insertChildren", query = "insert into SubgraphNodeEntity(queryId,nodeUuid,depth,parentIndexInParent,indexInParent) select parentNode.queryId, child.nodeUuidString, parentNode.depth+1, parentNode.indexInParent, child.indexInParent from NodeEntity child, SubgraphNodeEntity parentNode where child.workspaceId = :workspaceId and child.parent.nodeUuidString = parentNode.nodeUuid and parentNode.queryId = :queryId and parentNode.depth = :parentDepth" ),
47 @NamedQuery( name = "SubgraphNodeEntity.getCount", query = "select count(*) from SubgraphNodeEntity where queryId = :queryId" ),
48 @NamedQuery( name = "SubgraphNodeEntity.getNodeEntitiesWithLargeValues", query = "select props from NodeEntity props, SubgraphNodeEntity node where props.workspaceId = :workspaceId and props.nodeUuidString = node.nodeUuid and node.queryId = :queryId and node.depth >= :depth and size(props.largeValues) > 0" ),
49 @NamedQuery( name = "SubgraphNodeEntity.getChildEntities", query = "select child from NodeEntity child, SubgraphNodeEntity node where child.workspaceId = :workspaceId and child.nodeUuidString = node.nodeUuid and node.queryId = :queryId and node.depth >= :depth and node.depth <= :maxDepth order by node.depth, node.parentIndexInParent, node.indexInParent" ),
50
51
52
53
54
55
56
57
58
59 @NamedQuery( name = "SubgraphNodeEntity.clearParentReferences", query = "update NodeEntity child set child.parent = null where child.workspaceId = :workspaceId and child.nodeUuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId and node.depth >= :depth )" ),
60 @NamedQuery( name = "SubgraphNodeEntity.deleteChildEntities", query = "delete NodeEntity child where child.workspaceId = :workspaceId and child.nodeUuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId and node.depth >= :depth )" ),
61
62
63
64 @NamedQuery( name = "SubgraphNodeEntity.deleteByQueryId", query = "delete SubgraphNodeEntity where queryId = :queryId" )} )
65 public class SubgraphNodeEntity {
66
67 @Id
68 @Column( name = "ID" )
69 @GeneratedValue( strategy = GenerationType.AUTO )
70 private Long id;
71
72 @Column( name = "QUERY_ID", nullable = false, unique = false, updatable = false )
73 private Long queryId;
74
75 @Column( name = "UUID", updatable = false, nullable = false, length = 36 )
76 private String nodeUuid;
77
78 @Column( name = "DEPTH", updatable = false, nullable = false )
79 private int depth;
80
81 @Column( name = "PARENT_NUM", updatable = false, nullable = false )
82 private int parentIndexInParent;
83
84 @Column( name = "CHILD_NUM", updatable = false, nullable = false )
85 private int indexInParent;
86
87 public SubgraphNodeEntity() {
88 }
89
90 public SubgraphNodeEntity( Long queryId,
91 String nodeUuid,
92 int depth ) {
93 this.queryId = queryId;
94 this.nodeUuid = nodeUuid;
95 this.depth = depth;
96 }
97
98
99
100
101 public Long getId() {
102 return id;
103 }
104
105
106
107
108 public int getDepth() {
109 return depth;
110 }
111
112
113
114
115 public String getNodeUuid() {
116 return nodeUuid;
117 }
118
119
120
121
122 public Long getQueryId() {
123 return queryId;
124 }
125
126
127
128
129 public int getIndexInParent() {
130 return indexInParent;
131 }
132
133
134
135
136 public int getParentIndexInParent() {
137 return parentIndexInParent;
138 }
139
140
141
142
143
144
145 @Override
146 public int hashCode() {
147 return id != null ? id.intValue() : 0;
148 }
149
150
151
152
153
154
155 @Override
156 public boolean equals( Object obj ) {
157 if (obj == this) return true;
158 if (obj instanceof SubgraphNodeEntity) {
159 SubgraphNodeEntity that = (SubgraphNodeEntity)obj;
160 if (this.id.equals(that.id)) return true;
161 }
162 return false;
163 }
164
165
166
167
168
169
170 @Override
171 public String toString() {
172 return "" + id + " - Query " + queryId + "; depth=" + depth + "; node=" + nodeUuid + " at index " + indexInParent;
173 }
174
175 }