001package io.ebean.event;
002
003import io.ebean.config.DatabaseConfig;
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 DatabaseConfig#add(BeanPersistListener)}}.
033 * </p>
034 *
035 * @see DatabaseConfig#add(BeanPersistListener)
036 */
037public interface BeanPersistListener {
038
039  /**
040   * Return true if this BeanPersistListener should be registered for events
041   * on this entity type.
042   */
043  boolean isRegisterFor(Class<?> cls);
044
045  /**
046   * Notified that a bean has been inserted.
047   *
048   * @param bean 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              The bean that was updated.
056   * @param updatedProperties The properties that were modified by this update.
057   */
058  void updated(Object bean, Set<String> updatedProperties);
059
060  /**
061   * Notified that a bean has been deleted.
062   *
063   * @param bean The bean that was deleted.
064   */
065  void deleted(Object bean);
066
067  /**
068   * Notified that a bean has been soft deleted.
069   *
070   * @param bean The bean that was soft deleted.
071   */
072  void softDeleted(Object bean);
073
074}