001package com.avaje.ebean.event;
002
003import com.avaje.ebean.config.ServerConfig;
004
005import java.util.Set;
006
007/**
008 * Listens for committed bean events.
009 * <p>
010 * These listen events occur after a successful commit. They also occur in a
011 * background thread rather than the thread used to perform the actual insert
012 * update or delete. In this way there is a delay between the commit and when
013 * the listener is notified of the event.
014 * </p>
015 * <p>
016 * It is worth noting that BeanPersistListener is different in two main ways
017 * from BeanPersistController postXXX methods.
018 * <ul>
019 * <li>
020 *   BeanPersistListener only sees successfully committed events.
021 *   BeanPersistController pre and post methods occur before the commit or a
022 *   rollback and will see events that are later rolled back
023 * </li>
024 * <li>
025 *   BeanPersistListener runs in a background thread and will not effect the
026 *   response time of the actual persist where as BeanPersistController code will
027 * </li>
028 * </ul>
029 * </p>
030 * <p>
031 * A BeanPersistListener is either found automatically via class path search or
032 * can be added programmatically via {@link ServerConfig#add(BeanPersistListener)}}.
033 * </p>
034 * @see ServerConfig#add(BeanPersistListener)
035 */
036public interface BeanPersistListener {
037
038  /**
039   * Return true if this BeanPersistListener should be registered for events
040   * on this entity type.
041   */
042  boolean isRegisterFor(Class<?> cls);
043
044  /**
045   * Notified that a bean has been inserted.
046   * 
047   * @param bean
048   *          The bean that was inserted.
049   */
050  void inserted(Object bean);
051
052  /**
053   * Notified that a bean has been updated.
054   * 
055   * @param bean
056   *          The bean that was updated.
057   * @param updatedProperties
058   *          The properties that were modified by this update.
059   */
060  void updated(Object bean, Set<String> updatedProperties);
061
062  /**
063   * Notified that a bean has been deleted.
064   * 
065   * @param bean
066   *          The bean that was deleted.
067   */
068  void deleted(Object bean);
069
070}