1 56 package org.objectstyle.cayenne; 57 58 import java.util.Collections ; 59 import java.util.Map ; 60 61 import org.apache.commons.lang.builder.EqualsBuilder; 62 import org.apache.commons.lang.builder.HashCodeBuilder; 63 64 71 public class TempObjectId extends ObjectId { 72 73 protected byte[] key; 74 75 79 public TempObjectId(Class objectClass) { 80 super(objectClass, null); 81 } 82 83 89 public TempObjectId(Class objectClass, byte[] key) { 90 super(objectClass, null); 91 this.key = key; 92 } 93 94 99 public byte[] getKey() { 100 return key; 101 } 102 103 108 public boolean equals(Object object) { 109 if (key == null) { 111 return object == this; 112 } 113 114 if (this == object) { 115 return true; 116 } 117 118 if (!(object instanceof TempObjectId)) { 119 return false; 120 } 121 122 TempObjectId id = (TempObjectId) object; 123 return new EqualsBuilder() 124 .append(objectClass.getName(), id.objectClass.getName()) 125 .append(key, id.key) 126 .isEquals(); 127 } 128 129 public int hashCode() { 130 if (this.hashCode == Integer.MIN_VALUE) { 131 HashCodeBuilder builder = new HashCodeBuilder(15, 37); 133 134 builder.append(objectClass.getName().hashCode()); 137 138 if (key != null) { 139 builder.append(key); 140 } 141 142 this.hashCode = builder.toHashCode(); 143 } 144 145 return this.hashCode; 146 } 147 148 153 public Map getIdSnapshot() { 154 return (replacementIdMap == null) ? Collections.EMPTY_MAP : replacementIdMap; 155 } 156 157 160 public boolean isTemporary() { 161 return true; 162 } 163 } | Popular Tags |