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