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.basic;
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 @Table( name = "DNA_SUBGRAPH_NODES" )
43 @org.hibernate.annotations.Table( appliesTo = "DNA_SUBGRAPH_NODES", indexes = @Index( name = "QUERYID_INX", columnNames = {
44 "QUERY_ID", "UUID"} ) )
45 @NamedQueries( {
46 @NamedQuery( name = "SubgraphNodeEntity.insertChildren", query = "insert into SubgraphNodeEntity(queryId,nodeUuid,depth,parentIndexInParent,indexInParent) select parentNode.queryId, child.id.childUuidString, parentNode.depth+1, parentNode.indexInParent, child.indexInParent from ChildEntity child, SubgraphNodeEntity parentNode where child.id.workspaceId = :workspaceId and child.parentUuidString = 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.getPropertiesEntities", query = "select props from PropertiesEntity props, SubgraphNodeEntity node where props.id.workspaceId = :workspaceId and props.id.uuidString = node.nodeUuid and node.queryId = :queryId and node.depth >= :depth and node.depth <= :maxDepth order by node.depth, node.parentIndexInParent, node.indexInParent" ),
49 @NamedQuery( name = "SubgraphNodeEntity.getPropertiesEntitiesWithLargeValues", query = "select props from PropertiesEntity props, SubgraphNodeEntity node where props.id.workspaceId = :workspaceId and props.id.uuidString = node.nodeUuid and node.queryId = :queryId and node.depth >= :depth and size(props.largeValues) > 0" ),
50 @NamedQuery( name = "SubgraphNodeEntity.getChildEntities", query = "select child from ChildEntity child, SubgraphNodeEntity node where child.id.workspaceId = :workspaceId and child.id.childUuidString = node.nodeUuid and node.queryId = :queryId and node.depth >= :depth and node.depth <= :maxDepth order by node.depth, node.parentIndexInParent, node.indexInParent" ),
51 @NamedQuery( name = "SubgraphNodeEntity.getInternalReferences", query = "select ref from ReferenceEntity as ref where ref.id.workspaceId = :workspaceId and ref.id.toUuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId) and ref.id.fromUuidString in (select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId)" ),
52 @NamedQuery( name = "SubgraphNodeEntity.getOutwardReferences", query = "select ref from ReferenceEntity as ref where ref.id.workspaceId = :workspaceId and ref.id.toUuidString not in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId) and ref.id.fromUuidString in (select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId)" ),
53 @NamedQuery( name = "SubgraphNodeEntity.getInwardReferences", query = "select ref from ReferenceEntity as ref where ref.id.workspaceId = :workspaceId and ref.id.toUuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId) and ref.id.fromUuidString not in (select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId)" ),
54 @NamedQuery( name = "SubgraphNodeEntity.deletePropertiesEntities", query = "delete PropertiesEntity props where props.id.workspaceId = :workspaceId and props.id.uuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId )" ),
55 @NamedQuery( name = "SubgraphNodeEntity.deleteChildEntities", query = "delete ChildEntity child where child.id.workspaceId = :workspaceId and child.id.childUuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId )" ),
56 @NamedQuery( name = "SubgraphNodeEntity.deleteReferences", query = "delete ReferenceEntity as ref where ref.id.workspaceId = :workspaceId and ref.id.fromUuidString in ( select node.nodeUuid from SubgraphNodeEntity node where node.queryId = :queryId )" ),
57 @NamedQuery( name = "SubgraphNodeEntity.deleteByQueryId", query = "delete SubgraphNodeEntity where queryId = :queryId" )} )
58 public class SubgraphNodeEntity {
59
60 @Id
61 @Column( name = "ID" )
62 @GeneratedValue( strategy = GenerationType.AUTO )
63 private Long id;
64
65 @Column( name = "QUERY_ID", nullable = false, unique = false, updatable = false )
66 private Long queryId;
67
68 @Column( name = "UUID", updatable = false, nullable = false, length = 36 )
69 private String nodeUuid;
70
71 @Column( name = "DEPTH", updatable = false, nullable = false )
72 private int depth;
73
74 @Column( name = "PARENT_NUM", updatable = false, nullable = false )
75 private int parentIndexInParent;
76
77 @Column( name = "CHILD_NUM", updatable = false, nullable = false )
78 private int indexInParent;
79
80 public SubgraphNodeEntity() {
81 }
82
83 public SubgraphNodeEntity( Long queryId,
84 String nodeUuid,
85 int depth ) {
86 this.queryId = queryId;
87 this.nodeUuid = nodeUuid;
88 this.depth = depth;
89 }
90
91
92
93
94 public Long getId() {
95 return id;
96 }
97
98
99
100
101 public int getDepth() {
102 return depth;
103 }
104
105
106
107
108 public String getNodeUuid() {
109 return nodeUuid;
110 }
111
112
113
114
115 public Long getQueryId() {
116 return queryId;
117 }
118
119
120
121
122 public int getIndexInParent() {
123 return indexInParent;
124 }
125
126
127
128
129 public int getParentIndexInParent() {
130 return parentIndexInParent;
131 }
132
133
134
135
136
137
138 @Override
139 public int hashCode() {
140 return id != null ? id.intValue() : 0;
141 }
142
143
144
145
146
147
148 @Override
149 public boolean equals( Object obj ) {
150 if (obj == this) return true;
151 if (obj instanceof SubgraphNodeEntity) {
152 SubgraphNodeEntity that = (SubgraphNodeEntity)obj;
153 if (this.id.equals(that.id)) return true;
154 }
155 return false;
156 }
157
158
159
160
161
162
163 @Override
164 public String toString() {
165 return "" + id + " - Query " + queryId + "; depth=" + depth + "; node=" + nodeUuid + " at index " + indexInParent;
166 }
167
168 }