001package io.ebeanservice.docstore.api; 002 003import io.ebean.Query; 004import io.ebean.annotation.DocStoreMode; 005import io.ebean.docstore.DocUpdateContext; 006import io.ebean.plugin.BeanDocType; 007import io.ebeaninternal.server.core.PersistRequest; 008import io.ebeaninternal.server.core.PersistRequestBean; 009import io.ebeanservice.docstore.api.mapping.DocumentMapping; 010 011import java.io.IOException; 012import java.util.Set; 013 014/** 015 * Doc store specific adapter to process doc store events for a given bean type. 016 */ 017public interface DocStoreBeanAdapter<T> extends BeanDocType<T> { 018 019 /** 020 * In deployment phase read the embedded/nested document information. 021 */ 022 void registerPaths(); 023 024 /** 025 * Register invalidation events for embedded/nested documents the given path and properties. 026 */ 027 void registerInvalidationPath(String queueId, String path, Set<String> properties); 028 029 /** 030 * Apply the document structure to the query so that it fetches the required properties to build 031 * the document (typically in JSON form). 032 */ 033 @Override 034 void applyPath(Query<T> query); 035 036 /** 037 * Return true if this type is mapped for doc storage. 038 */ 039 boolean mapped(); 040 041 /** 042 * Return the unique queueId for this bean type. This is expected to be a relatively short unique 043 * string (rather than a fully qualified class name). 044 */ 045 String queueId(); 046 047 /** 048 * Determine and return how this persist type will be processed given the transaction mode. 049 * <p> 050 * Some transactions (like bulk updates) might specifically turn off indexing for example. 051 */ 052 DocStoreMode mode(PersistRequest.Type persistType, DocStoreMode txnMode); 053 054 /** 055 * Return the index type for this bean type. 056 */ 057 String indexType(); 058 059 /** 060 * Return the index name for this bean type. 061 */ 062 @Override 063 String indexName(); 064 065 /** 066 * Process a delete by id of a given document. 067 */ 068 @Override 069 void deleteById(Object idValue, DocUpdateContext 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, DocUpdateContext 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, DocUpdateContext 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}