001package io.ebean.plugin;
002
003import io.ebean.FetchPath;
004import io.ebean.Query;
005import io.ebean.docstore.DocUpdateContext;
006
007import java.io.IOException;
008
009/**
010 * Doc store functions for a specific entity bean type.
011 *
012 * @param <T> The type of entity bean
013 */
014public interface BeanDocType<T> {
015
016  /**
017   * Return the doc store index type for this bean type.
018   */
019  default String indexType() {
020    return getIndexType();
021  }
022
023  /**
024   * Deprecated migrate to indexType().
025   */
026  @Deprecated
027  String getIndexType();
028
029  /**
030   * Return the doc store index name for this bean type.
031   */
032  default String indexName() {
033    return getIndexName();
034  }
035
036  /**
037   * Deprecated migrate to indexName().
038   */
039  @Deprecated
040  String getIndexName();
041
042  /**
043   * Apply the appropriate fetch path to the query such that the query returns beans matching
044   * the document store structure with the expected embedded properties.
045   */
046  void applyPath(Query<T> spiQuery);
047
048  /**
049   * Return the FetchPath for the embedded document.
050   */
051  default FetchPath embedded(String path) {
052    return getEmbedded(path);
053  }
054
055  /**
056   * Deprecated migrate to embedded().
057   */
058  @Deprecated
059  FetchPath getEmbedded(String path);
060
061  /**
062   * For embedded 'many' properties we need a FetchPath relative to the root which is used to
063   * build and replace the embedded list.
064   */
065  default FetchPath embeddedManyRoot(String path) {
066    return getEmbeddedManyRoot(path);
067  }
068
069  /**
070   * Deprecated migrate to embeddedManyRoot().
071   */
072  @Deprecated
073  FetchPath getEmbeddedManyRoot(String path);
074
075  /**
076   * Return a 'raw' property mapped for the given property.
077   * If none exists the given property is returned.
078   */
079  String rawProperty(String property);
080
081  /**
082   * Store the bean in the doc store index.
083   * <p>
084   * This somewhat assumes the bean is fetched with appropriate path properties
085   * to match the expected document structure.
086   */
087  void index(Object idValue, T bean, DocUpdateContext txn) throws IOException;
088
089  /**
090   * Add a delete by Id to the doc store.
091   */
092  void deleteById(Object idValue, DocUpdateContext txn) throws IOException;
093
094  /**
095   * Add a embedded document update to the doc store.
096   *
097   * @param idValue            the Id value of the bean holding the embedded document
098   * @param embeddedProperty   the embedded property
099   * @param embeddedRawContent the content of the embedded document in JSON form
100   * @param txn                the doc store transaction to add the update to
101   */
102  void updateEmbedded(Object idValue, String embeddedProperty, String embeddedRawContent, DocUpdateContext txn) throws IOException;
103
104}