001package com.avaje.ebeanservice.docstore.api.mapping; 002 003import com.avaje.ebean.annotation.DocMapping; 004import com.avaje.ebean.annotation.DocProperty; 005 006/** 007 * Options for mapping a property for document storage. 008 */ 009public class DocPropertyOptions { 010 011 private Boolean code; 012 013 private Boolean sortable; 014 015 private Boolean store; 016 017 private Float boost; 018 019 private String nullValue; 020 021 private Boolean includeInAll; 022 023 private Boolean enabled; 024 025 private Boolean norms; 026 027 private Boolean docValues; 028 029 private String analyzer; 030 031 private String searchAnalyzer; 032 033 private String copyTo; 034 035 private DocProperty.Option options; 036 037 /** 038 * Construct with no values set. 039 */ 040 public DocPropertyOptions() { 041 042 } 043 044 /** 045 * Construct as a copy of the source options. 046 */ 047 protected DocPropertyOptions(DocPropertyOptions source) { 048 this.code = source.code; 049 this.sortable = source.sortable; 050 this.store = source.store; 051 this.boost = source.boost; 052 this.nullValue = source.nullValue; 053 this.includeInAll = source.includeInAll; 054 this.analyzer = source.analyzer; 055 this.searchAnalyzer = source.searchAnalyzer; 056 this.options = source.options; 057 this.docValues = source.docValues; 058 this.norms = source.norms; 059 this.copyTo = source.copyTo; 060 this.enabled = source.enabled; 061 } 062 063 public String toString() { 064 StringBuilder sb = new StringBuilder(); 065 if (code != null) { 066 sb.append("code:").append(code).append(" "); 067 } 068 if (sortable != null) { 069 sb.append("sortable:").append(sortable).append(" "); 070 } 071 if (store != null) { 072 sb.append("store:").append(store).append(" "); 073 } 074 if (boost != null) { 075 sb.append("boost:").append(boost).append(" "); 076 } 077 if (nullValue != null) { 078 sb.append("nullValue:").append(nullValue).append(" "); 079 } 080 return sb.toString(); 081 } 082 083 public Boolean getCode() { 084 return code; 085 } 086 087 public void setCode(Boolean code) { 088 this.code = code; 089 } 090 091 public Boolean getSortable() { 092 return sortable; 093 } 094 095 public void setSortable(Boolean sortable) { 096 this.sortable = sortable; 097 } 098 099 public Float getBoost() { 100 return boost; 101 } 102 103 public void setBoost(Float boost) { 104 this.boost = boost; 105 } 106 107 public String getNullValue() { 108 return nullValue; 109 } 110 111 public void setNullValue(String nullValue) { 112 this.nullValue = nullValue; 113 } 114 115 public Boolean getStore() { 116 return store; 117 } 118 119 public void setStore(Boolean store) { 120 this.store = store; 121 } 122 123 public Boolean getIncludeInAll() { 124 return includeInAll; 125 } 126 127 public void setIncludeInAll(Boolean includeInAll) { 128 this.includeInAll = includeInAll; 129 } 130 131 public Boolean getDocValues() { 132 return docValues; 133 } 134 135 public void setDocValues(Boolean docValues) { 136 this.docValues = docValues; 137 } 138 139 public String getAnalyzer() { 140 return analyzer; 141 } 142 143 public void setAnalyzer(String analyzer) { 144 this.analyzer = analyzer; 145 } 146 147 public String getSearchAnalyzer() { 148 return searchAnalyzer; 149 } 150 151 public void setSearchAnalyzer(String searchAnalyzer) { 152 this.searchAnalyzer = searchAnalyzer; 153 } 154 155 public String getCopyTo() { 156 return copyTo; 157 } 158 159 public void setCopyTo(String copyTo) { 160 this.copyTo = copyTo; 161 } 162 163 public Boolean getEnabled() { 164 return enabled; 165 } 166 167 public void setEnabled(Boolean enabled) { 168 this.enabled = enabled; 169 } 170 171 public Boolean getNorms() { 172 return norms; 173 } 174 175 public void setNorms(Boolean norms) { 176 this.norms = norms; 177 } 178 179 /** 180 * Return true if the index options is set to a non-default value. 181 */ 182 public boolean isOptionsSet() { 183 return options != null && options != DocProperty.Option.DEFAULT; 184 } 185 186 public DocProperty.Option getOptions() { 187 return options; 188 } 189 190 public void setOptions(DocProperty.Option options) { 191 this.options = options; 192 } 193 194 /** 195 * Create a copy of this such that it can be overridden on a per index basis. 196 */ 197 public DocPropertyOptions copy() { 198 return new DocPropertyOptions(this); 199 } 200 201 /** 202 * Apply override mapping from the document level or embedded property level. 203 */ 204 public void apply(DocMapping docMapping) { 205 apply(docMapping.options()); 206 } 207 208 /** 209 * Apply the property level mapping options. 210 */ 211 public void apply(DocProperty docMapping) { 212 213 options = docMapping.options(); 214 if (docMapping.code()) { 215 code = true; 216 } 217 if (docMapping.sortable()) { 218 sortable = true; 219 } 220 if (docMapping.store()) { 221 store = true; 222 } 223 if (docMapping.boost() != 1) { 224 boost = docMapping.boost(); 225 } 226 if (!"".equals(docMapping.nullValue())) { 227 nullValue = docMapping.nullValue(); 228 } 229 if (!docMapping.includeInAll()) { 230 includeInAll = false; 231 } 232 if (!docMapping.docValues()) { 233 docValues = false; 234 } 235 if (!docMapping.enabled()) { 236 enabled = false; 237 } 238 if (!docMapping.norms()) { 239 norms = false; 240 } 241 if (!"".equals(docMapping.analyzer())) { 242 analyzer = docMapping.analyzer(); 243 } 244 if (!"".equals(docMapping.searchAnalyzer())) { 245 searchAnalyzer = docMapping.searchAnalyzer(); 246 } 247 if (!"".equals(docMapping.copyTo())) { 248 copyTo = docMapping.copyTo(); 249 } 250 } 251 252}