1 package org.apache.torque.om; 2 3 21 22 import java.io.Serializable ; 23 import java.sql.Connection ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 import org.apache.torque.TorqueException; 29 import org.apache.torque.map.TableMap; 30 31 39 public abstract class BaseObject implements Persistent, Serializable 40 { 41 42 public static final int NEW_ID = -1; 43 44 48 private static final String NOT_IMPLEMENTED 49 = "Not implemented: Method must be overridden if called"; 50 51 52 private boolean isNew = true; 53 54 55 private ObjectKey primaryKey = null; 56 57 64 private boolean modified = true; 65 66 67 private transient Log log = null; 68 69 74 public ObjectKey getPrimaryKey() 75 { 76 return primaryKey; 77 } 78 79 84 public boolean isModified() 85 { 86 return modified; 87 } 88 89 96 public boolean isNew() 97 { 98 return isNew; 99 } 100 101 107 public void setNew(boolean b) 108 { 109 this.isNew = b; 110 } 111 112 119 public void setPrimaryKey(String primaryKey) throws TorqueException 120 { 121 this.primaryKey = new StringKey(primaryKey); 122 } 123 124 131 public void setPrimaryKey(SimpleKey[] primaryKey) throws TorqueException 132 { 133 this.primaryKey = new ComboKey(primaryKey); 134 } 135 136 143 public void setPrimaryKey(ObjectKey primaryKey) throws TorqueException 144 { 145 this.primaryKey = primaryKey; 146 } 147 148 153 public void setModified(boolean m) 154 { 155 modified = m; 156 } 157 158 161 public void resetModified() 162 { 163 modified = false; 164 } 165 166 174 public Object getByName(String field) 175 { 176 throw new Error ("BaseObject.getByName: " + NOT_IMPLEMENTED); 177 } 178 179 190 public boolean setByName(String name, Object value) 191 throws TorqueException 192 { 193 throw new Error ("BaseObject.setByName: " + NOT_IMPLEMENTED); 194 } 195 196 203 public Object getByPeerName(String name) 204 { 205 throw new Error ("BaseObject.getByPeerName: " + NOT_IMPLEMENTED); 206 } 207 208 219 public boolean setByPeerName(String name, Object value) 220 throws TorqueException 221 { 222 throw new Error ("BaseObject.setByPeerName: " + NOT_IMPLEMENTED); 223 } 224 225 233 public Object getByPosition(int pos) 234 { 235 throw new Error ("BaseObject.getByPosition: " + NOT_IMPLEMENTED); 236 } 237 238 249 public boolean setByPosition(int position, Object value) 250 throws TorqueException 251 { 252 throw new Error ("BaseObject.setByPosition: " + NOT_IMPLEMENTED); 253 } 254 255 264 public boolean equals(Object obj) 265 { 266 if (obj != null && obj instanceof BaseObject) 267 { 268 return equals((BaseObject) obj); 269 } 270 else 271 { 272 return false; 273 } 274 } 275 276 283 public boolean equals(BaseObject bo) 284 { 285 if (bo == null) 286 { 287 return false; 288 } 289 if (this == bo) 290 { 291 return true; 292 } 293 else if (getPrimaryKey() == null || bo.getPrimaryKey() == null) 294 { 295 return false; 296 } 297 else if (!getClass().equals(bo.getClass())) 298 { 299 return false; 300 } 301 else 302 { 303 return getPrimaryKey().equals(bo.getPrimaryKey()); 304 } 305 } 306 307 313 public int hashCode() 314 { 315 ObjectKey ok = getPrimaryKey(); 316 if (ok == null) 317 { 318 return super.hashCode(); 319 } 320 321 return ok.hashCode(); 322 } 323 324 329 protected Log getLog() 330 { 331 if (log == null) 332 { 333 log = LogFactory.getLog(getClass().getName()); 334 } 335 return log; 336 } 337 338 341 public abstract void save() throws Exception ; 342 343 346 public abstract void save(String dbName) throws Exception ; 347 348 351 public abstract void save(Connection con) throws Exception ; 352 353 360 public TableMap getTableMap() throws TorqueException 361 { 362 throw new Error ("BaseObject.getTableMap: " + NOT_IMPLEMENTED); 363 } 364 } 365 | Popular Tags |