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 27 35 public abstract class BasePortletMediatype extends BaseObject 36 { 37 38 private static final PortletMediatypePeer peer = 39 new PortletMediatypePeer(); 40 41 42 43 private long id; 44 45 46 private long mediaId; 47 48 49 53 public long getId() 54 { 55 return id; 56 } 57 58 59 62 public void setId(long v ) throws TorqueException 63 { 64 65 if (this.id != v) 66 { 67 this.id = v; 68 setModified(true); 69 } 70 71 72 if (aPortletDbEntry != null && !(aPortletDbEntry.getId() == v)) 73 { 74 aPortletDbEntry = null; 75 } 76 77 } 78 79 80 84 public long getMediaId() 85 { 86 return mediaId; 87 } 88 89 90 93 public void setMediaId(long v ) throws TorqueException 94 { 95 96 if (this.mediaId != v) 97 { 98 this.mediaId = v; 99 setModified(true); 100 } 101 102 103 if (aMediatype != null && !(aMediatype.getId() == v)) 104 { 105 aMediatype = null; 106 } 107 108 } 109 110 111 112 113 114 private PortletDbEntry aPortletDbEntry; 115 116 121 public void setPortletDbEntry(PortletDbEntry v) throws TorqueException 122 { 123 if (v == null) 124 { 125 setId(0); 126 } 127 else 128 { 129 setId(v.getId()); 130 } 131 aPortletDbEntry = v; 132 } 133 134 135 public PortletDbEntry getPortletDbEntry() throws TorqueException 136 { 137 if ( getId()>0 ) 138 { 139 return PortletDbEntryManager.getInstance(SimpleKey.keyFor(getId())); 140 } 141 return aPortletDbEntry; 142 } 143 144 150 public void setPortletDbEntryKey(ObjectKey key) throws TorqueException 151 { 152 153 setId(((NumberKey) key).longValue()); 154 } 155 156 157 158 159 private Mediatype aMediatype; 160 161 166 public void setMediatype(Mediatype v) throws TorqueException 167 { 168 if (v == null) 169 { 170 setMediaId(0); 171 } 172 else 173 { 174 setMediaId(v.getId()); 175 } 176 aMediatype = v; 177 } 178 179 180 public Mediatype getMediatype() throws TorqueException 181 { 182 if ( getMediaId()>0 ) 183 { 184 return MediatypeManager.getInstance(SimpleKey.keyFor(getMediaId())); 185 } 186 return aMediatype; 187 } 188 189 195 public void setMediatypeKey(ObjectKey key) throws TorqueException 196 { 197 198 setMediaId(((NumberKey) key).longValue()); 199 } 200 201 202 203 private static List fieldNames = null; 204 205 208 public static synchronized List getFieldNames() 209 { 210 if (fieldNames == null) 211 { 212 fieldNames = new ArrayList (); 213 fieldNames.add("Id"); 214 fieldNames.add("MediaId"); 215 fieldNames = Collections.unmodifiableList(fieldNames); 216 } 217 return fieldNames; 218 } 219 220 224 public Object getByName(String name) 225 { 226 if (name.equals("Id")) 227 { 228 return new Long (getId()); 229 } 230 if (name.equals("MediaId")) 231 { 232 return new Long (getMediaId()); 233 } 234 return null; 235 } 236 237 242 public Object getByPeerName(String name) 243 { 244 if (name.equals(PortletMediatypePeer.ID )) 245 { 246 return new Long (getId()); 247 } 248 if (name.equals(PortletMediatypePeer.MEDIA_ID )) 249 { 250 return new Long (getMediaId()); 251 } 252 return null; 253 } 254 255 259 public Object getByPosition(int pos) 260 { 261 if ( pos == 0 ) 262 { 263 return new Long (getId()); 264 } 265 if ( pos == 1 ) 266 { 267 return new Long (getMediaId()); 268 } 269 return null; 270 } 271 272 276 public void save() throws Exception 277 { 278 save(PortletMediatypePeer.getMapBuilder() 279 .getDatabaseMap().getName()); 280 } 281 282 289 public void save(String dbName) throws TorqueException 290 { 291 Connection con = null; 292 try 293 { 294 con = Transaction.begin(dbName); 295 save(con); 296 Transaction.commit(con); 297 } 298 catch(TorqueException e) 299 { 300 Transaction.safeRollback(con); 301 throw e; 302 } 303 } 304 305 307 private boolean alreadyInSave = false; 308 315 public void save(Connection con) throws TorqueException 316 { 317 if (!alreadyInSave) 318 { 319 alreadyInSave = true; 320 321 322 323 if (isModified()) 325 { 326 if (isNew()) 327 { 328 PortletMediatypePeer.doInsert((PortletMediatype)this, con); 329 setNew(false); 330 } 331 else 332 { 333 PortletMediatypePeer.doUpdate((PortletMediatype)this, con); 334 } 335 336 } 337 338 alreadyInSave = false; 339 } 340 } 341 342 343 344 345 349 public ObjectKey getPrimaryKey() 350 { 351 return null; 352 } 353 354 355 360 public PortletMediatype copy() throws TorqueException 361 { 362 PortletMediatype copyObj = new PortletMediatype(); 363 copyObj.setId(id); 364 copyObj.setMediaId(mediaId); 365 366 367 return copyObj; 368 } 369 370 376 public PortletMediatypePeer getPeer() 377 { 378 return peer; 379 } 380 } 381 | Popular Tags |