    001    package org.apache.turbine.services.security.torque.om;
    002
    003
    004    import java.math.BigDecimal;
    005    import java.sql.Connection;
    006    import java.util.ArrayList;
    007    import java.util.Collections;
    008    import java.util.Date;
    009    import java.util.List;
    010
    011    import org.apache.commons.lang.ObjectUtils;
    012    import org.apache.torque.TorqueException;
    013    import org.apache.torque.map.TableMap;
    014    import org.apache.torque.om.BaseObject;
    015    import org.apache.torque.om.ComboKey;
    016    import org.apache.torque.om.DateKey;
    017    import org.apache.torque.om.NumberKey;
    018    import org.apache.torque.om.ObjectKey;
    019    import org.apache.torque.om.SimpleKey;
    020    import org.apache.torque.om.StringKey;
    021    import org.apache.torque.om.Persistent;
    022    import org.apache.torque.util.Criteria;
    023    import org.apache.torque.util.Transaction;
    024
    025
    026
    027
    028
    029    /**
    030     * This class was autogenerated by Torque on:
    031     *
    032     * [Thu Jun 23 17:25:46 CEST 2011]
    033     *
    034     * You should not use this class directly.  It should not even be
    035     * extended all references should be to TurbineRolePermission
    036     */
    037    public abstract class BaseTurbineRolePermission extends BaseObject
    038    {
    039        /** Serial version */
    040        private static final long serialVersionUID = 1308842746584L;
    041
    042        /** The Peer class */
    043        private static final TurbineRolePermissionPeer peer =
    044            new TurbineRolePermissionPeer();
    045
    046
    047        /** The value for the roleId field */
    048        private int roleId;
    049
    050        /** The value for the permissionId field */
    051        private int permissionId;
    052
    053
    054        /**
    055         * Get the RoleId
    056         *
    057         * @return int
    058         */
    059        public int getRoleId()
    060        {
    061            return roleId;
    062        }
    063
    064
    065        /**
    066         * Set the value of RoleId
    067         *
    068         * @param v new value
    069         */
    070        public void setRoleId(int v) throws TorqueException
    071        {
    072
    073            if (this.roleId != v)
    074            {
    075                this.roleId = v;
    076                setModified(true);
    077            }
    078
    079
    080            if (aTurbineRole != null && !(aTurbineRole.getRoleId() == v))
    081            {
    082                aTurbineRole = null;
    083            }
    084
    085        }
    086
    087        /**
    088         * Get the PermissionId
    089         *
    090         * @return int
    091         */
    092        public int getPermissionId()
    093        {
    094            return permissionId;
    095        }
    096
    097
    098        /**
    099         * Set the value of PermissionId
    100         *
    101         * @param v new value
    102         */
    103        public void setPermissionId(int v) throws TorqueException
    104        {
    105
    106            if (this.permissionId != v)
    107            {
    108                this.permissionId = v;
    109                setModified(true);
    110            }
    111
    112
    113            if (aTurbinePermission != null && !(aTurbinePermission.getPermissionId() == v))
    114            {
    115                aTurbinePermission = null;
    116            }
    117
    118        }
    119
    120
    121
    122
    123
    124        private TurbineRole aTurbineRole;
    125
    126        /**
    127         * Declares an association between this object and a TurbineRole object
    128         *
    129         * @param v TurbineRole
    130         * @throws TorqueException
    131         */
    132        public void setTurbineRole(TurbineRole v) throws TorqueException
    133        {
    134            if (v == null)
    135            {
    136                setRoleId( 0);
    137            }
    138            else
    139            {
    140                setRoleId(v.getRoleId());
    141            }
    142            aTurbineRole = v;
    143        }
    144
    145
    146        /**
    147         * Returns the associated TurbineRole object.
    148         * If it was not retrieved before, the object is retrieved from
    149         * the database
    150         *
    151         * @return the associated TurbineRole object
    152         * @throws TorqueException
    153         */
    154        public TurbineRole getTurbineRole()
    155            throws TorqueException
    156        {
    157            if (aTurbineRole == null && (this.roleId != 0))
    158            {
    159                aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
    160            }
    161            return aTurbineRole;
    162        }
    163
    164        /**
    165         * Return the associated TurbineRole object
    166         * If it was not retrieved before, the object is retrieved from
    167         * the database using the passed connection
    168         *
    169         * @param connection the connection used to retrieve the associated object
    170         *        from the database, if it was not retrieved before
    171         * @return the associated TurbineRole object
    172         * @throws TorqueException
    173         */
    174        public TurbineRole getTurbineRole(Connection connection)
    175            throws TorqueException
    176        {
    177            if (aTurbineRole == null && (this.roleId != 0))
    178            {
    179                aTurbineRole = TurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId), connection);
    180            }
    181            return aTurbineRole;
    182        }
    183
    184        /**
    185         * Provides convenient way to set a relationship based on a
    186         * ObjectKey, for example
    187         * <code>bar.setFooKey(foo.getPrimaryKey())</code>
    188         *
    189         */
    190        public void setTurbineRoleKey(ObjectKey key) throws TorqueException
    191        {
    192
    193            setRoleId(((NumberKey) key).intValue());
    194        }
    195
    196
    197
    198
    199        private TurbinePermission aTurbinePermission;
    200
    201        /**
    202         * Declares an association between this object and a TurbinePermission object
    203         *
    204         * @param v TurbinePermission
    205         * @throws TorqueException
    206         */
    207        public void setTurbinePermission(TurbinePermission v) throws TorqueException
    208        {
    209            if (v == null)
    210            {
    211                setPermissionId( 0);
    212            }
    213            else
    214            {
    215                setPermissionId(v.getPermissionId());
    216            }
    217            aTurbinePermission = v;
    218        }
    219
    220
    221        /**
    222         * Returns the associated TurbinePermission object.
    223         * If it was not retrieved before, the object is retrieved from
    224         * the database
    225         *
    226         * @return the associated TurbinePermission object
    227         * @throws TorqueException
    228         */
    229        public TurbinePermission getTurbinePermission()
    230            throws TorqueException
    231        {
    232            if (aTurbinePermission == null && (this.permissionId != 0))
    233            {
    234                aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId));
    235            }
    236            return aTurbinePermission;
    237        }
    238
    239        /**
    240         * Return the associated TurbinePermission object
    241         * If it was not retrieved before, the object is retrieved from
    242         * the database using the passed connection
    243         *
    244         * @param connection the connection used to retrieve the associated object
    245         *        from the database, if it was not retrieved before
    246         * @return the associated TurbinePermission object
    247         * @throws TorqueException
    248         */
    249        public TurbinePermission getTurbinePermission(Connection connection)
    250            throws TorqueException
    251        {
    252            if (aTurbinePermission == null && (this.permissionId != 0))
    253            {
    254                aTurbinePermission = TurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId), connection);
    255            }
    256            return aTurbinePermission;
    257        }
    258
    259        /**
    260         * Provides convenient way to set a relationship based on a
    261         * ObjectKey, for example
    262         * <code>bar.setFooKey(foo.getPrimaryKey())</code>
    263         *
    264         */
    265        public void setTurbinePermissionKey(ObjectKey key) throws TorqueException
    266        {
    267
    268            setPermissionId(((NumberKey) key).intValue());
    269        }
    270
    271
    272        private static List<String> fieldNames = null;
    273
    274        /**
    275         * Generate a list of field names.
    276         *
    277         * @return a list of field names
    278         */
    279        public static synchronized List<String> getFieldNames()
    280        {
    281            if (fieldNames == null)
    282            {
    283                fieldNames = new ArrayList<String>();
    284                fieldNames.add("RoleId");
    285                fieldNames.add("PermissionId");
    286                fieldNames = Collections.unmodifiableList(fieldNames);
    287            }
    288            return fieldNames;
    289        }
    290
    291        /**
    292         * Retrieves a field from the object by field (Java) name passed in as a String.
    293         *
    294         * @param name field name
    295         * @return value
    296         */
    297        public Object getByName(String name)
    298        {
    299            if (name.equals("RoleId"))
    300            {
    301                return new Integer(getRoleId());
    302            }
    303            if (name.equals("PermissionId"))
    304            {
    305                return new Integer(getPermissionId());
    306            }
    307            return null;
    308        }
    309
    310        /**
    311         * Set a field in the object by field (Java) name.
    312         *
    313         * @param name field name
    314         * @param value field value
    315         * @return True if value was set, false if not (invalid name / protected field).
    316         * @throws IllegalArgumentException if object type of value does not match field object type.
    317         * @throws TorqueException If a problem occurs with the set[Field] method.
    318         */
    319        public boolean setByName(String name, Object value )
    320            throws TorqueException, IllegalArgumentException
    321        {
    322            if (name.equals("RoleId"))
    323            {
    324                if (value == null || ! (Integer.class.isInstance(value)))
    325                {
    326                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
    327                }
    328                setRoleId(((Integer) value).intValue());
    329                return true;
    330            }
    331            if (name.equals("PermissionId"))
    332            {
    333                if (value == null || ! (Integer.class.isInstance(value)))
    334                {
    335                    throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
    336                }
    337                setPermissionId(((Integer) value).intValue());
    338                return true;
    339            }
    340            return false;
    341        }
    342
    343        /**
    344         * Retrieves a field from the object by name passed in
    345         * as a String.  The String must be one of the static
    346         * Strings defined in this Class' Peer.
    347         *
    348         * @param name peer name
    349         * @return value
    350         */
    351        public Object getByPeerName(String name)
    352        {
    353            if (name.equals(TurbineRolePermissionPeer.ROLE_ID))
    354            {
    355                return new Integer(getRoleId());
    356            }
    357            if (name.equals(TurbineRolePermissionPeer.PERMISSION_ID))
    358            {
    359                return new Integer(getPermissionId());
    360            }
    361            return null;
    362        }
    363
    364        /**
    365         * Set field values by Peer Field Name
    366         *
    367         * @param name field name
    368         * @param value field value
    369         * @return True if value was set, false if not (invalid name / protected field).
    370         * @throws IllegalArgumentException if object type of value does not match field object type.
    371         * @throws TorqueException If a problem occurs with the set[Field] method.
    372         */
    373        public boolean setByPeerName(String name, Object value)
    374            throws TorqueException, IllegalArgumentException
    375        {
    376          if (TurbineRolePermissionPeer.ROLE_ID.equals(name))
    377            {
    378                return setByName("RoleId", value);
    379            }
    380          if (TurbineRolePermissionPeer.PERMISSION_ID.equals(name))
    381            {
    382                return setByName("PermissionId", value);
    383            }
    384            return false;
    385        }
    386
    387        /**
    388         * Retrieves a field from the object by Position as specified
    389         * in the xml schema.  Zero-based.
    390         *
    391         * @param pos position in xml schema
    392         * @return value
    393         */
    394        public Object getByPosition(int pos)
    395        {
    396            if (pos == 0)
    397            {
    398                return new Integer(getRoleId());
    399            }
    400            if (pos == 1)
    401            {
    402                return new Integer(getPermissionId());
    403            }
    404            return null;
    405        }
    406
    407        /**
    408         * Set field values by its position (zero based) in the XML schema.
    409         *
    410         * @param position The field position
    411         * @param value field value
    412         * @return True if value was set, false if not (invalid position / protected field).
    413         * @throws IllegalArgumentException if object type of value does not match field object type.
    414         * @throws TorqueException If a problem occurs with the set[Field] method.
    415         */
    416        public boolean setByPosition(int position, Object value)
    417            throws TorqueException, IllegalArgumentException
    418        {
    419        if (position == 0)
    420            {
    421                return setByName("RoleId", value);
    422            }
    423        if (position == 1)
    424            {
    425                return setByName("PermissionId", value);
    426            }
    427            return false;
    428        }
    429
    430        /**
    431         * Stores the object in the database.  If the object is new,
    432         * it inserts it; otherwise an update is performed.
    433         *
    434         * @throws Exception
    435         */
    436        public void save() throws Exception
    437        {
    438            save(TurbineRolePermissionPeer.DATABASE_NAME);
    439        }
    440
    441        /**
    442         * Stores the object in the database.  If the object is new,
    443         * it inserts it; otherwise an update is performed.
    444         * Note: this code is here because the method body is
    445         * auto-generated conditionally and therefore needs to be
    446         * in this file instead of in the super class, BaseObject.
    447         *
    448         * @param dbName
    449         * @throws TorqueException
    450         */
    451        public void save(String dbName) throws TorqueException
    452        {
    453            Connection con = null;
    454            try
    455            {
    456                con = Transaction.begin(dbName);
    457                save(con);
    458                Transaction.commit(con);
    459            }
    460            catch(TorqueException e)
    461            {
    462                Transaction.safeRollback(con);
    463                throw e;
    464            }
    465        }
    466
    467        /** flag to prevent endless save loop, if this object is referenced
    468            by another object which falls in this transaction. */
    469        private boolean alreadyInSave = false;
    470        /**
    471         * Stores the object in the database.  If the object is new,
    472         * it inserts it; otherwise an update is performed.  This method
    473         * is meant to be used as part of a transaction, otherwise use
    474         * the save() method and the connection details will be handled
    475         * internally
    476         *
    477         * @param con
    478         * @throws TorqueException
    479         */
    480        public void save(Connection con) throws TorqueException
    481        {
    482            if (!alreadyInSave)
    483            {
    484                alreadyInSave = true;
    485
    486
    487
    488                // If this object has been modified, then save it to the database.
    489                if (isModified())
    490                {
    491                    if (isNew())
    492                    {
    493                        TurbineRolePermissionPeer.doInsert((TurbineRolePermission) this, con);
    494                        setNew(false);
    495                    }
    496                    else
    497                    {
    498                        TurbineRolePermissionPeer.doUpdate((TurbineRolePermission) this, con);
    499                    }
    500                }
    501
    502                alreadyInSave = false;
    503            }
    504        }
    505
    506
    507
    508        private final SimpleKey[] pks = new SimpleKey[2];
    509        private final ComboKey comboPK = new ComboKey(pks);
    510
    511        /**
    512         * Set the PrimaryKey with an ObjectKey
    513         *
    514         * @param key
    515         */
    516        public void setPrimaryKey(ObjectKey key) throws TorqueException
    517        {
    518            SimpleKey[] keys = (SimpleKey[]) key.getValue();
    519            setRoleId(((NumberKey)keys[0]).intValue());
    520            setPermissionId(((NumberKey)keys[1]).intValue());
    521        }
    522
    523        /**
    524         * Set the PrimaryKey using SimpleKeys.
    525         *
    526         * @param roleId int
    527         * @param permissionId int
    528         */
    529        public void setPrimaryKey( int roleId, int permissionId)
    530            throws TorqueException
    531        {
    532            setRoleId(roleId);
    533            setPermissionId(permissionId);
    534        }
    535
    536        /**
    537         * Set the PrimaryKey using a String.
    538         */
    539        public void setPrimaryKey(String key) throws TorqueException
    540        {
    541            setPrimaryKey(new ComboKey(key));
    542        }
    543
    544        /**
    545         * returns an id that differentiates this object from others
    546         * of its class.
    547         */
    548        public ObjectKey getPrimaryKey()
    549        {
    550            pks[0] = SimpleKey.keyFor(getRoleId());
    551            pks[1] = SimpleKey.keyFor(getPermissionId());
    552            return comboPK;
    553        }
    554
    555
    556        /**
    557         * Makes a copy of this object.
    558         * It creates a new object filling in the simple attributes.
    559         * It then fills all the association collections and sets the
    560         * related objects to isNew=true.
    561         */
    562        public TurbineRolePermission copy() throws TorqueException
    563        {
    564            return copy(true);
    565        }
    566
    567        /**
    568         * Makes a copy of this object using connection.
    569         * It creates a new object filling in the simple attributes.
    570         * It then fills all the association collections and sets the
    571         * related objects to isNew=true.
    572         *
    573         * @param con the database connection to read associated objects.
    574         */
    575        public TurbineRolePermission copy(Connection con) throws TorqueException
    576        {
    577            return copy(true, con);
    578        }
    579
    580        /**
    581         * Makes a copy of this object.
    582         * It creates a new object filling in the simple attributes.
    583         * If the parameter deepcopy is true, it then fills all the
    584         * association collections and sets the related objects to
    585         * isNew=true.
    586         *
    587         * @param deepcopy whether to copy the associated objects.
    588         */
    589        public TurbineRolePermission copy(boolean deepcopy) throws TorqueException
    590        {
    591            return copyInto(new TurbineRolePermission(), deepcopy);
    592        }
    593
    594        /**
    595         * Makes a copy of this object using connection.
    596         * It creates a new object filling in the simple attributes.
    597         * If the parameter deepcopy is true, it then fills all the
    598         * association collections and sets the related objects to
    599         * isNew=true.
    600         *
    601         * @param deepcopy whether to copy the associated objects.
    602         * @param con the database connection to read associated objects.
    603         */
    604        public TurbineRolePermission copy(boolean deepcopy, Connection con) throws TorqueException
    605        {
    606            return copyInto(new TurbineRolePermission(), deepcopy, con);
    607        }
    608
    609        /**
    610         * Fills the copyObj with the contents of this object.
    611         * The associated objects are also copied and treated as new objects.
    612         *
    613         * @param copyObj the object to fill.
    614         */
    615        protected TurbineRolePermission copyInto(TurbineRolePermission copyObj) throws TorqueException
    616        {
    617            return copyInto(copyObj, true);
    618        }
    619
    620
    621        /**
    622         * Fills the copyObj with the contents of this object using connection.
    623         * The associated objects are also copied and treated as new objects.
    624         *
    625         * @param copyObj the object to fill.
    626         * @param con the database connection to read associated objects.
    627         */
    628        protected TurbineRolePermission copyInto(TurbineRolePermission copyObj, Connection con) throws TorqueException
    629        {
    630            return copyInto(copyObj, true, con);
    631        }
    632
    633        /**
    634         * Fills the copyObj with the contents of this object.
    635         * If deepcopy is true, The associated objects are also copied
    636         * and treated as new objects.
    637         *
    638         * @param copyObj the object to fill.
    639         * @param deepcopy whether the associated objects should be copied.
    640         */
    641        protected TurbineRolePermission copyInto(TurbineRolePermission copyObj, boolean deepcopy) throws TorqueException
    642        {
    643            copyObj.setRoleId(roleId);
    644            copyObj.setPermissionId(permissionId);
    645
    646            copyObj.setRoleId( 0);
    647            copyObj.setPermissionId( 0);
    648
    649            if (deepcopy)
    650            {
    651            }
    652            return copyObj;
    653        }
    654
    655
    656        /**
    657         * Fills the copyObj with the contents of this object using connection.
    658         * If deepcopy is true, The associated objects are also copied
    659         * and treated as new objects.
    660         *
    661         * @param copyObj the object to fill.
    662         * @param deepcopy whether the associated objects should be copied.
    663         * @param con the database connection to read associated objects.
    664         */
    665        protected TurbineRolePermission copyInto(TurbineRolePermission copyObj, boolean deepcopy, Connection con) throws TorqueException
    666        {
    667            copyObj.setRoleId(roleId);
    668            copyObj.setPermissionId(permissionId);
    669
    670            copyObj.setRoleId( 0);
    671            copyObj.setPermissionId( 0);
    672
    673            if (deepcopy)
    674            {
    675            }
    676            return copyObj;
    677        }
    678
    679
    680
    681        /**
    682         * returns a peer instance associated with this om.  Since Peer classes
    683         * are not to have any instance attributes, this method returns the
    684         * same instance for all member of this class. The method could therefore
    685         * be static, but this would prevent one from overriding the behavior.
    686         */
    687        public TurbineRolePermissionPeer getPeer()
    688        {
    689            return peer;
    690        }
    691
    692        /**
    693         * Retrieves the TableMap object related to this Table data without
    694         * compiler warnings of using getPeer().getTableMap().
    695         *
    696         * @return The associated TableMap object.
    697         */
    698        public TableMap getTableMap() throws TorqueException
    699        {
    700            return TurbineRolePermissionPeer.getTableMap();
    701        }
    702
    703
    704        public String toString()
    705        {
    706            StringBuffer str = new StringBuffer();
    707            str.append("TurbineRolePermission:\n");
    708            str.append("RoleId = ")
    709               .append(getRoleId())
    710               .append("\n");
    711            str.append("PermissionId = ")
    712               .append(getPermissionId())
    713               .append("\n");
    714            return(str.toString());
    715        }
    716    }