001: package org.tigris.scarab.om;
002:
003: import java.math.BigDecimal;
004: import java.sql.Connection;
005: import java.sql.SQLException;
006: import java.util.ArrayList;
007: import java.util.Date;
008: import java.util.Iterator;
009: import java.util.LinkedList;
010: import java.util.List;
011:
012: import org.apache.torque.NoRowsException;
013: import org.apache.torque.TooManyRowsException;
014: import org.apache.torque.Torque;
015: import org.apache.torque.TorqueException;
016: import org.apache.torque.map.MapBuilder;
017: import org.apache.torque.map.TableMap;
018: import org.apache.torque.om.DateKey;
019: import org.apache.torque.om.NumberKey;
020: import org.apache.torque.om.StringKey;
021: import org.apache.torque.om.ObjectKey;
022: import org.apache.torque.om.SimpleKey;
023: import org.apache.torque.util.BasePeer;
024: import org.apache.torque.util.Criteria;
025:
026: import com.workingdogs.village.DataSetException;
027: import com.workingdogs.village.QueryDataSet;
028: import com.workingdogs.village.Record;
029:
030: // Local classes
031: import org.tigris.scarab.om.map.*;
032:
033: /**
034: */
035: public abstract class BaseScarabUserImplPeer extends
036: org.apache.fulcrum.security.impl.db.entity.TurbineUserPeer {
037:
038: /** number of columns for this peer */
039: public static final int numColumns = 1;
040:
041: /** A class that can be returned by this peer. */
042: protected static final String CLASSNAME_DEFAULT = "org.tigris.scarab.om.ScarabUserImpl";
043:
044: /** A class that can be returned by this peer. */
045: protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
046:
047: /**
048: * Class object initialization method.
049: *
050: * @param className name of the class to initialize
051: * @return the initialized class
052: */
053: private static Class initClass(String className) {
054: Class c = null;
055: try {
056: c = Class.forName(className);
057: } catch (Throwable t) {
058: log
059: .error(
060: "A FATAL ERROR has occurred which should not "
061: + "have happened under any circumstance. Please notify "
062: + "the Torque developers <torque-dev@db.apache.org> "
063: + "and give as many details as possible (including the error "
064: + "stack trace).", t);
065:
066: // Error objects should always be propogated.
067: if (t instanceof Error) {
068: throw (Error) t.fillInStackTrace();
069: }
070: }
071: return c;
072: }
073:
074: /**
075: * The class that the Peer will make instances of.
076: * If the BO is abstract then you must implement this method
077: * in the BO.
078: *
079: * @throws TorqueException Any exceptions caught during processing will be
080: * rethrown wrapped into a TorqueException.
081: */
082: public static Class getOMClass() throws TorqueException {
083: return CLASS_DEFAULT;
084: }
085:
086: /**
087: * Retrieve a single object by pk
088: *
089: * @param pk the primary key
090: * @throws TorqueException Any exceptions caught during processing will be
091: * rethrown wrapped into a TorqueException.
092: * @throws NoRowsException Primary key was not found in database.
093: * @throws TooManyRowsException Primary key was not found in database.
094: */
095: public static ScarabUserImpl retrieveScarabUserImplByPK(Integer pk)
096: throws TorqueException, NoRowsException,
097: TooManyRowsException {
098: return retrieveScarabUserImplByPK(SimpleKey.keyFor(pk));
099: }
100:
101: /**
102: * Retrieve a single object by pk
103: *
104: * @param pk the primary key
105: * @param con the connection to use
106: * @throws TorqueException Any exceptions caught during processing will be
107: * rethrown wrapped into a TorqueException.
108: * @throws NoRowsException Primary key was not found in database.
109: * @throws TooManyRowsException Primary key was not found in database.
110: */
111: public static ScarabUserImpl retrieveScarabUserImplByPK(Integer pk,
112: Connection con) throws TorqueException, NoRowsException,
113: TooManyRowsException {
114: return retrieveScarabUserImplByPK(SimpleKey.keyFor(pk), con);
115: }
116:
117: /**
118: * Retrieve a single object by pk
119: *
120: * @param pk the primary key
121: * @throws TorqueException Any exceptions caught during processing will be
122: * rethrown wrapped into a TorqueException.
123: * @throws NoRowsException Primary key was not found in database.
124: * @throws TooManyRowsException Primary key was not found in database.
125: */
126: public static ScarabUserImpl retrieveScarabUserImplByPK(ObjectKey pk)
127: throws TorqueException, NoRowsException,
128: TooManyRowsException {
129: Connection db = null;
130: ScarabUserImpl retVal = null;
131: try {
132: db = Torque.getConnection(DATABASE_NAME);
133: retVal = retrieveScarabUserImplByPK(pk, db);
134: } finally {
135: Torque.closeConnection(db);
136: }
137: return retVal;
138: }
139:
140: /**
141: * Retrieve a single object by pk
142: *
143: * @param pk the primary key
144: * @param con the connection to use
145: * @throws TorqueException Any exceptions caught during processing will be
146: * rethrown wrapped into a TorqueException.
147: * @throws NoRowsException Primary key was not found in database.
148: * @throws TooManyRowsException Primary key was not found in database.
149: */
150: public static ScarabUserImpl retrieveScarabUserImplByPK(
151: ObjectKey pk, Connection con) throws TorqueException,
152: NoRowsException, TooManyRowsException {
153: Criteria criteria = buildCriteria(pk);
154: List v = doSelect(criteria, con);
155: if (v.size() == 0) {
156: throw new NoRowsException("Failed to select a row.");
157: } else if (v.size() > 1) {
158: throw new TooManyRowsException(
159: "Failed to select only one row.");
160: } else {
161: return (ScarabUserImpl) v.get(0);
162: }
163: }
164:
165: /**
166: * Retrieve a multiple objects by pk
167: *
168: * @param pks List of primary keys
169: * @throws TorqueException Any exceptions caught during processing will be
170: * rethrown wrapped into a TorqueException.
171: */
172: public static List retrieveScarabUserImplByPKs(List pks)
173: throws TorqueException {
174: Connection db = null;
175: List retVal = null;
176: try {
177: db = Torque.getConnection(DATABASE_NAME);
178: retVal = retrieveScarabUserImplByPKs(pks, db);
179: } finally {
180: Torque.closeConnection(db);
181: }
182: return retVal;
183: }
184:
185: /**
186: * Retrieve a multiple objects by pk
187: *
188: * @param pks List of primary keys
189: * @param dbcon the connection to use
190: * @throws TorqueException Any exceptions caught during processing will be
191: * rethrown wrapped into a TorqueException.
192: */
193: public static List retrieveScarabUserImplByPKs(List pks,
194: Connection dbcon) throws TorqueException {
195: List objs = null;
196: if (pks == null || pks.size() == 0) {
197: objs = new LinkedList();
198: } else {
199: Criteria criteria = new Criteria();
200: criteria.addIn(USER_ID, pks);
201: objs = doSelect(criteria, dbcon);
202: }
203: return objs;
204: }
205:
206: private static void setDbName(Criteria crit) {
207: // Set the correct dbName if it has not been overridden
208: // crit.getDbName will return the same object if not set to
209: // another value so == check is okay and faster
210: if (crit.getDbName() == Torque.getDefaultDB()) {
211: crit.setDbName(DATABASE_NAME);
212: }
213: }
214: }
|