1 package org.apache.turbine.services.security.torque; 2 3 18 19 import java.sql.Connection ; 20 21 import org.apache.torque.om.ObjectKey; 22 import org.apache.torque.om.Persistent; 23 24 import org.apache.turbine.om.security.SecurityEntity; 25 import org.apache.turbine.util.security.TurbineSecurityException; 26 27 35 36 public abstract class TorqueObject 37 implements SecurityEntity, 38 Comparable , 39 Persistent 40 { 41 42 protected Persistent obj = null; 43 44 48 public TorqueObject() 49 { 50 } 51 52 57 public TorqueObject(String name) 58 { 59 this.setName(name); 60 } 61 62 69 public TorqueObject(Persistent obj) 70 { 71 this.obj = obj; 72 } 73 74 80 public abstract Persistent getPersistentObj(); 81 82 87 public abstract String getName(); 88 89 94 public abstract void setName(String name); 95 96 101 public ObjectKey getPrimaryKey() 102 { 103 Persistent p = getPersistentObj(); 104 if(p != null) 105 { 106 return p.getPrimaryKey(); 107 } 108 else 109 { 110 return null; 111 } 112 } 113 114 121 public void setPrimaryKey(ObjectKey primaryKey) 122 throws Exception 123 { 124 getPersistentObj().setPrimaryKey(primaryKey); 125 } 126 127 135 public void setPrimaryKey(String primaryKey) 136 throws Exception 137 { 138 getPersistentObj().setPrimaryKey(primaryKey); 139 } 140 141 147 public boolean isModified() 148 { 149 return getPersistentObj().isModified(); 150 } 151 152 159 public boolean isNew() 160 { 161 return getPersistentObj().isNew(); 162 } 163 164 170 public void setNew(boolean b) 171 { 172 getPersistentObj().setNew(b); 173 } 174 175 180 public void setModified(boolean m) 181 { 182 getPersistentObj().setModified(m); 183 } 184 185 193 public void save(String torqueName) 194 throws Exception 195 { 196 getPersistentObj().save(torqueName); 197 } 198 199 210 public void save(Connection con) 211 throws Exception 212 { 213 getPersistentObj().save(con); 214 } 215 216 222 public abstract void save() 223 throws TurbineSecurityException; 224 225 232 public int compareTo(Object obj) 233 { 234 if (this.getClass() != obj.getClass()) 235 { 236 throw new ClassCastException (); 237 } 238 String name1 = ((SecurityEntity) obj).getName(); 239 String name2 = this.getName(); 240 241 return name2.compareTo(name1); 242 } 243 244 252 public boolean equals(Object obj) 253 { 254 if (obj != null && obj instanceof TorqueObject) 255 { 256 return equals((TorqueObject) obj); 257 } 258 else 259 { 260 return false; 261 } 262 } 263 264 270 public boolean equals(TorqueObject torqueObject) 271 { 272 if (torqueObject == null) 273 { 274 return false; 275 } 276 if (this == torqueObject) 277 { 278 return true; 279 } 280 else if (getPrimaryKey() == null || torqueObject.getPrimaryKey() == null) 281 { 282 return false; 283 } 284 else 285 { 286 return getPrimaryKey().equals(torqueObject.getPrimaryKey()); 287 } 288 } 289 290 296 public int hashCode() 297 { 298 ObjectKey ok = getPrimaryKey(); 299 if (ok == null) 300 { 301 return super.hashCode(); 302 } 303 304 return ok.hashCode(); 305 } 306 } 307 | Popular Tags |