001package org.apache.fulcrum.security.torque.om;
002
003import java.io.Serializable;
004import java.sql.Connection;
005import java.util.Objects;
006
007import org.apache.torque.TorqueException;
008import org.apache.torque.map.TableMap;
009import org.apache.torque.om.ComboKey;
010import org.apache.torque.om.NumberKey;
011import org.apache.torque.om.ObjectKey;
012import org.apache.torque.om.SimpleKey;
013import org.apache.torque.om.Persistent;
014import org.apache.torque.util.TorqueConnection;
015import org.apache.torque.util.Transaction;
016
017/**
018 * This class was autogenerated by Torque on:
019 *
020 * [Thu Nov 04 13:34:22 CET 2021]
021 *
022 * You should not use this class directly.  It should not even be
023 * extended; all references should be to TorqueTurbineRolePermission
024 */
025@SuppressWarnings("unused")
026public abstract class BaseTorqueTurbineRolePermission 
027    implements Persistent, Serializable
028{
029    /** Serial version */
030    private static final long serialVersionUID = 1636029262073L;
031
032
033
034    /** Defines the roleId field. */
035    private Integer roleId = null;
036
037    /** Defines the permissionId field. */
038    private Integer permissionId = null;
039
040    /** Whether this object was modified after loading or after last save. */
041    private boolean modified = true;
042
043    /** 
044     * Whether this object was loaded from the database or already saved 
045     * (false) or whether it is not yet in the database(true).
046     */
047    private boolean isNew = true;
048
049    /** Flag which indicates whether this object is currently saving. */
050    private boolean saving = false;
051
052    /** 
053     * Flag which indicates whether this object is currently loaded
054     * from the database. 
055     */
056    private boolean loading = false;
057
058    /** 
059     * Flag which indicates whether this object was deleted from the database.
060     * Note that this flags does not always display the current database state,
061     * there is no magical connection between this flag and the database.
062     */
063    private boolean deleted = false;
064
065    /** Defines the aTorqueTurbineRole field. */
066    private TorqueTurbineRole aTorqueTurbineRole = null;
067
068    /** Defines the aTorqueTurbinePermission field. */
069    private TorqueTurbinePermission aTorqueTurbinePermission = null;
070
071
072
073
074
075    /**
076     * Get the value of roleId.
077     *
078     * @return the value of roleId as Integer
079     */
080    public Integer getRoleId() 
081    {
082        
083        return roleId;
084    }
085
086    /**
087     * Set the value of roleId.
088     *
089     * @param v new value of roleId
090     */
091    public void setRoleId(Integer v)
092    {
093        if (!Objects.equals(this.roleId, v))
094        {
095            setModified(true);
096        }
097
098        this.roleId = v;
099        if (aTorqueTurbineRole != null && !Objects.equals(aTorqueTurbineRole.getEntityId(), v))
100        {
101            aTorqueTurbineRole = null;
102        }
103
104
105    }
106    
107    /**
108     * Get the value of permissionId.
109     *
110     * @return the value of permissionId as Integer
111     */
112    public Integer getPermissionId() 
113    {
114        
115        return permissionId;
116    }
117
118    /**
119     * Set the value of permissionId.
120     *
121     * @param v new value of permissionId
122     */
123    public void setPermissionId(Integer v)
124    {
125        if (!Objects.equals(this.permissionId, v))
126        {
127            setModified(true);
128        }
129
130        this.permissionId = v;
131        if (aTorqueTurbinePermission != null && !Objects.equals(aTorqueTurbinePermission.getEntityId(), v))
132        {
133            aTorqueTurbinePermission = null;
134        }
135
136
137    }
138    
139
140    /**
141     * Returns whether the object has ever been saved.  This will
142     * be false, if the object was retrieved from storage or was created
143     * and then saved.
144     *
145     * @return true, if the object has never been persisted.
146     */
147    public boolean isNew()
148    {
149        return isNew;
150    }
151
152    /**
153     * Sets whether the object has ever been saved.
154     *
155     * @param isNew true if the object has never been saved, false otherwise.
156     */
157    public void setNew(boolean isNew)
158    {
159        this.isNew = isNew;
160    }
161
162    /**
163     * Returns whether the object has been modified.
164     *
165     * @return True if the object has been modified.
166     */
167    public boolean isModified()
168    {
169        return modified;
170    }
171
172    /**
173     * Sets whether the object has been modified.
174     *
175     * @param modified true if the object has been modified, false otherwise.
176     */
177    public void setModified(boolean modified)
178    {
179        this.modified = modified;
180    }
181
182    /**
183     * Sets the modified state for the object to be false.
184     */
185    public void resetModified()
186    {
187        modified = false;
188    }
189
190
191    /**
192     * Returns whether this object is currently saving.
193     *
194     * @return true if this object is currently saving, false otherwise.
195     */
196    public boolean isSaving()
197    {
198        return saving;
199    }
200
201    /**
202     * Sets whether this object is currently saving.
203     *
204     * @param saving true if this object is currently saving, false otherwise.
205     */
206    public void setSaving(boolean saving)
207    {
208        this.saving = saving;
209    }
210
211
212    /**
213     * Returns whether this object is currently being loaded from the database.
214     *
215     * @return true if this object is currently loading, false otherwise.
216     */
217    public boolean isLoading()
218    {
219        return loading;
220    }
221
222    /**
223     * Sets whether this object is currently being loaded from the database.
224     *
225     * @param loading true if this object is currently loading, false otherwise.
226     */
227    public void setLoading(boolean loading)
228    {
229        this.loading = loading;
230    }
231
232
233    /**
234     * Returns whether this object was deleted from the database.
235     * Note that this getter does not automatically reflect database state,
236     * it will be set to true by Torque if doDelete() was called with this 
237     * object. Bulk deletes and deletes via primary key do not change
238     * this flag. Also, if doDelete() was called on an object which does
239     * not exist in the database, the deleted flag is set to true even if
240     * it was not deleted.
241     *
242     * @return true if this object was deleted, false otherwise.
243     */
244    public boolean isDeleted()
245    {
246        return deleted;
247    }
248
249    /**
250     * Sets whether this object was deleted from the database.
251     *
252     * @param deleted true if this object was deleted, false otherwise.
253     */
254    public void setDeleted(boolean deleted)
255    {
256        this.deleted = deleted;
257    }
258
259
260    /**
261     * Returns the associated TorqueTurbineRole object.
262     * If it was not retrieved before, the object is retrieved from
263     * the database
264     *
265     * @return the associated TorqueTurbineRole object
266     * @throws TorqueException when reading from the database fails.
267     */
268    public TorqueTurbineRole getTorqueTurbineRole()
269        throws TorqueException
270    {
271        if (aTorqueTurbineRole == null && !Objects.equals(this.roleId, null))
272        {
273            aTorqueTurbineRole = org.apache.fulcrum.security.torque.om.TorqueTurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId));
274        }
275        return aTorqueTurbineRole;
276    }
277
278    /**
279     * Return the associated TorqueTurbineRole object
280     * If it was not retrieved before, the object is retrieved from
281     * the database using the passed connection
282     *
283     * @param connection the connection used to retrieve the associated object
284     *        from the database, if it was not retrieved before
285     * @return the associated TorqueTurbineRole object
286     * @throws TorqueException If a problem occurs with the get[TorqueTurbineRole] method.
287     */
288    public TorqueTurbineRole getTorqueTurbineRole(Connection connection)
289        throws TorqueException
290    {
291        if (aTorqueTurbineRole == null && !Objects.equals(this.roleId, null))
292        {
293            aTorqueTurbineRole = org.apache.fulcrum.security.torque.om.TorqueTurbineRolePeer.retrieveByPK(SimpleKey.keyFor(this.roleId), connection);
294        }
295        return aTorqueTurbineRole;
296    }
297
298
299    /**
300     * Declares an association between this object and a TorqueTurbineRole object
301     *
302     * @param v TorqueTurbineRole
303     */
304    public void setTorqueTurbineRole(TorqueTurbineRole v)
305    {
306        if (v == null)
307        {
308            setRoleId(null);
309        }
310        else
311        {
312            setRoleId(v.getEntityId());
313        }
314        aTorqueTurbineRole = v;
315    }
316    /**
317     * Provides convenient way to set a relationship based on a
318     * ObjectKey, for example
319     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
320     *
321     * @param key the key to set
322     * @throws TorqueException if associated objects are not found
323     */
324    public void setTorqueTurbineRoleKey(ObjectKey<?> key) throws TorqueException
325    {
326       
327        setRoleId(Integer.valueOf(((NumberKey) key).intValue()));
328     }
329
330    /**
331     * Returns the associated TorqueTurbinePermission object.
332     * If it was not retrieved before, the object is retrieved from
333     * the database
334     *
335     * @return the associated TorqueTurbinePermission object
336     * @throws TorqueException when reading from the database fails.
337     */
338    public TorqueTurbinePermission getTorqueTurbinePermission()
339        throws TorqueException
340    {
341        if (aTorqueTurbinePermission == null && !Objects.equals(this.permissionId, null))
342        {
343            aTorqueTurbinePermission = org.apache.fulcrum.security.torque.om.TorqueTurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId));
344        }
345        return aTorqueTurbinePermission;
346    }
347
348    /**
349     * Return the associated TorqueTurbinePermission object
350     * If it was not retrieved before, the object is retrieved from
351     * the database using the passed connection
352     *
353     * @param connection the connection used to retrieve the associated object
354     *        from the database, if it was not retrieved before
355     * @return the associated TorqueTurbinePermission object
356     * @throws TorqueException If a problem occurs with the get[TorqueTurbinePermission] method.
357     */
358    public TorqueTurbinePermission getTorqueTurbinePermission(Connection connection)
359        throws TorqueException
360    {
361        if (aTorqueTurbinePermission == null && !Objects.equals(this.permissionId, null))
362        {
363            aTorqueTurbinePermission = org.apache.fulcrum.security.torque.om.TorqueTurbinePermissionPeer.retrieveByPK(SimpleKey.keyFor(this.permissionId), connection);
364        }
365        return aTorqueTurbinePermission;
366    }
367
368
369    /**
370     * Declares an association between this object and a TorqueTurbinePermission object
371     *
372     * @param v TorqueTurbinePermission
373     */
374    public void setTorqueTurbinePermission(TorqueTurbinePermission v)
375    {
376        if (v == null)
377        {
378            setPermissionId(null);
379        }
380        else
381        {
382            setPermissionId(v.getEntityId());
383        }
384        aTorqueTurbinePermission = v;
385    }
386    /**
387     * Provides convenient way to set a relationship based on a
388     * ObjectKey, for example
389     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
390     *
391     * @param key the key to set
392     * @throws TorqueException if associated objects are not found
393     */
394    public void setTorqueTurbinePermissionKey(ObjectKey<?> key) throws TorqueException
395    {
396       
397        setPermissionId(Integer.valueOf(((NumberKey) key).intValue()));
398     }
399
400
401
402
403
404
405
406    /**
407     * Stores an object in the database.  If the object is new,
408     * it is inserted; otherwise an update is performed.
409     *
410     * @throws TorqueException if an error occurs during saving.
411     */
412    public void save() throws TorqueException
413    {
414        save(TorqueTurbineRolePermissionPeer.DATABASE_NAME);
415    }
416
417    /**
418     * Stores an object in the database.  If the object is new,
419     * it is inserted; otherwise an update is performed.
420     *
421     * @param dbName the name of the database to which the object
422     *        should be saved.
423     *
424     * @throws TorqueException if an error occurs during saving.
425     */
426    public void save(String dbName) 
427            throws TorqueException
428    {
429        try (TorqueConnection con = Transaction.begin(dbName))
430        {
431            save(con);
432            Transaction.commit(con);
433        }
434    }
435
436    /**
437     * Stores an object in the database.  If the object is new,
438     * it is inserted; otherwise an update is performed.  This method
439     * is meant to be used as part of a transaction, otherwise use
440     * the save() method and the connection details will be handled
441     * internally.
442     *
443     * @param con the connection to use for saving the object, not null.
444     *
445     * @throws TorqueException if an error occurs during saving.
446     */
447    public void save(Connection con) 
448            throws TorqueException
449    {
450        if (isSaving())
451        {
452            return;
453        }
454        try
455        {
456            setSaving(true);
457            // If this object has been modified, then save it to the database.
458            if (isModified())
459            {
460                if (isNew())
461                {
462                    TorqueTurbineRolePermissionPeer.doInsert((TorqueTurbineRolePermission) this, con);
463                    setNew(false);
464                }
465                else
466                {
467                    TorqueTurbineRolePermissionPeer.doUpdate((TorqueTurbineRolePermission) this, con);
468                }
469            }
470
471        }
472        finally
473        {
474            setSaving(false);
475        }
476    }
477
478
479
480
481
482    private final SimpleKey<?>[] pks = new SimpleKey[2];
483    private final ComboKey comboPK = new ComboKey(pks);
484
485    /**
486     * Set the PrimaryKey with an ObjectKey
487     *
488     * @param key the primary key to set, not null.
489     */
490    public void setPrimaryKey(ObjectKey<?> key) throws TorqueException
491    {
492        SimpleKey<?>[] keys = (SimpleKey[]) key.getValue();
493        setRoleId(((NumberKey) keys[0]).intValue());
494        setPermissionId(((NumberKey) keys[1]).intValue());
495    }
496
497    /**
498     * Set the PrimaryKey using SimpleKeys.
499     *
500     * @param roleId a part of the primary key.
501     * @param permissionId a part of the primary key.
502     */
503    public void setPrimaryKey(Integer roleId, Integer permissionId)
504        
505    {
506        setRoleId(roleId);
507        setPermissionId(permissionId);
508    }
509
510    /**
511     * Set the PrimaryKey using a String.
512     * @param key the primary key to set.
513     */
514    public void setPrimaryKey(String key) throws TorqueException
515    {
516        setPrimaryKey(new ComboKey(key));
517    }
518
519    /**
520     * returns an id that differentiates this object from others
521     * of its class.
522     */
523    public ObjectKey<?> getPrimaryKey()
524    {
525        SimpleKey<?>[] pks = new SimpleKey[2];
526        pks[0] = SimpleKey.keyFor(getRoleId());
527        pks[1] = SimpleKey.keyFor(getPermissionId());
528        return new ComboKey(pks);
529    }
530
531
532    /**
533     * Returns an id that differentiates the referenced TorqueTurbineRole object
534     * from all other TorqueTurbineRole objects.
535     *
536     * @return an ObjectKey.
537     */
538    public ObjectKey<?> getForeignKeyForTorqueTurbineRole()
539    {
540        return SimpleKey.keyFor(getRoleId());
541    }
542    /**
543     * Returns an id that differentiates the referenced TorqueTurbinePermission object
544     * from all other TorqueTurbinePermission objects.
545     *
546     * @return an ObjectKey.
547     */
548    public ObjectKey<?> getForeignKeyForTorqueTurbinePermission()
549    {
550        return SimpleKey.keyFor(getPermissionId());
551    }
552
553    /**
554     * Makes a copy of this object.
555     * It creates a new object filling in the simple attributes.
556     * It then fills all the association collections and sets the
557     * related objects to isNew=true.
558     * @throws TorqueException if retrieval of the associated objects fails  
559     */
560    public TorqueTurbineRolePermission copy() throws TorqueException
561    {
562        return copy(true);
563    }
564
565    /**
566     * Makes a copy of this object using a connection.
567     * It creates a new object filling in the simple attributes.
568     * It then fills all the association collections and sets the
569     * related objects to isNew=true.
570     *
571     * @param con the database connection to read associated objects.
572     * @throws TorqueException if retrieval of the associated objects fails     
573     */
574    public TorqueTurbineRolePermission copy(Connection con) throws TorqueException
575    {
576        return copy(true, con);
577    }
578
579    /**
580     * Makes a copy of this object.
581     * It creates a new object filling in the simple attributes.
582     * If the parameter deepcopy is true, it then fills all the
583     * association collections and sets the related objects to
584     * isNew=true.
585     *
586     * @param deepcopy whether to copy the associated objects.
587     * @throws TorqueException if retrieval of the associated objects fails
588     */
589    public TorqueTurbineRolePermission copy(boolean deepcopy) throws TorqueException
590    {
591        TorqueTurbineRolePermission torqueTurbineRolePermission = new TorqueTurbineRolePermission();
592
593        return copyInto(torqueTurbineRolePermission, deepcopy);
594    }
595
596    /**
597     * Makes a copy of this object using connection.
598     * It creates a new object filling in the simple attributes.
599     * If the parameter deepcopy is true, it then fills all the
600     * association collections and sets the related objects to
601     * isNew=true.
602     *
603     * @param deepcopy whether to copy the associated objects.
604     * @param con the database connection to read associated objects.
605     * @throws TorqueException if retrieval of the associated objects fails
606     */
607    public TorqueTurbineRolePermission copy(boolean deepcopy, Connection con) throws TorqueException
608    {
609        TorqueTurbineRolePermission torqueTurbineRolePermission = new TorqueTurbineRolePermission();
610
611        return copyInto(torqueTurbineRolePermission, deepcopy, con);
612    }
613  
614    /**
615     * Fills the copyObj with the contents of this object.
616     * The associated objects are also copied and treated as new objects.
617     *
618     * @param copyObj the object to fill.
619     * @throws TorqueException if retrieval of the associated objects fails
620     */
621    public TorqueTurbineRolePermission copyInto(TorqueTurbineRolePermission copyObj) throws TorqueException
622    {
623        return copyInto(copyObj, true);
624    }
625
626    /**
627     * Fills the copyObj with the contents of this object using connection.
628     * The associated objects are also copied and treated as new objects.
629     *
630     * @param copyObj the object to fill.
631     * @param con the database connection to read associated objects.
632     * @throws TorqueException if retrieval of the associated objects fails
633     */
634    public TorqueTurbineRolePermission copyInto(TorqueTurbineRolePermission copyObj, Connection con) throws TorqueException
635    {
636        return copyInto(copyObj, true, con);
637    }
638  
639    /**
640     * Fills the copyObj with the contents of this object.
641     * If deepcopy is true, The associated objects are also copied
642     * and treated as new objects.
643     *
644     * @param copyObj the object to fill.
645     * @param deepcopy whether the associated objects should be copied.
646     * @throws TorqueException if retrieval of the associated objects fails
647     */
648    protected TorqueTurbineRolePermission copyInto(TorqueTurbineRolePermission copyObj, boolean deepcopy) throws TorqueException
649    {
650        copyObj.setRoleId((Integer) null);
651        copyObj.setPermissionId((Integer) null);
652
653        if (deepcopy)
654        {
655        }
656        return copyObj;
657    }
658        
659    
660    /**
661     * Fills the copyObj with the contents of this object using connection.
662     * If deepcopy is true, The associated objects are also copied
663     * and treated as new objects.
664     *
665     * @param copyObj the object to fill.
666     * @param deepcopy whether the associated objects should be copied.
667     * @param con the database connection to read associated objects.
668     * @throws TorqueException if retrieval of the associated objects fails
669     */
670    public TorqueTurbineRolePermission copyInto(TorqueTurbineRolePermission copyObj, boolean deepcopy, Connection con) throws TorqueException
671    {
672        copyObj.setRoleId((Integer) null);
673        copyObj.setPermissionId((Integer) null);
674
675        if (deepcopy)
676        {
677        }
678        return copyObj;
679    }
680
681    /** The Peer class */
682    private static final org.apache.fulcrum.security.torque.om.TorqueTurbineRolePermissionPeer peer
683            = new org.apache.fulcrum.security.torque.om.TorqueTurbineRolePermissionPeer();
684
685    /**
686     * returns a peer instance associated with this om.  Since Peer classes
687     * are not to have any instance attributes, this method returns the
688     * same instance for all member of this class. The method could therefore
689     * be static, but this would prevent one from overriding the behavior.
690     */
691    public org.apache.fulcrum.security.torque.om.TorqueTurbineRolePermissionPeer getPeer()
692    {
693        return peer;
694    }
695
696    /**
697     * Retrieves the TableMap object related to this Table data without
698     * compiler warnings of using getPeer().getTableMap().
699     *
700     * @return The associated TableMap object.
701     * @throws TorqueException if associated objects are not found
702     */
703    public TableMap getTableMap() throws TorqueException
704    {
705        return org.apache.fulcrum.security.torque.om.TorqueTurbineRolePermissionPeer.getTableMap();
706    }
707
708
709
710    public String toString()
711    {
712        StringBuffer str = new StringBuffer();
713        str.append("TorqueTurbineRolePermission:\n");
714        str.append("roleId = ")
715           .append(getRoleId())
716           .append("\n");
717        str.append("permissionId = ")
718           .append(getPermissionId())
719           .append("\n");
720        return(str.toString());
721    }
722
723    /**
724     * Compares the primary key of this instance with the key of another.
725     *
726     * @param toCompare The object to compare to.
727     * @return Whether the primary keys are equal and the object have the
728     *         same class.
729     */
730    public boolean equals(Object toCompare)
731    {
732        if (toCompare == null)
733        {
734            return false;
735        }
736        if (this == toCompare)
737        {
738            return true;
739        }
740        if (!getClass().equals(toCompare.getClass()))
741        {
742            return false;
743        }
744        TorqueTurbineRolePermission other = (TorqueTurbineRolePermission) toCompare;
745        if (getPrimaryKey() == null || other.getPrimaryKey() == null)
746        {
747            return false;
748        }
749        return getPrimaryKey().equals(other.getPrimaryKey());
750    }
751
752    /**
753     * If the primary key is not <code>null</code>, return the hashcode of the
754     * primary key.  Otherwise calls <code>Object.hashCode()</code>.
755     *
756     * @return an <code>int</code> value
757     */
758    public int hashCode()
759    {
760        ObjectKey<?> ok = getPrimaryKey();
761        if (ok == null)
762        {
763            return super.hashCode();
764        }
765
766        return ok.hashCode();
767    }
768
769
770
771    /**
772     * Compares the content of this object to another object
773     *
774     * @param toCompare The object to compare to.
775     * @return true if all of the columns in the other object have 
776     *         the same value as the objects in this class.
777     */
778    public boolean valueEquals(TorqueTurbineRolePermission toCompare)
779    {
780        if (toCompare == null)
781        {
782            return false;
783        }
784        if (this == toCompare)
785        {
786            return true;
787        }
788        if (!Objects.equals(this.roleId, toCompare.getRoleId()))
789        {
790            return false;
791        }
792        if (!Objects.equals(this.permissionId, toCompare.getPermissionId()))
793        {
794            return false;
795        }
796        return true;
797    }
798
799
800
801}