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 class DocStoreIndexEvent<T> implements DocStoreUpdate { 014 015 private final BeanType<T> beanType; 016 017 private final Object idValue; 018 019 private final T bean; 020 021 public DocStoreIndexEvent(BeanType<T> beanType, Object idValue, T bean) { 022 this.beanType = beanType; 023 this.idValue = idValue; 024 this.bean = bean; 025 } 026 027 /** 028 * Add appropriate JSON content for sending to the ElasticSearch Bulk API. 029 */ 030 @Override 031 public void docStoreUpdate(DocStoreUpdateContext txn) throws IOException { 032 beanType.docStore().index(idValue, bean, txn); 033 } 034 035 /** 036 * Add this event to the queue (for queue delayed processing). 037 */ 038 @Override 039 public void addToQueue(DocStoreUpdates docStoreUpdates) { 040 docStoreUpdates.queueIndex(beanType.getDocStoreQueueId(), idValue); 041 } 042}