001package io.ebeanservice.docstore.api.support;
002
003import io.ebean.plugin.BeanType;
004import io.ebeanservice.docstore.api.DocStoreUpdate;
005import io.ebeanservice.docstore.api.DocStoreUpdateContext;
006import io.ebeanservice.docstore.api.DocStoreUpdates;
007
008import java.io.IOException;
009
010/**
011 * A 'Delete by Id' request that is send to the document store.
012 */
013public final class DocStoreIndexEvent<T> implements DocStoreUpdate {
014
015  private final BeanType<T> beanType;
016  private final Object idValue;
017  private final T bean;
018
019  public DocStoreIndexEvent(BeanType<T> beanType, Object idValue, T bean) {
020    this.beanType = beanType;
021    this.idValue = idValue;
022    this.bean = bean;
023  }
024
025  /**
026   * Add appropriate JSON content for sending to the ElasticSearch Bulk API.
027   */
028  @Override
029  public void docStoreUpdate(DocStoreUpdateContext txn) throws IOException {
030    beanType.docStore().index(idValue, bean, txn);
031  }
032
033  /**
034   * Add this event to the queue (for queue delayed processing).
035   */
036  @Override
037  public void addToQueue(DocStoreUpdates docStoreUpdates) {
038    docStoreUpdates.queueIndex(beanType.docStoreQueueId(), idValue);
039  }
040}