1 package org.apache.jetspeed.om.dbregistry; 2 3 4 import java.math.BigDecimal ; 5 import java.sql.Connection ; 6 import java.util.ArrayList ; 7 import java.util.Collections ; 8 import java.util.Date ; 9 import java.util.List ; 10 11 import org.apache.commons.lang.ObjectUtils; 12 import org.apache.torque.TorqueException; 13 import org.apache.torque.om.BaseObject; 14 import org.apache.torque.om.ComboKey; 15 import org.apache.torque.om.DateKey; 16 import org.apache.torque.om.NumberKey; 17 import org.apache.torque.om.ObjectKey; 18 import org.apache.torque.om.SimpleKey; 19 import org.apache.torque.om.StringKey; 20 import org.apache.torque.om.Persistent; 21 import org.apache.torque.util.Criteria; 22 import org.apache.torque.util.Transaction; 23 24 25 26 34 public abstract class BasePortletCategory extends BaseObject 35 { 36 37 private static final PortletCategoryPeer peer = 38 new PortletCategoryPeer(); 39 40 41 42 private long id; 43 44 45 private String name; 46 47 48 private String group; 49 50 51 private long owner; 52 53 54 58 public long getId() 59 { 60 return id; 61 } 62 63 64 67 public void setId(long v ) 68 { 69 70 if (this.id != v) 71 { 72 this.id = v; 73 setModified(true); 74 } 75 76 77 } 78 79 80 84 public String getName() 85 { 86 return name; 87 } 88 89 90 93 public void setName(String v ) 94 { 95 96 if (!ObjectUtils.equals(this.name, v)) 97 { 98 this.name = v; 99 setModified(true); 100 } 101 102 103 } 104 105 106 110 public String getGroup() 111 { 112 return group; 113 } 114 115 116 119 public void setGroup(String v ) 120 { 121 122 if (!ObjectUtils.equals(this.group, v)) 123 { 124 this.group = v; 125 setModified(true); 126 } 127 128 129 } 130 131 132 136 public long getOwner() 137 { 138 return owner; 139 } 140 141 142 145 public void setOwner(long v ) throws TorqueException 146 { 147 148 if (this.owner != v) 149 { 150 this.owner = v; 151 setModified(true); 152 } 153 154 155 if (aPortletDbEntry != null && !(aPortletDbEntry.getId() == v)) 156 { 157 aPortletDbEntry = null; 158 } 159 160 } 161 162 163 164 165 166 private PortletDbEntry aPortletDbEntry; 167 168 173 public void setPortletDbEntry(PortletDbEntry v) throws TorqueException 174 { 175 if (v == null) 176 { 177 setOwner(0); 178 } 179 else 180 { 181 setOwner(v.getId()); 182 } 183 aPortletDbEntry = v; 184 } 185 186 187 public PortletDbEntry getPortletDbEntry() throws TorqueException 188 { 189 if ( getOwner()>0 ) 190 { 191 return PortletDbEntryManager.getInstance(SimpleKey.keyFor(getOwner())); 192 } 193 return aPortletDbEntry; 194 } 195 196 202 public void setPortletDbEntryKey(ObjectKey key) throws TorqueException 203 { 204 205 setOwner(((NumberKey) key).longValue()); 206 } 207 208 209 210 private static List fieldNames = null; 211 212 215 public static synchronized List getFieldNames() 216 { 217 if (fieldNames == null) 218 { 219 fieldNames = new ArrayList (); 220 fieldNames.add("Id"); 221 fieldNames.add("Name"); 222 fieldNames.add("Group"); 223 fieldNames.add("Owner"); 224 fieldNames = Collections.unmodifiableList(fieldNames); 225 } 226 return fieldNames; 227 } 228 229 233 public Object getByName(String name) 234 { 235 if (name.equals("Id")) 236 { 237 return new Long (getId()); 238 } 239 if (name.equals("Name")) 240 { 241 return getName(); 242 } 243 if (name.equals("Group")) 244 { 245 return getGroup(); 246 } 247 if (name.equals("Owner")) 248 { 249 return new Long (getOwner()); 250 } 251 return null; 252 } 253 254 259 public Object getByPeerName(String name) 260 { 261 if (name.equals(PortletCategoryPeer.ID )) 262 { 263 return new Long (getId()); 264 } 265 if (name.equals(PortletCategoryPeer.NAME )) 266 { 267 return getName(); 268 } 269 if (name.equals(PortletCategoryPeer.GROUPE )) 270 { 271 return getGroup(); 272 } 273 if (name.equals(PortletCategoryPeer.OWNER )) 274 { 275 return new Long (getOwner()); 276 } 277 return null; 278 } 279 280 284 public Object getByPosition(int pos) 285 { 286 if ( pos == 0 ) 287 { 288 return new Long (getId()); 289 } 290 if ( pos == 1 ) 291 { 292 return getName(); 293 } 294 if ( pos == 2 ) 295 { 296 return getGroup(); 297 } 298 if ( pos == 3 ) 299 { 300 return new Long (getOwner()); 301 } 302 return null; 303 } 304 305 309 public void save() throws Exception 310 { 311 save(PortletCategoryPeer.getMapBuilder() 312 .getDatabaseMap().getName()); 313 } 314 315 322 public void save(String dbName) throws TorqueException 323 { 324 Connection con = null; 325 try 326 { 327 con = Transaction.begin(dbName); 328 save(con); 329 Transaction.commit(con); 330 } 331 catch(TorqueException e) 332 { 333 Transaction.safeRollback(con); 334 throw e; 335 } 336 } 337 338 340 private boolean alreadyInSave = false; 341 348 public void save(Connection con) throws TorqueException 349 { 350 if (!alreadyInSave) 351 { 352 alreadyInSave = true; 353 354 355 356 if (isModified()) 358 { 359 if (isNew()) 360 { 361 PortletCategoryPeer.doInsert((PortletCategory)this, con); 362 setNew(false); 363 } 364 else 365 { 366 PortletCategoryPeer.doUpdate((PortletCategory)this, con); 367 } 368 369 if (isCacheOnSave()) 370 { 371 PortletCategoryManager.putInstance(this); 372 } 373 } 374 375 alreadyInSave = false; 376 } 377 } 378 379 383 protected boolean isCacheOnSave() 384 { 385 return true; 386 } 387 388 389 394 public void setPrimaryKey(ObjectKey id) 395 { 396 setId(((NumberKey)id).longValue()); 397 } 398 399 402 public void setPrimaryKey(String key) 403 { 404 setId(Long.parseLong(key)); 405 } 406 407 408 412 public ObjectKey getPrimaryKey() 413 { 414 return SimpleKey.keyFor(getId()); 415 } 416 417 418 423 public PortletCategory copy() throws TorqueException 424 { 425 PortletCategory copyObj = new PortletCategory(); 426 copyObj.setId(id); 427 copyObj.setName(name); 428 copyObj.setGroup(group); 429 copyObj.setOwner(owner); 430 431 copyObj.setId(0); 432 433 return copyObj; 434 } 435 436 442 public PortletCategoryPeer getPeer() 443 { 444 return peer; 445 } 446 } 447 | Popular Tags |