KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BaseAttributePeer


1 package org.tigris.scarab.om;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.LinkedList JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.apache.torque.NoRowsException;
13 import org.apache.torque.TooManyRowsException;
14 import org.apache.torque.Torque;
15 import org.apache.torque.TorqueException;
16 import org.apache.torque.map.MapBuilder;
17 import org.apache.torque.map.TableMap;
18 import org.apache.torque.om.DateKey;
19 import org.apache.torque.om.NumberKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.ObjectKey;
22 import org.apache.torque.om.SimpleKey;
23 import org.apache.torque.util.BasePeer;
24 import org.apache.torque.util.Criteria;
25
26 import com.workingdogs.village.DataSetException;
27 import com.workingdogs.village.QueryDataSet;
28 import com.workingdogs.village.Record;
29
30 // Local classes
31
import org.tigris.scarab.om.map.*;
32
33
34   
35   
36   
37 /**
38  */

39 public abstract class BaseAttributePeer
40     extends BasePeer
41 {
42
43     /** the default database name for this class */
44     public static final String JavaDoc DATABASE_NAME = "scarab";
45
46      /** the table name for this class */
47     public static final String JavaDoc TABLE_NAME = "SCARAB_ATTRIBUTE";
48
49     /**
50      * @return the map builder for this peer
51      * @throws TorqueException Any exceptions caught during processing will be
52      * rethrown wrapped into a TorqueException.
53      */

54     public static MapBuilder getMapBuilder()
55         throws TorqueException
56     {
57         return getMapBuilder(AttributeMapBuilder.CLASS_NAME);
58     }
59
60       /** the column name for the ATTRIBUTE_ID field */
61     public static final String JavaDoc ATTRIBUTE_ID;
62       /** the column name for the ATTRIBUTE_NAME field */
63     public static final String JavaDoc ATTRIBUTE_NAME;
64       /** the column name for the ATTRIBUTE_TYPE_ID field */
65     public static final String JavaDoc ATTRIBUTE_TYPE_ID;
66       /** the column name for the PERMISSION field */
67     public static final String JavaDoc PERMISSION;
68       /** the column name for the REQUIRED_OPTION_ID field */
69     public static final String JavaDoc REQUIRED_OPTION_ID;
70       /** the column name for the DESCRIPTION field */
71     public static final String JavaDoc DESCRIPTION;
72       /** the column name for the ACTION field */
73     public static final String JavaDoc ACTION;
74       /** the column name for the CREATED_BY field */
75     public static final String JavaDoc CREATED_BY;
76       /** the column name for the CREATED_DATE field */
77     public static final String JavaDoc CREATED_DATE;
78       /** the column name for the DELETED field */
79     public static final String JavaDoc DELETED;
80   
81     static
82     {
83           ATTRIBUTE_ID = "SCARAB_ATTRIBUTE.ATTRIBUTE_ID";
84           ATTRIBUTE_NAME = "SCARAB_ATTRIBUTE.ATTRIBUTE_NAME";
85           ATTRIBUTE_TYPE_ID = "SCARAB_ATTRIBUTE.ATTRIBUTE_TYPE_ID";
86           PERMISSION = "SCARAB_ATTRIBUTE.PERMISSION";
87           REQUIRED_OPTION_ID = "SCARAB_ATTRIBUTE.REQUIRED_OPTION_ID";
88           DESCRIPTION = "SCARAB_ATTRIBUTE.DESCRIPTION";
89           ACTION = "SCARAB_ATTRIBUTE.ACTION";
90           CREATED_BY = "SCARAB_ATTRIBUTE.CREATED_BY";
91           CREATED_DATE = "SCARAB_ATTRIBUTE.CREATED_DATE";
92           DELETED = "SCARAB_ATTRIBUTE.DELETED";
93           if (Torque.isInit())
94         {
95             try
96             {
97                 getMapBuilder(AttributeMapBuilder.CLASS_NAME);
98             }
99             catch (Exception JavaDoc e)
100             {
101                 log.error("Could not initialize Peer", e);
102             }
103         }
104         else
105         {
106             Torque.registerMapBuilder(AttributeMapBuilder.CLASS_NAME);
107         }
108     }
109  
110     /** number of columns for this peer */
111     public static final int numColumns = 10;
112
113     /** A class that can be returned by this peer. */
114     protected static final String JavaDoc CLASSNAME_DEFAULT =
115         "org.tigris.scarab.om.Attribute";
116
117     /** A class that can be returned by this peer. */
118     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
119
120     /**
121      * Class object initialization method.
122      *
123      * @param className name of the class to initialize
124      * @return the initialized class
125      */

126     private static Class JavaDoc initClass(String JavaDoc className)
127     {
128         Class JavaDoc c = null;
129         try
130         {
131             c = Class.forName(className);
132         }
133         catch (Throwable JavaDoc t)
134         {
135             log.error("A FATAL ERROR has occurred which should not "
136                 + "have happened under any circumstance. Please notify "
137                 + "the Torque developers <torque-dev@db.apache.org> "
138                 + "and give as many details as possible (including the error "
139                 + "stack trace).", t);
140
141             // Error objects should always be propogated.
142
if (t instanceof Error JavaDoc)
143             {
144                 throw (Error JavaDoc) t.fillInStackTrace();
145             }
146         }
147         return c;
148     }
149
150     /**
151      * Get the list of objects for a ResultSet. Please not that your
152      * resultset MUST return columns in the right order. You can use
153      * getFieldNames() in BaseObject to get the correct sequence.
154      *
155      * @param results the ResultSet
156      * @return the list of objects
157      * @throws TorqueException Any exceptions caught during processing will be
158      * rethrown wrapped into a TorqueException.
159      */

160     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
161             throws TorqueException
162     {
163         try
164         {
165             QueryDataSet qds = null;
166             List JavaDoc rows = null;
167             try
168             {
169                 qds = new QueryDataSet(results);
170                 rows = getSelectResults(qds);
171             }
172             finally
173             {
174                 if (qds != null)
175                 {
176                     qds.close();
177                 }
178             }
179
180             return populateObjects(rows);
181         }
182         catch (SQLException JavaDoc e)
183         {
184             throw new TorqueException(e);
185         }
186         catch (DataSetException e)
187         {
188             throw new TorqueException(e);
189         }
190     }
191
192
193   
194     /**
195      * Method to do inserts.
196      *
197      * @param criteria object used to create the INSERT statement.
198      * @throws TorqueException Any exceptions caught during processing will be
199      * rethrown wrapped into a TorqueException.
200      */

201     public static ObjectKey doInsert(Criteria criteria)
202         throws TorqueException
203     {
204         return BaseAttributePeer
205             .doInsert(criteria, (Connection JavaDoc) null);
206     }
207
208     /**
209      * Method to do inserts. This method is to be used during a transaction,
210      * otherwise use the doInsert(Criteria) method. It will take care of
211      * the connection details internally.
212      *
213      * @param criteria object used to create the INSERT statement.
214      * @param con the connection to use
215      * @throws TorqueException Any exceptions caught during processing will be
216      * rethrown wrapped into a TorqueException.
217      */

218     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
219         throws TorqueException
220     {
221                                                                     // check for conversion from boolean to int
222
if (criteria.containsKey(DELETED))
223         {
224             Object JavaDoc possibleBoolean = criteria.get(DELETED);
225             if (possibleBoolean instanceof Boolean JavaDoc)
226             {
227                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
228             }
229          }
230       
231         setDbName(criteria);
232
233         if (con == null)
234         {
235             return BasePeer.doInsert(criteria);
236         }
237         else
238         {
239             return BasePeer.doInsert(criteria, con);
240         }
241     }
242
243     /**
244      * Add all the columns needed to create a new object.
245      *
246      * @param criteria object containing the columns to add.
247      * @throws TorqueException Any exceptions caught during processing will be
248      * rethrown wrapped into a TorqueException.
249      */

250     public static void addSelectColumns(Criteria criteria)
251             throws TorqueException
252     {
253           criteria.addSelectColumn(ATTRIBUTE_ID);
254           criteria.addSelectColumn(ATTRIBUTE_NAME);
255           criteria.addSelectColumn(ATTRIBUTE_TYPE_ID);
256           criteria.addSelectColumn(PERMISSION);
257           criteria.addSelectColumn(REQUIRED_OPTION_ID);
258           criteria.addSelectColumn(DESCRIPTION);
259           criteria.addSelectColumn(ACTION);
260           criteria.addSelectColumn(CREATED_BY);
261           criteria.addSelectColumn(CREATED_DATE);
262           criteria.addSelectColumn(DELETED);
263       }
264
265     /**
266      * Create a new object of type cls from a resultset row starting
267      * from a specified offset. This is done so that you can select
268      * other rows than just those needed for this object. You may
269      * for example want to create two objects from the same row.
270      *
271      * @throws TorqueException Any exceptions caught during processing will be
272      * rethrown wrapped into a TorqueException.
273      */

274     public static Attribute row2Object(Record row,
275                                              int offset,
276                                              Class JavaDoc cls)
277         throws TorqueException
278     {
279         try
280         {
281             Attribute obj = (Attribute) cls.newInstance();
282             AttributePeer.populateObject(row, offset, obj);
283                   obj.setModified(false);
284               obj.setNew(false);
285
286             return obj;
287         }
288         catch (InstantiationException JavaDoc e)
289         {
290             throw new TorqueException(e);
291         }
292         catch (IllegalAccessException JavaDoc e)
293         {
294             throw new TorqueException(e);
295         }
296     }
297
298     /**
299      * Populates an object from a resultset row starting
300      * from a specified offset. This is done so that you can select
301      * other rows than just those needed for this object. You may
302      * for example want to create two objects from the same row.
303      *
304      * @throws TorqueException Any exceptions caught during processing will be
305      * rethrown wrapped into a TorqueException.
306      */

307     public static void populateObject(Record row,
308                                       int offset,
309                                       Attribute obj)
310         throws TorqueException
311     {
312         try
313         {
314                 obj.setAttributeId(row.getValue(offset + 0).asIntegerObj());
315                   obj.setName(row.getValue(offset + 1).asString());
316                   obj.setTypeId(row.getValue(offset + 2).asIntegerObj());
317                   obj.setPermission(row.getValue(offset + 3).asString());
318                   obj.setRequiredOptionId(row.getValue(offset + 4).asIntegerObj());
319                   obj.setDescription(row.getValue(offset + 5).asString());
320                   obj.setAction(row.getValue(offset + 6).asString());
321                   obj.setCreatedBy(row.getValue(offset + 7).asIntegerObj());
322                   obj.setCreatedDate(row.getValue(offset + 8).asUtilDate());
323                   obj.setDeleted(row.getValue(offset + 9).asBoolean());
324               }
325         catch (DataSetException e)
326         {
327             throw new TorqueException(e);
328         }
329     }
330
331     /**
332      * Method to do selects.
333      *
334      * @param criteria object used to create the SELECT statement.
335      * @return List of selected Objects
336      * @throws TorqueException Any exceptions caught during processing will be
337      * rethrown wrapped into a TorqueException.
338      */

339     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
340     {
341         return populateObjects(doSelectVillageRecords(criteria));
342     }
343
344     /**
345      * Method to do selects within a transaction.
346      *
347      * @param criteria object used to create the SELECT statement.
348      * @param con the connection to use
349      * @return List of selected Objects
350      * @throws TorqueException Any exceptions caught during processing will be
351      * rethrown wrapped into a TorqueException.
352      */

353     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
354         throws TorqueException
355     {
356         return populateObjects(doSelectVillageRecords(criteria, con));
357     }
358
359     /**
360      * Grabs the raw Village records to be formed into objects.
361      * This method handles connections internally. The Record objects
362      * returned by this method should be considered readonly. Do not
363      * alter the data and call save(), your results may vary, but are
364      * certainly likely to result in hard to track MT bugs.
365      *
366      * @throws TorqueException Any exceptions caught during processing will be
367      * rethrown wrapped into a TorqueException.
368      */

369     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
370         throws TorqueException
371     {
372         return BaseAttributePeer
373             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
374     }
375
376     /**
377      * Grabs the raw Village records to be formed into objects.
378      * This method should be used for transactions
379      *
380      * @param criteria object used to create the SELECT statement.
381      * @param con the connection to use
382      * @throws TorqueException Any exceptions caught during processing will be
383      * rethrown wrapped into a TorqueException.
384      */

385     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
386         throws TorqueException
387     {
388         if (criteria.getSelectColumns().size() == 0)
389         {
390             addSelectColumns(criteria);
391         }
392
393                                                                     // check for conversion from boolean to int
394
if (criteria.containsKey(DELETED))
395         {
396             Object JavaDoc possibleBoolean = criteria.get(DELETED);
397             if (possibleBoolean instanceof Boolean JavaDoc)
398             {
399                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
400             }
401          }
402       
403         setDbName(criteria);
404
405         // BasePeer returns a List of Value (Village) arrays. The array
406
// order follows the order columns were placed in the Select clause.
407
if (con == null)
408         {
409             return BasePeer.doSelect(criteria);
410         }
411         else
412         {
413             return BasePeer.doSelect(criteria, con);
414         }
415     }
416
417     /**
418      * The returned List will contain objects of the default type or
419      * objects that inherit from the default.
420      *
421      * @throws TorqueException Any exceptions caught during processing will be
422      * rethrown wrapped into a TorqueException.
423      */

424     public static List JavaDoc populateObjects(List JavaDoc records)
425         throws TorqueException
426     {
427         List JavaDoc results = new ArrayList JavaDoc(records.size());
428
429         // populate the object(s)
430
for (int i = 0; i < records.size(); i++)
431         {
432             Record row = (Record) records.get(i);
433               results.add(AttributePeer.row2Object(row, 1,
434                 AttributePeer.getOMClass()));
435           }
436         return results;
437     }
438  
439
440     /**
441      * The class that the Peer will make instances of.
442      * If the BO is abstract then you must implement this method
443      * in the BO.
444      *
445      * @throws TorqueException Any exceptions caught during processing will be
446      * rethrown wrapped into a TorqueException.
447      */

448     public static Class JavaDoc getOMClass()
449         throws TorqueException
450     {
451         return CLASS_DEFAULT;
452     }
453
454     /**
455      * Method to do updates.
456      *
457      * @param criteria object containing data that is used to create the UPDATE
458      * statement.
459      * @throws TorqueException Any exceptions caught during processing will be
460      * rethrown wrapped into a TorqueException.
461      */

462     public static void doUpdate(Criteria criteria) throws TorqueException
463     {
464          BaseAttributePeer
465             .doUpdate(criteria, (Connection JavaDoc) null);
466     }
467
468     /**
469      * Method to do updates. This method is to be used during a transaction,
470      * otherwise use the doUpdate(Criteria) method. It will take care of
471      * the connection details internally.
472      *
473      * @param criteria object containing data that is used to create the UPDATE
474      * statement.
475      * @param con the connection to use
476      * @throws TorqueException Any exceptions caught during processing will be
477      * rethrown wrapped into a TorqueException.
478      */

479     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
480         throws TorqueException
481     {
482         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
483                    selectCriteria.put(ATTRIBUTE_ID, criteria.remove(ATTRIBUTE_ID));
484                                                                                                   // check for conversion from boolean to int
485
if (criteria.containsKey(DELETED))
486         {
487             Object JavaDoc possibleBoolean = criteria.get(DELETED);
488             if (possibleBoolean instanceof Boolean JavaDoc)
489             {
490                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
491             }
492          }
493           
494         setDbName(criteria);
495
496         if (con == null)
497         {
498             BasePeer.doUpdate(selectCriteria, criteria);
499         }
500         else
501         {
502             BasePeer.doUpdate(selectCriteria, criteria, con);
503         }
504     }
505
506     /**
507      * Method to do deletes.
508      *
509      * @param criteria object containing data that is used DELETE from database.
510      * @throws TorqueException Any exceptions caught during processing will be
511      * rethrown wrapped into a TorqueException.
512      */

513      public static void doDelete(Criteria criteria) throws TorqueException
514      {
515          AttributePeer
516             .doDelete(criteria, (Connection JavaDoc) null);
517      }
518
519     /**
520      * Method to do deletes. This method is to be used during a transaction,
521      * otherwise use the doDelete(Criteria) method. It will take care of
522      * the connection details internally.
523      *
524      * @param criteria object containing data that is used DELETE from database.
525      * @param con the connection to use
526      * @throws TorqueException Any exceptions caught during processing will be
527      * rethrown wrapped into a TorqueException.
528      */

529      public static void doDelete(Criteria criteria, Connection JavaDoc con)
530         throws TorqueException
531      {
532                                                                     // check for conversion from boolean to int
533
if (criteria.containsKey(DELETED))
534         {
535             Object JavaDoc possibleBoolean = criteria.get(DELETED);
536             if (possibleBoolean instanceof Boolean JavaDoc)
537             {
538                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
539             }
540          }
541       
542         setDbName(criteria);
543
544         if (con == null)
545         {
546             BasePeer.doDelete(criteria);
547         }
548         else
549         {
550             BasePeer.doDelete(criteria, con);
551         }
552      }
553
554     /**
555      * Method to do selects
556      *
557      * @throws TorqueException Any exceptions caught during processing will be
558      * rethrown wrapped into a TorqueException.
559      */

560     public static List JavaDoc doSelect(Attribute obj) throws TorqueException
561     {
562         return doSelect(buildSelectCriteria(obj));
563     }
564
565     /**
566      * Method to do inserts
567      *
568      * @throws TorqueException Any exceptions caught during processing will be
569      * rethrown wrapped into a TorqueException.
570      */

571     public static void doInsert(Attribute obj) throws TorqueException
572     {
573           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
574           obj.setNew(false);
575         obj.setModified(false);
576     }
577
578     /**
579      * @param obj the data object to update in the database.
580      * @throws TorqueException Any exceptions caught during processing will be
581      * rethrown wrapped into a TorqueException.
582      */

583     public static void doUpdate(Attribute obj) throws TorqueException
584     {
585         doUpdate(buildCriteria(obj));
586         obj.setModified(false);
587     }
588
589     /**
590      * @param obj the data object to delete in the database.
591      * @throws TorqueException Any exceptions caught during processing will be
592      * rethrown wrapped into a TorqueException.
593      */

594     public static void doDelete(Attribute obj) throws TorqueException
595     {
596         doDelete(buildSelectCriteria(obj));
597     }
598
599     /**
600      * Method to do inserts. This method is to be used during a transaction,
601      * otherwise use the doInsert(Attribute) method. It will take
602      * care of the connection details internally.
603      *
604      * @param obj the data object to insert into the database.
605      * @param con the connection to use
606      * @throws TorqueException Any exceptions caught during processing will be
607      * rethrown wrapped into a TorqueException.
608      */

609     public static void doInsert(Attribute obj, Connection JavaDoc con)
610         throws TorqueException
611     {
612           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
613           obj.setNew(false);
614         obj.setModified(false);
615     }
616
617     /**
618      * Method to do update. This method is to be used during a transaction,
619      * otherwise use the doUpdate(Attribute) method. It will take
620      * care of the connection details internally.
621      *
622      * @param obj the data object to update in the database.
623      * @param con the connection to use
624      * @throws TorqueException Any exceptions caught during processing will be
625      * rethrown wrapped into a TorqueException.
626      */

627     public static void doUpdate(Attribute obj, Connection JavaDoc con)
628         throws TorqueException
629     {
630         doUpdate(buildCriteria(obj), con);
631         obj.setModified(false);
632     }
633
634     /**
635      * Method to delete. This method is to be used during a transaction,
636      * otherwise use the doDelete(Attribute) method. It will take
637      * care of the connection details internally.
638      *
639      * @param obj the data object to delete in the database.
640      * @param con the connection to use
641      * @throws TorqueException Any exceptions caught during processing will be
642      * rethrown wrapped into a TorqueException.
643      */

644     public static void doDelete(Attribute obj, Connection JavaDoc con)
645         throws TorqueException
646     {
647         doDelete(buildSelectCriteria(obj), con);
648     }
649
650     /**
651      * Method to do deletes.
652      *
653      * @param pk ObjectKey that is used DELETE from database.
654      * @throws TorqueException Any exceptions caught during processing will be
655      * rethrown wrapped into a TorqueException.
656      */

657     public static void doDelete(ObjectKey pk) throws TorqueException
658     {
659         BaseAttributePeer
660            .doDelete(pk, (Connection JavaDoc) null);
661     }
662
663     /**
664      * Method to delete. This method is to be used during a transaction,
665      * otherwise use the doDelete(ObjectKey) method. It will take
666      * care of the connection details internally.
667      *
668      * @param pk the primary key for the object to delete in the database.
669      * @param con the connection to use
670      * @throws TorqueException Any exceptions caught during processing will be
671      * rethrown wrapped into a TorqueException.
672      */

673     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
674         throws TorqueException
675     {
676         doDelete(buildCriteria(pk), con);
677     }
678
679     /** Build a Criteria object from an ObjectKey */
680     public static Criteria buildCriteria( ObjectKey pk )
681     {
682         Criteria criteria = new Criteria();
683               criteria.add(ATTRIBUTE_ID, pk);
684           return criteria;
685      }
686
687     /** Build a Criteria object from the data object for this peer */
688     public static Criteria buildCriteria( Attribute obj )
689     {
690         Criteria criteria = new Criteria(DATABASE_NAME);
691               if (!obj.isNew())
692             criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
693               criteria.add(ATTRIBUTE_NAME, obj.getName());
694               criteria.add(ATTRIBUTE_TYPE_ID, obj.getTypeId());
695               criteria.add(PERMISSION, obj.getPermission());
696               criteria.add(REQUIRED_OPTION_ID, obj.getRequiredOptionId());
697               criteria.add(DESCRIPTION, obj.getDescription());
698               criteria.add(ACTION, obj.getAction());
699               criteria.add(CREATED_BY, obj.getCreatedBy());
700               criteria.add(CREATED_DATE, obj.getCreatedDate());
701               criteria.add(DELETED, obj.getDeleted());
702           return criteria;
703     }
704
705     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
706     public static Criteria buildSelectCriteria( Attribute obj )
707     {
708         Criteria criteria = new Criteria(DATABASE_NAME);
709               if (!obj.isNew())
710                     criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
711                           criteria.add(ATTRIBUTE_NAME, obj.getName());
712                           criteria.add(ATTRIBUTE_TYPE_ID, obj.getTypeId());
713                           criteria.add(PERMISSION, obj.getPermission());
714                           criteria.add(REQUIRED_OPTION_ID, obj.getRequiredOptionId());
715                           criteria.add(DESCRIPTION, obj.getDescription());
716                           criteria.add(ACTION, obj.getAction());
717                           criteria.add(CREATED_BY, obj.getCreatedBy());
718                           criteria.add(CREATED_DATE, obj.getCreatedDate());
719                           criteria.add(DELETED, obj.getDeleted());
720               return criteria;
721     }
722  
723     
724         /**
725      * Retrieve a single object by pk
726      *
727      * @param pk the primary key
728      * @throws TorqueException Any exceptions caught during processing will be
729      * rethrown wrapped into a TorqueException.
730      * @throws NoRowsException Primary key was not found in database.
731      * @throws TooManyRowsException Primary key was not found in database.
732      */

733     public static Attribute retrieveByPK(Integer JavaDoc pk)
734         throws TorqueException, NoRowsException, TooManyRowsException
735     {
736         return retrieveByPK(SimpleKey.keyFor(pk));
737     }
738
739     /**
740      * Retrieve a single object by pk
741      *
742      * @param pk the primary key
743      * @param con the connection to use
744      * @throws TorqueException Any exceptions caught during processing will be
745      * rethrown wrapped into a TorqueException.
746      * @throws NoRowsException Primary key was not found in database.
747      * @throws TooManyRowsException Primary key was not found in database.
748      */

749     public static Attribute retrieveByPK(Integer JavaDoc pk, Connection JavaDoc con)
750         throws TorqueException, NoRowsException, TooManyRowsException
751     {
752         return retrieveByPK(SimpleKey.keyFor(pk), con);
753     }
754   
755     /**
756      * Retrieve a single object by pk
757      *
758      * @param pk the primary key
759      * @throws TorqueException Any exceptions caught during processing will be
760      * rethrown wrapped into a TorqueException.
761      * @throws NoRowsException Primary key was not found in database.
762      * @throws TooManyRowsException Primary key was not found in database.
763      */

764     public static Attribute retrieveByPK(ObjectKey pk)
765         throws TorqueException, NoRowsException, TooManyRowsException
766     {
767         Connection JavaDoc db = null;
768         Attribute retVal = null;
769         try
770         {
771             db = Torque.getConnection(DATABASE_NAME);
772             retVal = retrieveByPK(pk, db);
773         }
774         finally
775         {
776             Torque.closeConnection(db);
777         }
778         return(retVal);
779     }
780
781     /**
782      * Retrieve a single object by pk
783      *
784      * @param pk the primary key
785      * @param con the connection to use
786      * @throws TorqueException Any exceptions caught during processing will be
787      * rethrown wrapped into a TorqueException.
788      * @throws NoRowsException Primary key was not found in database.
789      * @throws TooManyRowsException Primary key was not found in database.
790      */

791     public static Attribute retrieveByPK(ObjectKey pk, Connection JavaDoc con)
792         throws TorqueException, NoRowsException, TooManyRowsException
793     {
794         Criteria criteria = buildCriteria(pk);
795         List JavaDoc v = doSelect(criteria, con);
796         if (v.size() == 0)
797         {
798             throw new NoRowsException("Failed to select a row.");
799         }
800         else if (v.size() > 1)
801         {
802             throw new TooManyRowsException("Failed to select only one row.");
803         }
804         else
805         {
806             return (Attribute)v.get(0);
807         }
808     }
809
810     /**
811      * Retrieve a multiple objects by pk
812      *
813      * @param pks List of primary keys
814      * @throws TorqueException Any exceptions caught during processing will be
815      * rethrown wrapped into a TorqueException.
816      */

817     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
818         throws TorqueException
819     {
820         Connection JavaDoc db = null;
821         List JavaDoc retVal = null;
822         try
823         {
824            db = Torque.getConnection(DATABASE_NAME);
825            retVal = retrieveByPKs(pks, db);
826         }
827         finally
828         {
829             Torque.closeConnection(db);
830         }
831         return(retVal);
832     }
833
834     /**
835      * Retrieve a multiple objects by pk
836      *
837      * @param pks List of primary keys
838      * @param dbcon the connection to use
839      * @throws TorqueException Any exceptions caught during processing will be
840      * rethrown wrapped into a TorqueException.
841      */

842     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
843         throws TorqueException
844     {
845         List JavaDoc objs = null;
846         if (pks == null || pks.size() == 0)
847         {
848             objs = new LinkedList JavaDoc();
849         }
850         else
851         {
852             Criteria criteria = new Criteria();
853               criteria.addIn( ATTRIBUTE_ID, pks );
854           objs = doSelect(criteria, dbcon);
855         }
856         return objs;
857     }
858
859  
860
861
862
863               
864                                               
865                 
866                 
867
868     /**
869      * selects a collection of Attribute objects pre-filled with their
870      * AttributeType objects.
871      *
872      * This method is protected by default in order to keep the public
873      * api reasonable. You can provide public methods for those you
874      * actually need in AttributePeer.
875      *
876      * @throws TorqueException Any exceptions caught during processing will be
877      * rethrown wrapped into a TorqueException.
878      */

879     protected static List JavaDoc doSelectJoinAttributeType(Criteria criteria)
880         throws TorqueException
881     {
882         setDbName(criteria);
883
884         AttributePeer.addSelectColumns(criteria);
885         int offset = numColumns + 1;
886         AttributeTypePeer.addSelectColumns(criteria);
887
888
889                         criteria.addJoin(AttributePeer.ATTRIBUTE_TYPE_ID,
890             AttributeTypePeer.ATTRIBUTE_TYPE_ID);
891         
892
893                                                                                                                                                                                             // check for conversion from boolean to int
894
if (criteria.containsKey(DELETED))
895         {
896             Object JavaDoc possibleBoolean = criteria.get(DELETED);
897             if (possibleBoolean instanceof Boolean JavaDoc)
898             {
899                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
900             }
901          }
902                   
903         List JavaDoc rows = BasePeer.doSelect(criteria);
904         List JavaDoc results = new ArrayList JavaDoc();
905
906         for (int i = 0; i < rows.size(); i++)
907         {
908             Record row = (Record) rows.get(i);
909
910                             Class JavaDoc omClass = AttributePeer.getOMClass();
911                     Attribute obj1 = (Attribute) AttributePeer
912                 .row2Object(row, 1, omClass);
913                      omClass = AttributeTypePeer.getOMClass();
914                     AttributeType obj2 = (AttributeType)AttributeTypePeer
915                 .row2Object(row, offset, omClass);
916
917             boolean newObject = true;
918             for (int j = 0; j < results.size(); j++)
919             {
920                 Attribute temp_obj1 = (Attribute)results.get(j);
921                 AttributeType temp_obj2 = (AttributeType)temp_obj1.getAttributeType();
922                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
923                 {
924                     newObject = false;
925                               temp_obj2.addAttribute(obj1);
926                               break;
927                 }
928             }
929                       if (newObject)
930             {
931                 obj2.initAttributes();
932                 obj2.addAttribute(obj1);
933             }
934                       results.add(obj1);
935         }
936         return results;
937     }
938                                                             
939                 
940                 
941
942     /**
943      * selects a collection of Attribute objects pre-filled with their
944      * AttributeOption objects.
945      *
946      * This method is protected by default in order to keep the public
947      * api reasonable. You can provide public methods for those you
948      * actually need in AttributePeer.
949      *
950      * @throws TorqueException Any exceptions caught during processing will be
951      * rethrown wrapped into a TorqueException.
952      */

953     protected static List JavaDoc doSelectJoinAttributeOption(Criteria criteria)
954         throws TorqueException
955     {
956         setDbName(criteria);
957
958         AttributePeer.addSelectColumns(criteria);
959         int offset = numColumns + 1;
960         AttributeOptionPeer.addSelectColumns(criteria);
961
962
963                         criteria.addJoin(AttributePeer.REQUIRED_OPTION_ID,
964             AttributeOptionPeer.OPTION_ID);
965         
966
967                                                                                                                                                                                             // check for conversion from boolean to int
968
if (criteria.containsKey(DELETED))
969         {
970             Object JavaDoc possibleBoolean = criteria.get(DELETED);
971             if (possibleBoolean instanceof Boolean JavaDoc)
972             {
973                 criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
974             }
975          }
976                   
977         List JavaDoc rows = BasePeer.doSelect(criteria);
978         List JavaDoc results = new ArrayList JavaDoc();
979
980         for (int i = 0; i < rows.size(); i++)
981         {
982             Record row = (Record) rows.get(i);
983
984                             Class JavaDoc omClass = AttributePeer.getOMClass();
985                     Attribute obj1 = (Attribute) AttributePeer
986                 .row2Object(row, 1, omClass);
987                      omClass = AttributeOptionPeer.getOMClass();
988                     AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
989                 .row2Object(row, offset, omClass);
990
991             boolean newObject = true;
992             for (int j = 0; j < results.size(); j++)
993             {
994                 Attribute temp_obj1 = (Attribute)results.get(j);
995                 AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOption();
996                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
997                 {
998                     newObject = false;
999                               temp_obj2.addAttribute(obj1);
1000                              break;
1001                }
1002            }
1003                      if (newObject)
1004            {
1005                obj2.initAttributes();
1006                obj2.addAttribute(obj1);
1007            }
1008                      results.add(obj1);
1009        }
1010        return results;
1011    }
1012                                                            
1013                        
1014                
1015
1016    /**
1017     * selects a collection of Attribute objects pre-filled with their
1018     * ScarabUserImpl objects.
1019     *
1020     * This method is protected by default in order to keep the public
1021     * api reasonable. You can provide public methods for those you
1022     * actually need in AttributePeer.
1023     *
1024     * @throws TorqueException Any exceptions caught during processing will be
1025     * rethrown wrapped into a TorqueException.
1026     */

1027    protected static List JavaDoc doSelectJoinScarabUserImpl(Criteria criteria)
1028        throws TorqueException
1029    {
1030        setDbName(criteria);
1031
1032        AttributePeer.addSelectColumns(criteria);
1033        int offset = numColumns + 1;
1034        ScarabUserImplPeer.addSelectColumns(criteria);
1035
1036
1037                        criteria.addJoin(AttributePeer.CREATED_BY,
1038            ScarabUserImplPeer.USER_ID);
1039        
1040
1041                                                                                                                                                                                            // check for conversion from boolean to int
1042
if (criteria.containsKey(DELETED))
1043        {
1044            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1045            if (possibleBoolean instanceof Boolean JavaDoc)
1046            {
1047                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1048            }
1049         }
1050                  
1051        List JavaDoc rows = BasePeer.doSelect(criteria);
1052        List JavaDoc results = new ArrayList JavaDoc();
1053
1054        for (int i = 0; i < rows.size(); i++)
1055        {
1056            Record row = (Record) rows.get(i);
1057
1058                            Class JavaDoc omClass = AttributePeer.getOMClass();
1059                    Attribute obj1 = (Attribute) AttributePeer
1060                .row2Object(row, 1, omClass);
1061                     omClass = ScarabUserImplPeer.getOMClass();
1062                    ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer
1063                .row2Object(row, offset, omClass);
1064
1065            boolean newObject = true;
1066            for (int j = 0; j < results.size(); j++)
1067            {
1068                Attribute temp_obj1 = (Attribute)results.get(j);
1069                ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUser();
1070                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1071                {
1072                    newObject = false;
1073                              temp_obj2.addAttribute(obj1);
1074                              break;
1075                }
1076            }
1077                      if (newObject)
1078            {
1079                obj2.initAttributes();
1080                obj2.addAttribute(obj1);
1081            }
1082                      results.add(obj1);
1083        }
1084        return results;
1085    }
1086                    
1087  
1088                                    
1089          
1090        
1091                                  
1092                
1093
1094    /**
1095     * selects a collection of Attribute objects pre-filled with
1096     * all related objects.
1097     *
1098     * This method is protected by default in order to keep the public
1099     * api reasonable. You can provide public methods for those you
1100     * actually need in AttributePeer.
1101     *
1102     * @throws TorqueException Any exceptions caught during processing will be
1103     * rethrown wrapped into a TorqueException.
1104     */

1105    protected static List JavaDoc doSelectJoinAllExceptAttributeType(Criteria criteria)
1106        throws TorqueException
1107    {
1108        setDbName(criteria);
1109
1110        addSelectColumns(criteria);
1111        int offset2 = numColumns + 1;
1112                                    
1113                                                  
1114                    AttributeOptionPeer.addSelectColumns(criteria);
1115        int offset3 = offset2 + AttributeOptionPeer.numColumns;
1116                                                                
1117                    ScarabUserImplPeer.addSelectColumns(criteria);
1118        int offset4 = offset3 + ScarabUserImplPeer.numColumns;
1119                                                                                                                                                                                                                                        // check for conversion from boolean to int
1120
if (criteria.containsKey(DELETED))
1121        {
1122            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1123            if (possibleBoolean instanceof Boolean JavaDoc)
1124            {
1125                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1126            }
1127         }
1128                  
1129        List JavaDoc rows = BasePeer.doSelect(criteria);
1130        List JavaDoc results = new ArrayList JavaDoc();
1131
1132        for (int i = 0; i < rows.size(); i++)
1133        {
1134            Record row = (Record)rows.get(i);
1135
1136                            Class JavaDoc omClass = AttributePeer.getOMClass();
1137                    Attribute obj1 = (Attribute)AttributePeer
1138                .row2Object(row, 1, omClass);
1139                                                
1140                                                                  
1141                                                        
1142                            
1143              
1144                           omClass = AttributeOptionPeer.getOMClass();
1145                          AttributeOption obj2 = (AttributeOption)AttributeOptionPeer
1146                .row2Object( row, offset2, omClass);
1147
1148               boolean newObject = true;
1149            for (int j = 0; j < results.size(); j++)
1150            {
1151                Attribute temp_obj1 = (Attribute)results.get(j);
1152                AttributeOption temp_obj2 = (AttributeOption)temp_obj1.getAttributeOption();
1153                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1154                {
1155                    newObject = false;
1156                                    temp_obj2.addAttribute(obj1);
1157                                    break;
1158                }
1159            }
1160                            if (newObject)
1161            {
1162                obj2.initAttributes();
1163                obj2.addAttribute(obj1);
1164            }
1165                                                                                                
1166                                                        
1167                            
1168              
1169                           omClass = ScarabUserImplPeer.getOMClass();
1170                          ScarabUserImpl obj3 = (ScarabUserImpl)ScarabUserImplPeer
1171                .row2Object( row, offset3, omClass);
1172
1173               newObject = true;
1174            for (int j = 0; j < results.size(); j++)
1175            {
1176                Attribute temp_obj1 = (Attribute)results.get(j);
1177                ScarabUserImpl temp_obj3 = (ScarabUserImpl)temp_obj1.getScarabUser();
1178                if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey()))
1179                {
1180                    newObject = false;
1181                                    temp_obj3.addAttribute(obj1);
1182                                    break;
1183                }
1184            }
1185                            if (newObject)
1186            {
1187                obj3.initAttributes();
1188                obj3.addAttribute(obj1);
1189            }
1190                                                                results.add(obj1);
1191        }
1192        return results;
1193    }
1194        
1195        
1196                                  
1197                
1198
1199    /**
1200     * selects a collection of Attribute objects pre-filled with
1201     * all related objects.
1202     *
1203     * This method is protected by default in order to keep the public
1204     * api reasonable. You can provide public methods for those you
1205     * actually need in AttributePeer.
1206     *
1207     * @throws TorqueException Any exceptions caught during processing will be
1208     * rethrown wrapped into a TorqueException.
1209     */

