001package io.ebeanservice.docstore.api.mapping; 002 003import io.ebean.annotation.DocMapping; 004import io.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 @Override 064 public String toString() { 065 StringBuilder sb = new StringBuilder(); 066 if (code != null) { 067 sb.append("code:").append(code).append(" "); 068 } 069 if (sortable != null) { 070 sb.append("sortable:").append(sortable).append(" "); 071 } 072 if (store != null) { 073 sb.append("store:").append(store).append(" "); 074 } 075 if (boost != null) { 076 sb.append("boost:").append(boost).append(" "); 077 } 078 if (nullValue != null) { 079 sb.append("nullValue:").append(nullValue).append(" "); 080 } 081 return sb.toString(); 082 } 083 084 public boolean isCode() { 085 return Boolean.TRUE.equals(code); 086 } 087 088 public Boolean getCode() { 089 return code; 090 } 091 092 public void setCode(Boolean code) { 093 this.code = code; 094 } 095 096 public boolean isSortable() { 097 return Boolean.TRUE.equals(sortable); 098 } 099 100 public Boolean getSortable() { 101 return sortable; 102 } 103 104 public void setSortable(Boolean sortable) { 105 this.sortable = sortable; 106 } 107 108 public Float getBoost() { 109 return boost; 110 } 111 112 public void setBoost(Float boost) { 113 this.boost = boost; 114 } 115 116 public String getNullValue() { 117 return nullValue; 118 } 119 120 public void setNullValue(String nullValue) { 121 this.nullValue = nullValue; 122 } 123 124 public Boolean getStore() { 125 return store; 126 } 127 128 public void setStore(Boolean store) { 129 this.store = store; 130 } 131 132 public Boolean getIncludeInAll() { 133 return includeInAll; 134 } 135 136 public void setIncludeInAll(Boolean includeInAll) { 137 this.includeInAll = includeInAll; 138 } 139 140 public Boolean getDocValues() { 141 return docValues; 142 } 143 144 public void setDocValues(Boolean docValues) { 145 this.docValues = docValues; 146 } 147 148 public String getAnalyzer() { 149 return analyzer; 150 } 151 152 public void setAnalyzer(String analyzer) { 153 this.analyzer = analyzer; 154 } 155 156 public String getSearchAnalyzer() { 157 return searchAnalyzer; 158 } 159 160 public void setSearchAnalyzer(String searchAnalyzer) { 161 this.searchAnalyzer = searchAnalyzer; 162 } 163 164 public String getCopyTo() { 165 return copyTo; 166 } 167 168 public void setCopyTo(String copyTo) { 169 this.copyTo = copyTo; 170 } 171 172 public Boolean getEnabled() { 173 return enabled; 174 } 175 176 public void setEnabled(Boolean enabled) { 177 this.enabled = enabled; 178 } 179 180 public Boolean getNorms() { 181 return norms; 182 } 183 184 public void setNorms(Boolean norms) { 185 this.norms = norms; 186 } 187 188 /** 189 * Return true if the index options is set to a non-default value. 190 */ 191 public boolean isOptionsSet() { 192 return options != null && options != DocProperty.Option.DEFAULT; 193 } 194 195 public DocProperty.Option getOptions() { 196 return options; 197 } 198 199 public void setOptions(DocProperty.Option options) { 200 this.options = options; 201 } 202 203 /** 204 * Create a copy of this such that it can be overridden on a per index basis. 205 */ 206 public DocPropertyOptions copy() { 207 return new DocPropertyOptions(this); 208 } 209 210 /** 211 * Apply override mapping from the document level or embedded property level. 212 */ 213 public void apply(DocMapping docMapping) { 214 apply(docMapping.options()); 215 } 216 217 /** 218 * Apply the property level mapping options. 219 */ 220 public void apply(DocProperty docMapping) { 221 222 options = docMapping.options(); 223 if (docMapping.code()) { 224 code = true; 225 } 226 if (docMapping.sortable()) { 227 sortable = true; 228 } 229 if (docMapping.store()) { 230 store = true; 231 } 232 if (Float.compare(docMapping.boost(), 1.0F) != 0) { 233 boost = docMapping.boost(); 234 } 235 if (!"".equals(docMapping.nullValue())) { 236 nullValue = docMapping.nullValue(); 237 } 238 if (!docMapping.includeInAll()) { 239 includeInAll = false; 240 } 241 if (!docMapping.docValues()) { 242 docValues = false; 243 } 244 if (!docMapping.enabled()) { 245 enabled = false; 246 } 247 if (!docMapping.norms()) { 248 norms = false; 249 } 250 if (!"".equals(docMapping.analyzer())) { 251 analyzer = docMapping.analyzer(); 252 } 253 if (!"".equals(docMapping.searchAnalyzer())) { 254 searchAnalyzer = docMapping.searchAnalyzer(); 255 } 256 if (!"".equals(docMapping.copyTo())) { 257 copyTo = docMapping.copyTo(); 258 } 259 } 260 261}