001package com.avaje.ebeanservice.docstore.api; 002 003import com.avaje.ebean.Query; 004import com.avaje.ebean.annotation.DocStoreMode; 005import com.avaje.ebean.plugin.BeanDocType; 006import com.avaje.ebeaninternal.server.core.PersistRequest; 007import com.avaje.ebeaninternal.server.core.PersistRequestBean; 008import com.avaje.ebeanservice.docstore.api.mapping.DocumentMapping; 009 010import java.io.IOException; 011import java.util.Set; 012 013/** 014 * Doc store specific adapter to process doc store events for a given bean type. 015 */ 016public interface DocStoreBeanAdapter<T> extends BeanDocType<T> { 017 018 /** 019 * In deployment phase read the embedded/nested document information. 020 */ 021 void registerPaths(); 022 023 /** 024 * Register invalidation events for embedded/nested documents the given path and properties. 025 */ 026 void registerInvalidationPath(String queueId, String path, Set<String> properties); 027 028 /** 029 * Apply the document structure to the query so that it fetches the required properties to build 030 * the document (typically in JSON form). 031 */ 032 void applyPath(Query<T> query); 033 034 /** 035 * Return true if this type is mapped for doc storage. 036 */ 037 boolean isMapped(); 038 039 /** 040 * Return the unique queueId for this bean type. This is expected to be a relatively short unique 041 * string (rather than a fully qualified class name). 042 */ 043 String getQueueId(); 044 045 /** 046 * Determine and return how this persist type will be processed given the transaction mode. 047 * <p> 048 * Some transactions (like bulk updates) might specifically turn off indexing for example. 049 */ 050 DocStoreMode getMode(PersistRequest.Type persistType, DocStoreMode txnMode); 051 052 /** 053 * Return the index type for this bean type. 054 */ 055 String getIndexType(); 056 057 /** 058 * Return the index name for this bean type. 059 */ 060 String getIndexName(); 061 062 /** 063 * Process a delete by id of a given document. 064 */ 065 void deleteById(Object idValue, DocStoreUpdateContext txn) throws IOException; 066 067 /** 068 * Process an index event which is effectively an insert or update (or put). 069 */ 070 void index(Object idValue, T entityBean, DocStoreUpdateContext txn) throws IOException; 071 072 /** 073 * Process an insert persist request. 074 */ 075 void insert(Object idValue, PersistRequestBean<T> persistRequest, DocStoreUpdateContext txn) throws IOException; 076 077 /** 078 * Process an update persist request. 079 */ 080 void update(Object idValue, PersistRequestBean<T> persistRequest, DocStoreUpdateContext txn) throws IOException; 081 082 /** 083 * Process the persist request adding any embedded/nested document invalidation to the docStoreUpdates. 084 * <p> 085 * This is expected to check the specific properties to see what other documents they are nested in 086 * and register invalidation events based on that. 087 * 088 * @param request The persist request 089 * @param docStoreUpdates Invalidation events are registered to this docStoreUpdates 090 */ 091 void updateEmbedded(PersistRequestBean<T> request, DocStoreUpdates docStoreUpdates); 092 093 /** 094 * Process an update of an embedded document. 095 * 096 * @param idValue the id of the bean effected by an embedded document update 097 * @param embeddedProperty the path of the property 098 * @param embeddedRawContent the embedded content for this property in JSON form 099 * @param txn the doc store transaction to use to process the update 100 */ 101 void updateEmbedded(Object idValue, String embeddedProperty, String embeddedRawContent, DocStoreUpdateContext txn) throws IOException; 102 103 /** 104 * Create the document mapping. 105 */ 106 DocumentMapping createDocMapping(); 107 108 /** 109 * Return an un-analysed property to use instead of the given property. 110 * <p> 111 * For analysed properties that we want to sort on we will map the property to an additional 112 * 'raw' property that we can use for sorting etc. 113 * </p> 114 */ 115 String rawProperty(String property); 116 117 /** 118 * Return true if this bean type as embedded invalidate registered. 119 */ 120 boolean hasEmbeddedInvalidation(); 121}