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 javax.persistence.Column; 028 import javax.persistence.Embeddable; 029 import net.jcip.annotations.Immutable; 030 import org.jboss.dna.common.util.HashCode; 031 032 /** 033 * A unique identifer for a parent-child relationship. 034 * 035 * @author Randall Hauch 036 */ 037 @Embeddable 038 @Immutable 039 @org.hibernate.annotations.Immutable 040 public class ChildId implements Serializable { 041 042 /** 043 * Version {@value} 044 */ 045 private static final long serialVersionUID = 1L; 046 047 @Column( name = "WORKSPACE_ID", nullable = false ) 048 private Long workspaceId; 049 050 @Column( name = "PARENT_UUID", nullable = false, length = 36 ) 051 private String parentUuidString; 052 053 @Column( name = "CHILD_UUID", nullable = false, length = 36 ) 054 private String childUuidString; 055 056 public ChildId() { 057 } 058 059 public ChildId( Long workspaceId, 060 NodeId parentId, 061 NodeId childId ) { 062 this.workspaceId = workspaceId; 063 if (parentId != null) this.parentUuidString = parentId.getUuidString(); 064 if (childId != null) this.childUuidString = childId.getUuidString(); 065 } 066 067 public ChildId( Long workspaceId, 068 String parentUuid, 069 String childUuid ) { 070 this.workspaceId = workspaceId; 071 this.parentUuidString = parentUuid; 072 this.childUuidString = childUuid; 073 } 074 075 /** 076 * @return parentUuidString 077 */ 078 public String getParentUuidString() { 079 return parentUuidString; 080 } 081 082 /** 083 * @return childUuidString 084 */ 085 public String getChildUuidString() { 086 return childUuidString; 087 } 088 089 /** 090 * @return workspaceId 091 */ 092 public Long getWorkspaceId() { 093 return workspaceId; 094 } 095 096 /** 097 * {@inheritDoc} 098 * 099 * @see java.lang.Object#hashCode() 100 */ 101 @Override 102 public int hashCode() { 103 return HashCode.compute(parentUuidString, childUuidString); 104 } 105 106 /** 107 * {@inheritDoc} 108 * 109 * @see java.lang.Object#equals(java.lang.Object) 110 */ 111 @Override 112 public boolean equals( Object obj ) { 113 if (obj == this) return true; 114 if (obj instanceof ChildId) { 115 ChildId that = (ChildId)obj; 116 if (this.workspaceId == null) { 117 if (that.workspaceId != null) return false; 118 } else { 119 if (!this.workspaceId.equals(that.workspaceId)) return false; 120 } 121 if (this.parentUuidString == null) { 122 if (that.parentUuidString != null) return false; 123 } else { 124 if (!this.parentUuidString.equals(that.parentUuidString)) return false; 125 } 126 if (this.childUuidString == null) { 127 if (that.childUuidString != null) return false; 128 } else { 129 if (!this.childUuidString.equals(that.childUuidString)) return false; 130 } 131 return true; 132 } 133 return false; 134 } 135 136 /** 137 * {@inheritDoc} 138 * 139 * @see java.lang.Object#toString() 140 */ 141 @Override 142 public String toString() { 143 return "Child " + childUuidString + " of " + parentUuidString + " in workspace " + workspaceId; 144 } 145 146 }