001package io.ebeanservice.docstore.api; 002 003import io.ebean.DocStoreQueueEntry; 004import io.ebean.DocStoreQueueEntry.Action; 005 006import java.util.ArrayList; 007import java.util.List; 008 009/** 010 * Collection of document store updates that are either sent to the document store 011 * or queued for future processing 012 */ 013public class DocStoreUpdates { 014 015 /** 016 * Persist inserts and updates. 017 */ 018 private final List<DocStoreUpdate> persistEvents = new ArrayList<>(); 019 020 /** 021 * Delete by Id. 022 */ 023 private final List<DocStoreUpdate> deleteEvents = new ArrayList<>(); 024 025 /** 026 * Nested updates. 027 */ 028 private final List<DocStoreQueueEntry> nestedEvents = new ArrayList<>(); 029 030 /** 031 * Entries sent to the queue for later processing. 032 */ 033 private final List<DocStoreQueueEntry> queueEntries = new ArrayList<>(); 034 035 public DocStoreUpdates() { 036 } 037 038 /** 039 * Return true if there are no events to process. 040 */ 041 public boolean isEmpty() { 042 return persistEvents.isEmpty() && deleteEvents.isEmpty() && nestedEvents.isEmpty() && queueEntries.isEmpty(); 043 } 044 045 /** 046 * Add a persist request. 047 */ 048 public void addPersist(DocStoreUpdate bulkRequest) { 049 persistEvents.add(bulkRequest); 050 } 051 052 /** 053 * Add a delete request. 054 */ 055 public void addDelete(DocStoreUpdate bulkRequest) { 056 deleteEvents.add(bulkRequest); 057 } 058 059 /** 060 * Add a nested update. 061 */ 062 public void addNested(String queueId, String path, Object beanId) { 063 nestedEvents.add(new DocStoreQueueEntry(Action.NESTED, queueId, path, beanId)); 064 } 065 066 /** 067 * Queue an 'index' request. 068 */ 069 public void queueIndex(String queueId, Object beanId) { 070 queueEntries.add(new DocStoreQueueEntry(Action.INDEX, queueId, beanId)); 071 } 072 073 /** 074 * Queue a 'delete' request. 075 */ 076 public void queueDelete(String queueId, Object beanId) { 077 queueEntries.add(new DocStoreQueueEntry(Action.DELETE, queueId, beanId)); 078 } 079 080 /** 081 * Queue an update to a nested/embedded object. 082 */ 083 public void queueNested(String queueId, String path, Object beanId) { 084 queueEntries.add(new DocStoreQueueEntry(Action.NESTED, queueId, path, beanId)); 085 } 086 087 /** 088 * Return the persist insert and update requests to be sent to the document store. 089 */ 090 public List<DocStoreUpdate> getPersistEvents() { 091 return persistEvents; 092 } 093 094 /** 095 * Return delete events. 096 */ 097 public List<DocStoreUpdate> getDeleteEvents() { 098 return deleteEvents; 099 } 100 101 /** 102 * Return the list of nested update events. 103 */ 104 public List<DocStoreQueueEntry> getNestedEvents() { 105 return nestedEvents; 106 } 107 108 /** 109 * Return the entries for sending to the queue. 110 */ 111 public List<DocStoreQueueEntry> getQueueEntries() { 112 return queueEntries; 113 } 114 115}