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 java.io.Serializable;
27  import javax.persistence.Column;
28  import javax.persistence.Embeddable;
29  import net.jcip.annotations.Immutable;
30  import org.modeshape.common.util.HashCode;
31  
32  /**
33   * An identifier for a reference, comprised of a single {@link NodeId} of the node containing the reference and a single
34   * {@link NodeId} of the node being referenced.
35   */
36  @Embeddable
37  @Immutable
38  @org.hibernate.annotations.Immutable
39  public class ReferenceId implements Serializable {
40  
41      /**
42       * Version {@value}
43       */
44      private static final long serialVersionUID = 1L;
45  
46      @Column( name = "WORKSPACE_ID", nullable = false )
47      private Long workspaceId;
48  
49      @Column( name = "FROM_UUID", nullable = false, updatable = false, length = 36 )
50      private String fromUuidString;
51  
52      @Column( name = "TO_UUID", nullable = false, updatable = false, length = 36 )
53      private String toUuidString;
54  
55      public ReferenceId() {
56      }
57  
58      public ReferenceId( Long workspaceId,
59                          String fromUuid,
60                          String toUuid ) {
61          this.workspaceId = workspaceId;
62          this.fromUuidString = fromUuid;
63          this.toUuidString = toUuid;
64      }
65  
66      /**
67       * @return fromUuidString
68       */
69      public String getFromUuidString() {
70          return fromUuidString;
71      }
72  
73      /**
74       * @return toUuidString
75       */
76      public String getToUuidString() {
77          return toUuidString;
78      }
79  
80      /**
81       * @return workspaceId
82       */
83      public Long getWorkspaceId() {
84          return workspaceId;
85      }
86  
87      /**
88       * {@inheritDoc}
89       * 
90       * @see java.lang.Object#hashCode()
91       */
92      @Override
93      public int hashCode() {
94          return HashCode.compute(fromUuidString, toUuidString);
95      }
96  
97      /**
98       * {@inheritDoc}
99       * 
100      * @see java.lang.Object#equals(java.lang.Object)
101      */
102     @Override
103     public boolean equals( Object obj ) {
104         if (obj == this) return true;
105         if (obj instanceof ReferenceId) {
106             ReferenceId that = (ReferenceId)obj;
107             if (this.workspaceId == null) {
108                 if (that.workspaceId != null) return false;
109             } else {
110                 if (!this.workspaceId.equals(that.workspaceId)) return false;
111             }
112             if (this.fromUuidString == null) {
113                 if (that.fromUuidString != null) return false;
114             } else {
115                 if (!this.fromUuidString.equals(that.fromUuidString)) return false;
116             }
117             if (this.toUuidString == null) {
118                 if (that.toUuidString != null) return false;
119             } else {
120                 if (!this.toUuidString.equals(that.toUuidString)) return false;
121             }
122             return true;
123         }
124         return false;
125     }
126 
127     /**
128      * {@inheritDoc}
129      * 
130      * @see java.lang.Object#toString()
131      */
132     @Override
133     public String toString() {
134         return "Reference from " + fromUuidString + " to " + toUuidString + " in workspace " + workspaceId;
135     }
136 
137 }