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