001package com.avaje.ebean.config; 002 003import com.avaje.ebean.annotation.DocStoreMode; 004 005/** 006 * Configuration for the Document store integration (e.g. ElasticSearch). 007 */ 008public class DocStoreConfig { 009 010 /** 011 * True when the Document store integration is active/on. 012 */ 013 protected boolean active; 014 015 /** 016 * Set to true means Ebean will generate mapping files on startup. 017 */ 018 protected boolean generateMapping; 019 020 /** 021 * When true the Document store should drop and re-create document indexes. 022 */ 023 protected boolean dropCreate; 024 025 /** 026 * When true the Document store should create any document indexes that don't already exist. 027 */ 028 protected boolean create; 029 030 /** 031 * The URL of the Document store server. For example: http://localhost:9200. 032 */ 033 protected String url; 034 035 /** 036 * The default mode used by indexes. 037 */ 038 protected DocStoreMode persist = DocStoreMode.UPDATE; 039 040 /** 041 * The default batch size to use for the Bulk API calls. 042 */ 043 protected int bulkBatchSize = 1000; 044 045 /** 046 * Resource path for the Document store mapping files. 047 */ 048 protected String mappingPath; 049 050 /** 051 * Suffix used for mapping files. 052 */ 053 protected String mappingSuffix; 054 055 /** 056 * Location of resources that mapping files are generated into. 057 */ 058 protected String pathToResources = "src/main/resources"; 059 060 /** 061 * Return true if the Document store (ElasticSearch) integration is active. 062 */ 063 public boolean isActive() { 064 String systemValue = System.getProperty("ebean.docstore.active"); 065 if (systemValue != null) { 066 return Boolean.parseBoolean(systemValue); 067 } 068 return active; 069 } 070 071 /** 072 * Set to true to make the Document store (ElasticSearch) integration active. 073 */ 074 public void setActive(boolean active) { 075 this.active = active; 076 } 077 078 /** 079 * Return the URL to the Document store. 080 */ 081 public String getUrl() { 082 String systemValue = System.getProperty("ebean.docstore.url"); 083 if (systemValue != null) { 084 return systemValue; 085 } 086 087 return url; 088 } 089 090 /** 091 * Set the URL to the Document store server. 092 * <p> 093 * For a local ElasticSearch server this would be: http://localhost:9200 094 */ 095 public void setUrl(String url) { 096 this.url = url; 097 } 098 099 /** 100 * Return true if Ebean should generate mapping files on server startup. 101 */ 102 public boolean isGenerateMapping() { 103 return generateMapping; 104 } 105 106 /** 107 * Set to true if Ebean should generate mapping files on server startup. 108 */ 109 public void setGenerateMapping(boolean generateMapping) { 110 this.generateMapping = generateMapping; 111 } 112 113 /** 114 * Return true if the document store should recreate mapped indexes. 115 */ 116 public boolean isDropCreate() { 117 return dropCreate; 118 } 119 120 /** 121 * Set to true if the document store should recreate mapped indexes. 122 */ 123 public void setDropCreate(boolean dropCreate) { 124 this.dropCreate = dropCreate; 125 } 126 127 /** 128 * Create true if the document store should create mapped indexes that don't yet exist. 129 * This is only used if dropCreate is false. 130 */ 131 public boolean isCreate() { 132 return create; 133 } 134 135 /** 136 * Set to true if the document store should create mapped indexes that don't yet exist. 137 * This is only used if dropCreate is false. 138 */ 139 public void setCreate(boolean create) { 140 this.create = create; 141 } 142 143 /** 144 * Return the default batch size to use for calls to the Bulk API. 145 */ 146 public int getBulkBatchSize() { 147 return bulkBatchSize; 148 } 149 150 /** 151 * Set the default batch size to use for calls to the Bulk API. 152 * <p> 153 * The batch size can be set on a transaction via {@link com.avaje.ebean.Transaction#setDocStoreBatchSize(int)}. 154 * </p> 155 */ 156 public void setBulkBatchSize(int bulkBatchSize) { 157 this.bulkBatchSize = bulkBatchSize; 158 } 159 160 /** 161 * Return the mapping path. 162 */ 163 public String getMappingPath() { 164 return mappingPath; 165 } 166 167 /** 168 * Set the mapping path. 169 */ 170 public void setMappingPath(String mappingPath) { 171 this.mappingPath = mappingPath; 172 } 173 174 /** 175 * Return the mapping suffix. 176 */ 177 public String getMappingSuffix() { 178 return mappingSuffix; 179 } 180 181 /** 182 * Set the mapping suffix. 183 */ 184 public void setMappingSuffix(String mappingSuffix) { 185 this.mappingSuffix = mappingSuffix; 186 } 187 188 /** 189 * Return the relative file system path to resources when generating mapping files. 190 */ 191 public String getPathToResources() { 192 return pathToResources; 193 } 194 195 /** 196 * Set the relative file system path to resources when generating mapping files. 197 */ 198 public void setPathToResources(String pathToResources) { 199 this.pathToResources = pathToResources; 200 } 201 202 /** 203 * Return the default behavior for when Insert, Update and Delete events occur on beans that have an associated 204 * Document store. 205 */ 206 public DocStoreMode getPersist() { 207 return persist; 208 } 209 210 /** 211 * Set the default behavior for when Insert, Update and Delete events occur on beans that have an associated 212 * Document store. 213 * <ul> 214 * <li>DocStoreEvent.UPDATE - build and send message to Bulk API</li> 215 * <li>DocStoreEvent.QUEUE - add an entry with the index type and id only into a queue for later processing</li> 216 * <li>DocStoreEvent.IGNORE - ignore. Most likely used when some scheduled batch job handles updating the index</li> 217 * </ul> 218 * <p> 219 * You might choose to use QUEUE if that particular index data is updating very frequently or the cost of indexing 220 * is expensive. Setting it to QUEUE can mean many changes can be batched together potentially coalescing multiple 221 * updates for an index entry into a single update. 222 * </p> 223 * <p> 224 * You might choose to use IGNORE when you have your own external process for updating the indexes. In this case 225 * you don't want Ebean to do anything when the data changes. 226 * </p> 227 */ 228 public void setPersist(DocStoreMode persist) { 229 this.persist = persist; 230 } 231 232 /** 233 * Load settings specified in properties files. 234 */ 235 public void loadSettings(PropertiesWrapper properties) { 236 237 active = properties.getBoolean("docstore.active", active); 238 url = properties.get("docstore.url", url); 239 persist = properties.getEnum(DocStoreMode.class, "docstore.persist", persist); 240 bulkBatchSize = properties.getInt("docstore.bulkBatchSize", bulkBatchSize); 241 generateMapping = properties.getBoolean("docstore.generateMapping", generateMapping); 242 dropCreate = properties.getBoolean("docstore.dropCreate", dropCreate); 243 create = properties.getBoolean("docstore.create", create); 244 mappingPath = properties.get("docstore.mappingPath", mappingPath); 245 mappingSuffix = properties.get("docstore.mappingSuffix", mappingSuffix); 246 pathToResources = properties.get("docstore.pathToResources", pathToResources); 247 } 248}