001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: Callbacks.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.database.querymanagers.generic;
009:
010: /**
011: * Callbacks are hooks that are being called when beans are manipulated
012: * through the {@link
013: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager} or other
014: * query managers that are based on it ({@link
015: * com.uwyn.rife.cmf.dam.ContentQueryManager}, for instance). They can either
016: * be implemented directly by implementing this interface, or they can be
017: * provided by a bean by implementing the {@link
018: * com.uwyn.rife.database.querymanagers.generic.CallbacksProvider} interface.
019: * <p>This can for example be used to delete associated and dependent objects
020: * when delete is called (by implementing {@link #beforeDelete(int)}), or to
021: * clear a cache when an object has been modified (by implementing {@link
022: * #afterSave(Object, boolean)} and {@link #afterDelete(int, boolean)}).
023: * <p>The return value of callbacks can be used to cancel actions. When the
024: * <code>before*</code> callbacks return <code>false</code>, the associated
025: * actions are cancelled. When the <code>after*</code> callbacks return
026: * <code>false</code>, the execution of the action is interrupted at that step
027: * and no further callbacks will be called.
028: *
029: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
030: * @version $Revision: 3634 $
031: * @see com.uwyn.rife.database.querymanagers.generic.GenericQueryManager
032: * @since 1.0
033: */
034: public interface Callbacks<BeanType> {
035: /**
036: * Is called before {@link
037: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#validate(Validated)}.
038: *
039: * @param object the bean instance that will be validated
040: * @return <code>true</code> if the execution should continue as normal;
041: * or
042: * <p><code>false</code> if the execution should be interrupted
043: * @since 1.3
044: */
045: public boolean beforeValidate(BeanType object);
046:
047: /**
048: * Is called before {@link
049: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#insert(Object)},
050: * or in the beginning of {@link
051: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#save(Object)}
052: * if a new bean is being saved.
053: *
054: * @param object the bean instance that will be inserted
055: * @return <code>true</code> if the execution should continue as normal;
056: * or
057: * <p><code>false</code> if the execution should be interrupted
058: * @since 1.0
059: */
060: public boolean beforeInsert(BeanType object);
061:
062: /**
063: * Is called before {@link
064: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#delete(int)}.
065: *
066: * @param objectId the id of the bean that will be deleted
067: * @return <code>true</code> if the execution should continue as normal;
068: * or
069: * <p><code>false</code> if the execution should be interrupted
070: * @since 1.0
071: */
072: public boolean beforeDelete(int objectId);
073:
074: /**
075: * Is called before {@link
076: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#save(Object)}.
077: *
078: * @param object the bean instance that will be saved
079: * @return <code>true</code> if the execution should continue as normal;
080: * or
081: * <p><code>false</code> if the execution should be interrupted
082: * @since 1.0
083: */
084: public boolean beforeSave(BeanType object);
085:
086: /**
087: * Is called before {@link
088: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#update(Object)},
089: * or in the beginning of {@link
090: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#save(Object)}
091: * if an existing bean is being saved.
092: *
093: * @param object the bean instance that will be updated
094: * @return <code>true</code> if the execution should continue as normal;
095: * or
096: * <p><code>false</code> if the execution should be interrupted
097: * @since 1.0
098: */
099: public boolean beforeUpdate(BeanType object);
100:
101: /**
102: * Is called after {@link
103: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#validate(Validated)}.
104: *
105: * @param object the bean instance that was validated
106: * @return <code>true</code> if the execution should continue as normal;
107: * or
108: * <p><code>false</code> if the execution should be interrupted
109: * @since 1.3
110: */
111: public boolean afterValidate(BeanType object);
112:
113: /**
114: * Is called after {@link
115: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#insert(Object)},
116: * or at the end of {@link
117: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#save(Object)}
118: * if a new bean was saved.
119: *
120: * @param object the bean instance that was inserted
121: * @param success <code>true</code> if the insert was successful; or
122: * <p><code>false</code> otherwise
123: * @return <code>true</code> if the execution should continue as normal;
124: * or
125: * <p><code>false</code> if the execution should be interrupted
126: * @since 1.0
127: */
128: public boolean afterInsert(BeanType object, boolean success);
129:
130: /**
131: * Is called after {@link
132: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#delete(int)}.
133: *
134: * @param objectId the id of the bean instance that was deleted
135: * @param success <code>true</code> if the delete was successful; or
136: * <p><code>false</code> otherwise
137: * @return <code>true</code> if the execution should continue as normal;
138: * or
139: * <p><code>false</code> if the execution should be interrupted
140: * @since 1.0
141: */
142: public boolean afterDelete(int objectId, boolean success);
143:
144: /**
145: * Is called after {@link
146: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#save(Object)}.
147: *
148: * @param object the bean instance that was saved
149: * @param success <code>true</code> if the save was successful; or
150: * <p><code>false</code> otherwise
151: * @return <code>true</code> if the execution should continue as normal;
152: * or
153: * <p><code>false</code> if the execution should be interrupted
154: * @since 1.0
155: */
156: public boolean afterSave(BeanType object, boolean success);
157:
158: /**
159: * Is called after {@link
160: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#update(Object)},
161: * or at the end of {@link
162: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#save(Object)}
163: * if an existing bean was saved.
164: *
165: * @param object the bean instance that was updated
166: * @param success <code>true</code> if the update was successful; or
167: * <p><code>false</code> otherwise
168: * @return <code>true</code> if the execution should continue as normal;
169: * or
170: * <p><code>false</code> if the execution should be interrupted
171: * @since 1.0
172: */
173: public boolean afterUpdate(BeanType object, boolean success);
174:
175: /**
176: * Is called after {@link
177: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#restore(int)}
178: * and {@link
179: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#restoreFirst(RestoreQuery)},
180: * and for every instance restored during {@link
181: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#restore()}
182: * and {@link
183: * com.uwyn.rife.database.querymanagers.generic.GenericQueryManager#restore(RestoreQuery)}.
184: *
185: * @param object the bean instance that was restored
186: * @return <code>true</code> if the execution should continue as normal;
187: * or
188: * <p><code>false</code> if the execution should be interrupted
189: * @since 1.0
190: */
191: public boolean afterRestore(BeanType object);
192: }
|