KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > classic > Lifecycle


1 //$Id: Lifecycle.java,v 1.2 2005/07/20 07:16:16 oneovthafew Exp $
2
package org.hibernate.classic;
3
4 import java.io.Serializable JavaDoc;
5
6 import org.hibernate.CallbackException;
7 import org.hibernate.Session;
8
9 /**
10  * Provides callbacks from the <tt>Session</tt> to the persistent object.
11  * Persistent classes <b>may</b> implement this interface but they are not
12  * required to.<br>
13  * <br>
14  * <b>onSave:</b> called just before the object is saved<br>
15  * <b>onUpdate:</b> called just before an object is updated,
16  * ie. when <tt>Session.update()</tt> is called<br>
17  * <b>onDelete:</b> called just before an object is deleted<br>
18  * <b>onLoad:</b> called just after an object is loaded<br>
19  * <br>
20  * <tt>onLoad()</tt> may be used to initialize transient properties of the
21  * object from its persistent state. It may <b>not</b> be used to load
22  * dependent objects since the <tt>Session</tt> interface may not be
23  * invoked from inside this method.<br>
24  * <br>
25  * A further intended usage of <tt>onLoad()</tt>, <tt>onSave()</tt> and
26  * <tt>onUpdate()</tt> is to store a reference to the <tt>Session</tt>
27  * for later use.<br>
28  * <br>
29  * If <tt>onSave()</tt>, <tt>onUpdate()</tt> or <tt>onDelete()</tt> return
30  * <tt>VETO</tt>, the operation is silently vetoed. If a
31  * <tt>CallbackException</tt> is thrown, the operation is vetoed and the
32  * exception is passed back to the application.<br>
33  * <br>
34  * Note that <tt>onSave()</tt> is called after an identifier is assigned
35  * to the object, except when identity column key generation is used.
36  *
37  * @see CallbackException
38  * @author Gavin King
39  */

40 public interface Lifecycle {
41
42     /**
43      * Return value to veto the action (true)
44      */

45     public static final boolean VETO = true;
46
47     /**
48      * Return value to accept the action (false)
49      */

50     public static final boolean NO_VETO = false;
51
52     /**
53      * Called when an entity is saved.
54      * @param s the session
55      * @return true to veto save
56      * @throws CallbackException
57      */

58     public boolean onSave(Session s) throws CallbackException;
59
60     /**
61      * Called when an entity is passed to <tt>Session.update()</tt>.
62      * This method is <em>not</em> called every time the object's
63      * state is persisted during a flush.
64      * @param s the session
65      * @return true to veto update
66      * @throws CallbackException
67      */

68     public boolean onUpdate(Session s) throws CallbackException;
69
70     /**
71      * Called when an entity is deleted.
72      * @param s the session
73      * @return true to veto delete
74      * @throws CallbackException
75      */

76     public boolean onDelete(Session s) throws CallbackException;
77
78     /**
79      * Called after an entity is loaded. <em>It is illegal to
80      * access the <tt>Session</tt> from inside this method.</em>
81      * However, the object may keep a reference to the session
82      * for later use.
83      *
84      * @param s the session
85      * @param id the identifier
86      */

87     public void onLoad(Session s, Serializable JavaDoc id);
88 }
89
90
91
92
93
94
95
Popular Tags