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 /***
28 * This class was autogenerated by Torque on:
29 *
30 * [Thu Apr 22 23:12:36 EDT 2004]
31 *
32 * You should not use this class directly. It should not even be
33 * extended all references should be to PortletMediatype
34 */
35 public abstract class BasePortletMediatype extends BaseObject
36 {
37 /*** The Peer class */
38 private static final PortletMediatypePeer peer =
39 new PortletMediatypePeer();
40
41
42 /*** The value for the id field */
43 private long id;
44
45 /*** The value for the mediaId field */
46 private long mediaId;
47
48
49 /***
50 * Get the Id
51 * @return long
52 */
53 public long getId()
54 {
55 return id;
56 }
57
58
59 /***
60 * Set the value of Id
61 */
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 /***
81 * Get the MediaId
82 * @return long
83 */
84 public long getMediaId()
85 {
86 return mediaId;
87 }
88
89
90 /***
91 * Set the value of MediaId
92 */
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 /***
117 * Declares an association between this object and a PortletDbEntry object
118 *
119 * @param PortletDbEntry v
120 */
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 /***
145 * Provides convenient way to set a relationship based on a
146 * ObjectKey. e.g.
147 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
148 *
149 */
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 /***
162 * Declares an association between this object and a Mediatype object
163 *
164 * @param Mediatype v
165 */
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 /***
190 * Provides convenient way to set a relationship based on a
191 * ObjectKey. e.g.
192 * <code>bar.setFooKey(foo.getPrimaryKey())</code>
193 *
194 */
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 /***
206 * Generate a list of field names.
207 */
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 /***
221 * Retrieves a field from the object by name passed in
222 * as a String.
223 */
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 /***
238 * Retrieves a field from the object by name passed in
239 * as a String. The String must be one of the static
240 * Strings defined in this Class' Peer.
241 */
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 /***
256 * Retrieves a field from the object by Position as specified
257 * in the xml schema. Zero-based.
258 */
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 /***
273 * Stores the object in the database. If the object is new,
274 * it inserts it; otherwise an update is performed.
275 */
276 public void save() throws Exception
277 {
278 save(PortletMediatypePeer.getMapBuilder()
279 .getDatabaseMap().getName());
280 }
281
282 /***
283 * Stores the object in the database. If the object is new,
284 * it inserts it; otherwise an update is performed.
285 * Note: this code is here because the method body is
286 * auto-generated conditionally and therefore needs to be
287 * in this file instead of in the super class, BaseObject.
288 */
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 /*** flag to prevent endless save loop, if this object is referenced
306 by another object which falls in this transaction. */
307 private boolean alreadyInSave = false;
308 /***
309 * Stores the object in the database. If the object is new,
310 * it inserts it; otherwise an update is performed. This method
311 * is meant to be used as part of a transaction, otherwise use
312 * the save() method and the connection details will be handled
313 * internally
314 */
315 public void save(Connection con) throws TorqueException
316 {
317 if (!alreadyInSave)
318 {
319 alreadyInSave = true;
320
321
322
323
324 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 /***
346 * returns an id that differentiates this object from others
347 * of its class.
348 */
349 public ObjectKey getPrimaryKey()
350 {
351 return null;
352 }
353
354
355 /***
356 * Makes a copy of this object.
357 * It creates a new object filling in the simple attributes.
358 * It then fills all the association collections.
359 */
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 /***
371 * returns a peer instance associated with this om. Since Peer classes
372 * are not to have any instance attributes, this method returns the
373 * same instance for all member of this class. The method could therefore
374 * be static, but this would prevent one from overriding the behavior.
375 */
376 public PortletMediatypePeer getPeer()
377 {
378 return peer;
379 }
380 }