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
31 /**
32 * A unique identifer for a large value, which is the 160-bit SHA-1 hash of this value, in hex form (40-bytes). The SHA-1
33 * algorithm is fast and has not yet proven to have any duplicates. Even if SHA-2 and SHA-3 are better for cryptographically
34 * secure purposes, it is doubtful whether a repository needs more than SHA-1 for identity purposes.
35 */
36 @Embeddable
37 @Immutable
38 @org.hibernate.annotations.Immutable
39 public class LargeValueId implements Serializable {
40
41 /**
42 * Version {@value}
43 */
44 private static final long serialVersionUID = 1L;
45
46 @Column( name = "SHA1", nullable = false, length = 40 )
47 private String hash;
48
49 public LargeValueId() {
50 }
51
52 public LargeValueId( String hash ) {
53 this.hash = hash;
54 }
55
56 /**
57 * @return hash
58 */
59 public String getHash() {
60 return hash;
61 }
62
63 /**
64 * {@inheritDoc}
65 *
66 * @see java.lang.Object#hashCode()
67 */
68 @Override
69 public int hashCode() {
70 return hash.hashCode();
71 }
72
73 /**
74 * {@inheritDoc}
75 *
76 * @see java.lang.Object#equals(java.lang.Object)
77 */
78 @Override
79 public boolean equals( Object obj ) {
80 if (obj == this) return true;
81 if (obj instanceof LargeValueId) {
82 LargeValueId that = (LargeValueId)obj;
83 return this.hash.equals(that.hash);
84 }
85 return false;
86 }
87
88 /**
89 * {@inheritDoc}
90 *
91 * @see java.lang.Object#toString()
92 */
93 @Override
94 public String toString() {
95 return "Large value " + hash;
96 }
97
98 }