1210    protected static List JavaDoc doSelectJoinAllExceptAttributeOption(Criteria criteria)
1211        throws TorqueException
1212    {
1213        setDbName(criteria);
1214
1215        addSelectColumns(criteria);
1216        int offset2 = numColumns + 1;
1217                                    
1218                    AttributeTypePeer.addSelectColumns(criteria);
1219        int offset3 = offset2 + AttributeTypePeer.numColumns;
1220                                                                
1221                                                  
1222                    ScarabUserImplPeer.addSelectColumns(criteria);
1223        int offset4 = offset3 + ScarabUserImplPeer.numColumns;
1224                                                                                                                                                                                                                                        // check for conversion from boolean to int
1225
if (criteria.containsKey(DELETED))
1226        {
1227            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1228            if (possibleBoolean instanceof Boolean JavaDoc)
1229            {
1230                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1231            }
1232         }
1233                  
1234        List JavaDoc rows = BasePeer.doSelect(criteria);
1235        List JavaDoc results = new ArrayList JavaDoc();
1236
1237        for (int i = 0; i < rows.size(); i++)
1238        {
1239            Record row = (Record)rows.get(i);
1240
1241                            Class JavaDoc omClass = AttributePeer.getOMClass();
1242                    Attribute obj1 = (Attribute)AttributePeer
1243                .row2Object(row, 1, omClass);
1244                                                
1245                                                        
1246                            
1247              
1248                           omClass = AttributeTypePeer.getOMClass();
1249                          AttributeType obj2 = (AttributeType)AttributeTypePeer
1250                .row2Object( row, offset2, omClass);
1251
1252               boolean newObject = true;
1253            for (int j = 0; j < results.size(); j++)
1254            {
1255                Attribute temp_obj1 = (Attribute)results.get(j);
1256                AttributeType temp_obj2 = (AttributeType)temp_obj1.getAttributeType();
1257                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1258                {
1259                    newObject = false;
1260                                    temp_obj2.addAttribute(obj1);
1261                                    break;
1262                }
1263            }
1264                            if (newObject)
1265            {
1266                obj2.initAttributes();
1267                obj2.addAttribute(obj1);
1268            }
1269                                                                                    
1270                                                                              
1271                                                        
1272                            
1273              
1274                           omClass = ScarabUserImplPeer.getOMClass();
1275                          ScarabUserImpl obj3 = (ScarabUserImpl)ScarabUserImplPeer
1276                .row2Object( row, offset3, omClass);
1277
1278               newObject = true;
1279            for (int j = 0; j < results.size(); j++)
1280            {
1281                Attribute temp_obj1 = (Attribute)results.get(j);
1282                ScarabUserImpl temp_obj3 = (ScarabUserImpl)temp_obj1.getScarabUser();
1283                if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey()))
1284                {
1285                    newObject = false;
1286                                    temp_obj3.addAttribute(obj1);
1287                                    break;
1288                }
1289            }
1290                            if (newObject)
1291            {
1292                obj3.initAttributes();
1293                obj3.addAttribute(obj1);
1294            }
1295                                                                results.add(obj1);
1296        }
1297        return results;
1298    }
1299        
1300        
1301                                  
1302                
1303
1304    /**
1305     * selects a collection of Attribute objects pre-filled with
1306     * all related objects.
1307     *
1308     * This method is protected by default in order to keep the public
1309     * api reasonable. You can provide public methods for those you
1310     * actually need in AttributePeer.
1311     *
1312     * @throws TorqueException Any exceptions caught during processing will be
1313     * rethrown wrapped into a TorqueException.
1314     */

