001package io.ebean.plugin;
002
003import io.ebean.FetchPath;
004import io.ebean.Query;
005import io.ebeanservice.docstore.api.DocStoreUpdateContext;
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  String getIndexType();
020
021  /**
022   * Return the doc store index name for this bean type.
023   */
024  String getIndexName();
025
026  /**
027   * Apply the appropriate fetch path to the query such that the query returns beans matching
028   * the document store structure with the expected embedded properties.
029   */
030  void applyPath(Query<T> spiQuery);
031
032  /**
033   * Return the FetchPath for the embedded document.
034   */
035  FetchPath getEmbedded(String path);
036
037  /**
038   * For embedded 'many' properties we need a FetchPath relative to the root which is used to
039   * build and replace the embedded list.
040   */
041  FetchPath getEmbeddedManyRoot(String path);
042
043  /**
044   * Return a 'raw' property mapped for the given property.
045   * If none exists the given property is returned.
046   */
047  String rawProperty(String property);
048
049  /**
050   * Store the bean in the doc store index.
051   * <p>
052   * This somewhat assumes the bean is fetched with appropriate path properties
053   * to match the expected document structure.
054   */
055  void index(Object idValue, T bean, DocStoreUpdateContext txn) throws IOException;
056
057  /**
058   * Add a delete by Id to the doc store.
059   */
060  void deleteById(Object idValue, DocStoreUpdateContext txn) throws IOException;
061
062  /**
063   * Add a embedded document update to the doc store.
064   *
065   * @param idValue            the Id value of the bean holding the embedded document
066   * @param embeddedProperty   the embedded property
067   * @param embeddedRawContent the content of the embedded document in JSON form
068   * @param txn                the doc store transaction to add the update to
069   */
070  void updateEmbedded(Object idValue, String embeddedProperty, String embeddedRawContent, DocStoreUpdateContext txn) throws IOException;
071
072}