001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.connector.store.jpa.model.basic; 025 026 import java.io.Serializable; 027 import java.util.UUID; 028 import javax.persistence.Column; 029 import javax.persistence.Embeddable; 030 import net.jcip.annotations.Immutable; 031 032 /** 033 * An identifier for a node, comprised of a single {@link UUID}, and {@link Embeddable embeddable} in a persistent entity. The 034 * identifier takes the form of two <code>long</code> columns: one for the UUID's {@link UUID#getMostSignificantBits() most 035 * significant bits} and one for its {@link UUID#getLeastSignificantBits() least significant bits}. 036 * 037 * @author Randall Hauch 038 */ 039 @Embeddable 040 @Immutable 041 @org.hibernate.annotations.Immutable 042 public class NodeId implements Serializable { 043 044 /** 045 * Version {@value} 046 */ 047 private static final long serialVersionUID = 1L; 048 049 @Column( name = "WORKSPACE_ID", nullable = false ) 050 private Long workspaceId; 051 052 @Column( name = "UUID", nullable = true ) 053 private String uuidString; 054 055 public NodeId() { 056 } 057 058 public NodeId( Long workspaceId, 059 String uuidString ) { 060 this.workspaceId = workspaceId; 061 this.uuidString = uuidString; 062 } 063 064 /** 065 * @return uuidString 066 */ 067 public String getUuidString() { 068 return uuidString; 069 } 070 071 /** 072 * @param uuidString Sets uuidString to the specified value. 073 */ 074 public void setUuidString( String uuidString ) { 075 this.uuidString = uuidString; 076 } 077 078 /** 079 * @return workspaceId 080 */ 081 public Long getWorkspaceId() { 082 return workspaceId; 083 } 084 085 /** 086 * @param workspaceId Sets workspaceId to the specified value. 087 */ 088 public void setWorkspaceId( Long workspaceId ) { 089 this.workspaceId = workspaceId; 090 } 091 092 /** 093 * {@inheritDoc} 094 * 095 * @see java.lang.Object#hashCode() 096 */ 097 @Override 098 public int hashCode() { 099 return uuidString.hashCode(); 100 } 101 102 /** 103 * {@inheritDoc} 104 * 105 * @see java.lang.Object#equals(java.lang.Object) 106 */ 107 @Override 108 public boolean equals( Object obj ) { 109 if (obj == this) return true; 110 if (obj instanceof NodeId) { 111 NodeId that = (NodeId)obj; 112 if (this.uuidString == null) { 113 if (that.uuidString != null) return false; 114 } else { 115 if (!this.uuidString.equals(that.uuidString)) return false; 116 } 117 return true; 118 } 119 return false; 120 } 121 122 /** 123 * {@inheritDoc} 124 * 125 * @see java.lang.Object#toString() 126 */ 127 @Override 128 public String toString() { 129 return uuidString + " in workspace " + workspaceId; 130 } 131 }