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