View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors. 
8    *
9    * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10   * is licensed to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   *
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   * Represents a single node that appears in a subgraph.
38   * 
39   * @see SubgraphQueryEntity
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       * @return id
93       */
94      public Long getId() {
95          return id;
96      }
97  
98      /**
99       * @return depth
100      */
101     public int getDepth() {
102         return depth;
103     }
104 
105     /**
106      * @return nodeUuid
107      */
108     public String getNodeUuid() {
109         return nodeUuid;
110     }
111 
112     /**
113      * @return queryId
114      */
115     public Long getQueryId() {
116         return queryId;
117     }
118 
119     /**
120      * @return indexInParent
121      */
122     public int getIndexInParent() {
123         return indexInParent;
124     }
125 
126     /**
127      * @return parentIndexInParent
128      */
129     public int getParentIndexInParent() {
130         return parentIndexInParent;
131     }
132 
133     /**
134      * {@inheritDoc}
135      * 
136      * @see java.lang.Object#hashCode()
137      */
138     @Override
139     public int hashCode() {
140         return id != null ? id.intValue() : 0;
141     }
142 
143     /**
144      * {@inheritDoc}
145      * 
146      * @see java.lang.Object#equals(java.lang.Object)
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      * {@inheritDoc}
160      * 
161      * @see java.lang.Object#toString()
162      */
163     @Override
164     public String toString() {
165         return "" + id + " - Query " + queryId + "; depth=" + depth + "; node=" + nodeUuid + " at index " + indexInParent;
166     }
167 
168 }