001package io.ebean.event;
002
003import io.ebean.Database;
004import io.ebean.EbeanServer;
005import io.ebean.Transaction;
006import io.ebean.ValuePair;
007
008import java.util.Map;
009import java.util.Set;
010
011/**
012 * Holds the information available for a bean persist (insert, update or
013 * delete).
014 * <p>
015 * This is made available for the BeanPersistControllers.
016 * </p>
017 */
018public interface BeanPersistRequest<T> {
019
020  /**
021   * Return the DB processing the request.
022   */
023  default Database database() {
024    return getEbeanServer();
025  }
026
027  /**
028   * Deprecated migrate to database().
029   */
030  @Deprecated
031  EbeanServer getEbeanServer();
032
033  /**
034   * Return the Transaction associated with this request.
035   */
036  Transaction transaction();
037
038  /**
039   * Deprecated migrate to transaction().
040   */
041  @Deprecated
042  default Transaction getTransaction() {
043    return transaction();
044  }
045
046  /**
047   * Return true if this request is due to cascading persist.
048   * False implies this is a "top level" request.
049   */
050  boolean isCascade();
051
052  /**
053   * For an update or delete of a partially populated bean this is the set of
054   * loaded properties and otherwise returns null.
055   */
056  Set<String> loadedProperties();
057
058  /**
059   * Deprecated migrate to loadedProperties().
060   */
061  @Deprecated
062  default Set<String> getLoadedProperties() {
063    return loadedProperties();
064  }
065
066  /**
067   * For an update this is the set of properties that where updated.
068   * <p>
069   * Note that hasDirtyProperty() is a more efficient check than this method and
070   * should be preferred if it satisfies the requirement.
071   * </p>
072   */
073  Set<String> updatedProperties();
074
075  /**
076   * Deprecated migrate to updatedProperties().
077   */
078  @Deprecated
079  default Set<String> getUpdatedProperties() {
080    return updatedProperties();
081  }
082
083  /**
084   * Flags set for dirty properties (used by ElasticSearch integration).
085   */
086  boolean[] dirtyProperties();
087
088  /**
089   * Deprecated migrate to updatedProperties().
090   */
091  @Deprecated
092  default boolean[] getDirtyProperties() {
093    return dirtyProperties();
094  }
095
096  /**
097   * Return true for an update request if at least one of dirty properties is contained
098   * in the given set of property names.
099   * <p>
100   * This method will produce less GC compared with getUpdatedProperties() and should
101   * be preferred if it satisfies the requirement.
102   * </p>
103   * <p>
104   * Note that this method is used by the default ChangeLogFilter mechanism for when
105   * the <code>@ChangeLog</code> updatesThatInclude attribute has been specified.
106   * </p>
107   *
108   * @param propertyNames a set of property names which we are checking to see if at least
109   *                      one of them is dirty.
110   */
111  boolean hasDirtyProperty(Set<String> propertyNames);
112
113  /**
114   * Returns the bean being inserted updated or deleted.
115   */
116  T bean();
117
118  /**
119   * Deprecated migrate to bean().
120   */
121  @Deprecated
122  default T getBean() {
123    return bean();
124  }
125
126  /**
127   * Returns a map of the properties that have changed and their new and old values.
128   */
129  Map<String, ValuePair> updatedValues();
130
131  /**
132   * Deprecated migrate to updatedValues().
133   */
134  @Deprecated
135  default Map<String, ValuePair> getUpdatedValues() {
136    return updatedValues();
137  }
138
139}