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 isMapped(); 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 getQueueId(); 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 getMode(PersistRequest.Type persistType, DocStoreMode txnMode); 053 054 /** 055 * Return the index type for this bean type. 056 */ 057 @Override 058 String getIndexType(); 059 060 /** 061 * Return the index name for this bean type. 062 */ 063 @Override 064 String getIndexName(); 065 066 /** 067 * Process a delete by id of a given document. 068 */ 069 @Override 070 void deleteById(Object idValue, DocUpdateContext txn) throws IOException; 071 072 /** 073 * Process an index event which is effectively an insert or update (or put). 074 */ 075 @Override 076 void index(Object idValue, T entityBean, DocUpdateContext txn) throws IOException; 077 078 /** 079 * Process an insert persist request. 080 */ 081 void insert(Object idValue, PersistRequestBean<T> persistRequest, DocStoreUpdateContext txn) throws IOException; 082 083 /** 084 * Process an update persist request. 085 */ 086 void update(Object idValue, PersistRequestBean<T> persistRequest, DocStoreUpdateContext txn) throws IOException; 087 088 /** 089 * Process the persist request adding any embedded/nested document invalidation to the docStoreUpdates. 090 * <p> 091 * This is expected to check the specific properties to see what other documents they are nested in 092 * and register invalidation events based on that. 093 * 094 * @param request The persist request 095 * @param docStoreUpdates Invalidation events are registered to this docStoreUpdates 096 */ 097 void updateEmbedded(PersistRequestBean<T> request, DocStoreUpdates docStoreUpdates); 098 099 /** 100 * Process an update of an embedded document. 101 * 102 * @param idValue the id of the bean effected by an embedded document update 103 * @param embeddedProperty the path of the property 104 * @param embeddedRawContent the embedded content for this property in JSON form 105 * @param txn the doc store transaction to use to process the update 106 */ 107 @Override 108 void updateEmbedded(Object idValue, String embeddedProperty, String embeddedRawContent, DocUpdateContext txn) throws IOException; 109 110 /** 111 * Create the document mapping. 112 */ 113 DocumentMapping createDocMapping(); 114 115 /** 116 * Return an un-analysed property to use instead of the given property. 117 * <p> 118 * For analysed properties that we want to sort on we will map the property to an additional 119 * 'raw' property that we can use for sorting etc. 120 * </p> 121 */ 122 @Override 123 String rawProperty(String property); 124 125 /** 126 * Return true if this bean type as embedded invalidate registered. 127 */ 128 boolean hasEmbeddedInvalidation(); 129}