1 2 12 package com.versant.core.common; 13 14 import com.versant.core.metadata.ClassMetaData; 15 import com.versant.core.util.OIDObjectInput; 16 import com.versant.core.util.OIDObjectOutput; 17 18 import java.io.*; 19 20 26 public class NewObjectOID implements OID { 27 28 private ClassMetaData cmd; 29 34 public int idNo; 35 40 public OID realOID; 41 42 public NewObjectOID(ClassMetaData cmd) { 43 this.cmd = cmd; 44 } 45 46 51 public NewObjectOID() { 52 } 53 54 57 public boolean isNew() { 58 return true; 59 } 60 61 public boolean isResolved() { 62 return true; 63 } 64 65 public void resolve(State state) { 66 } 67 68 public int getIdentityType() { 69 return cmd.identityType; 70 } 71 72 75 public void init(int id) { 76 idNo = id; 77 } 78 79 public int getClassIndex() { 80 return cmd.index; 81 } 82 83 public ClassMetaData getCmd() { 84 return cmd; 85 } 86 87 91 public ClassMetaData getClassMetaData() { 92 return cmd; 93 } 94 95 public ClassMetaData getAvailableClassMetaData() { 96 return cmd; 97 } 98 99 public ClassMetaData getBaseClassMetaData() { 100 return cmd.top; 101 } 102 103 public void copyKeyFields(Object [] data) { 104 throw BindingSupportImpl.getInstance().internal( 105 "copyKeyFields(Object[]) called on NewObjectOID"); 106 } 107 108 public OID copy() { 109 NewObjectOID nOID = new NewObjectOID(); 110 nOID.cmd = cmd; 111 nOID.idNo = idNo; 112 return nOID; 113 } 114 115 public void fillFromPK(Object pk) { 116 } 118 119 public OID fillFromIDObject(Object id) { 120 return this; 122 } 123 124 public int hashCode() { 125 return cmd.index + idNo; 126 } 127 128 public boolean equals(Object obj) { 129 if (obj == this) return true; 130 if (obj instanceof NewObjectOID) { 131 NewObjectOID other = (NewObjectOID)obj; 132 if (other.cmd == cmd && other.idNo == idNo) { 133 return true; 134 } 135 } 136 return false; 137 } 138 139 public String toString() { 140 return toStringImp(); 141 } 142 143 146 public String toStringImp() { 147 return "NewObjectOID@" + 148 Integer.toHexString(System.identityHashCode(this)) + 149 " classIndex = " + cmd.index + 150 " id = " + idNo + 151 " realOID = " + realOID; 152 } 153 154 public String toSString() { 155 return "NewObjectOID@" + 156 Integer.toHexString(System.identityHashCode(this)) + 157 " classIndex = " + cmd.index + 158 " id = " + idNo + (realOID == null ? "" : " realOID = " + realOID.toSString()); 159 } 160 161 public String toPkString() { 162 return "(New)"; 163 } 164 165 public OID getAvailableOID() { 166 if (realOID != null) return realOID; 167 return this; 168 } 169 170 public OID getRealOID() { 171 return realOID; 172 } 173 174 public OID setRealOid(OID oid) { 175 if (oid == null) { 176 throw BindingSupportImpl.getInstance().internal("The supplied oid is NULL"); 177 } 178 if (this.realOID == null) { 179 this.realOID = oid; 180 } else { 181 if (!this.realOID.equals(oid)) { 182 throw BindingSupportImpl.getInstance().internal("The supplied R-OID is not " + 183 "equal to the current realOID"); 184 } 185 } 186 return oid; 187 } 188 189 public void writeExternal(OIDObjectOutput os) throws IOException { 190 os.writeInt(idNo); 191 os.write(realOID); 192 } 193 194 public void readExternal(OIDObjectInput is) throws ClassNotFoundException , 195 IOException { 196 idNo = is.readInt(); 197 realOID = is.readOID(); 198 } 199 200 public void fillFromIDString(String idString, int index) { 201 throw BindingSupportImpl.getInstance().internal("fillFromIDString called"); 202 } 203 204 public void fillFromIDString(String idString) { 205 throw BindingSupportImpl.getInstance().internal("Should not be called"); 206 } 207 208 public int compareTo(Object o) { 209 OID oo = (OID)o; 210 int diff = cmd.index - oo.getClassIndex(); 211 if (diff != 0) return diff; 212 if (oo.isNew()) { 213 return idNo - ((NewObjectOID)o).idNo; 214 } else { 215 return -1; } 217 } 218 219 223 public long getLongPrimaryKey() { 224 if (realOID == null) return idNo; 225 return realOID.getLongPrimaryKey(); 226 } 227 228 232 public void setLongPrimaryKey(long pk) { 233 realOID.setLongPrimaryKey(pk); 234 } 235 236 public void populateObjectIdClassInstance(Object o) { 237 throw BindingSupportImpl.getInstance().internal("Should not be called"); 238 } 239 240 public int getAvailableClassId() { 241 return getAvailableClassMetaData().classId; 242 } 243 244 public NewObjectOID newInstance(ClassMetaData cmd) { 245 return new NewObjectOID(cmd); 246 } 247 248 } 249 | Popular Tags |