1315    protected static List JavaDoc doSelectJoinAllExceptScarabUserImpl(Criteria criteria)
1316        throws TorqueException
1317    {
1318        setDbName(criteria);
1319
1320        addSelectColumns(criteria);
1321        int offset2 = numColumns + 1;
1322                                    
1323                    AttributeTypePeer.addSelectColumns(criteria);
1324        int offset3 = offset2 + AttributeTypePeer.numColumns;
1325                                                                
1326                    AttributeOptionPeer.addSelectColumns(criteria);
1327        int offset4 = offset3 + AttributeOptionPeer.numColumns;
1328                                                                
1329                                                                                                                                                                                                                          // check for conversion from boolean to int
1330
if (criteria.containsKey(DELETED))
1331        {
1332            Object JavaDoc possibleBoolean = criteria.get(DELETED);
1333            if (possibleBoolean instanceof Boolean JavaDoc)
1334            {
1335                criteria.add(DELETED, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1336            }
1337         }
1338                  
1339        List JavaDoc rows = BasePeer.doSelect(criteria);
1340        List JavaDoc results = new ArrayList JavaDoc();
1341
1342        for (int i = 0; i < rows.size(); i++)
1343        {
1344            Record row = (Record)rows.get(i);
1345
1346                            Class JavaDoc omClass = AttributePeer.getOMClass();
1347                    Attribute obj1 = (Attribute)AttributePeer
1348                .row2Object(row, 1, omClass);
1349                                                
1350                                                        
1351                            
1352              
1353                           omClass = AttributeTypePeer.getOMClass();
1354                          AttributeType obj2 = (AttributeType)AttributeTypePeer
1355                .row2Object( row, offset2, omClass);
1356
1357               boolean newObject = true;
1358            for (int j = 0; j < results.size(); j++)
1359            {
1360                Attribute temp_obj1 = (Attribute)results.get(j);
1361                AttributeType temp_obj2 = (AttributeType)temp_obj1.getAttributeType();
1362                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1363                {
1364                    newObject = false;
1365                                    temp_obj2.addAttribute(obj1);
1366                                    break;
1367                }
1368            }
1369                            if (newObject)
1370            {
1371                obj2.initAttributes();
1372                obj2.addAttribute(obj1);
1373            }
1374                                                                                    
1375                                                        
1376                            
1377              
1378                           omClass = AttributeOptionPeer.getOMClass();
1379                          AttributeOption obj3 = (AttributeOption)AttributeOptionPeer
1380                .row2Object( row, offset3, omClass);
1381
1382               newObject = true;
1383            for (int j = 0; j < results.size(); j++)
1384            {
1385                Attribute temp_obj1 = (Attribute)results.get(j);
1386                AttributeOption temp_obj3 = (AttributeOption)temp_obj1.getAttributeOption();
1387                if (temp_obj3.getPrimaryKey().equals(obj3.getPrimaryKey()))
1388                {
1389                    newObject = false;
1390                                    temp_obj3.addAttribute(obj1);
1391                                    break;
1392                }
1393            }
1394                            if (newObject)
1395            {
1396                obj3.initAttributes();
1397                obj3.addAttribute(obj1);
1398            }
1399                                                                                                
1400                                              results.add(obj1);
1401        }
1402        return results;
1403    }
1404                    
1405  
1406      /**
1407     * Returns the TableMap related to this peer. This method is not
1408     * needed for general use but a specific application could have a need.
1409     *
1410     * @throws TorqueException Any exceptions caught during processing will be
1411     * rethrown wrapped into a TorqueException.
1412     */

1413    protected static TableMap getTableMap()
1414        throws TorqueException
1415    {
1416        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1417    }
1418   
1419    private static void setDbName(Criteria crit)
1420    {
1421        // Set the correct dbName if it has not been overridden
1422
// crit.getDbName will return the same object if not set to
1423
// another value so == check is okay and faster
1424
if (crit.getDbName() == Torque.getDefaultDB())
1425        {
1426            crit.setDbName(DATABASE_NAME);
1427        }
1428    }
1429}
1430
Popular Tags