001package io.ebean.plugin; 002 003import io.ebean.Query; 004import io.ebean.config.dbplatform.IdType; 005import io.ebean.docstore.DocMapping; 006import io.ebean.event.BeanFindController; 007import io.ebean.event.BeanPersistController; 008import io.ebean.event.BeanPersistListener; 009import io.ebean.event.BeanQueryAdapter; 010 011import java.util.Collection; 012import java.util.List; 013import java.util.function.Consumer; 014 015/** 016 * Information and methods on BeanDescriptors made available to plugins. 017 */ 018public interface BeanType<T> { 019 020 /** 021 * Return the short name of the bean type. 022 */ 023 String name(); 024 025 /** 026 * Deprecated migrate to name(). 027 */ 028 @Deprecated 029 default String getName() { 030 return name(); 031 } 032 033 /** 034 * Return the full name of the bean type. 035 */ 036 String fullName(); 037 038 /** 039 * Deprecated migrate to fullName(). 040 */ 041 @Deprecated 042 default String getFullName() { 043 return fullName(); 044 } 045 046 /** 047 * Return the class type this BeanDescriptor describes. 048 */ 049 Class<T> type(); 050 051 /** 052 * Deprecated migrate to type(). 053 */ 054 @Deprecated 055 default Class<T> getBeanType() { 056 return type(); 057 } 058 059 /** 060 * Return the type bean for an OneToMany or ManyToOne or ManyToMany property. 061 */ 062 BeanType<?> beanTypeAtPath(String propertyName); 063 064 /** 065 * Deprecated migrate to beanTypeAtPath(). 066 */ 067 @Deprecated 068 default BeanType<?> getBeanTypeAtPath(String propertyName) { 069 return beanTypeAtPath(propertyName); 070 } 071 072 /** 073 * Return all the properties for this bean type. 074 */ 075 Collection<? extends Property> allProperties(); 076 077 /** 078 * Return the Id property. 079 */ 080 Property idProperty(); 081 082 /** 083 * Deprecated migrate to idProperty(). 084 */ 085 @Deprecated 086 default Property getIdProperty() { 087 return idProperty(); 088 } 089 090 /** 091 * Return the when modified property if there is one defined. 092 */ 093 Property whenModifiedProperty(); 094 095 /** 096 * Deprecated migrate to idProperty(). 097 */ 098 @Deprecated 099 default Property getWhenModifiedProperty() { 100 return whenModifiedProperty(); 101 } 102 103 /** 104 * Return the when created property if there is one defined. 105 */ 106 Property whenCreatedProperty(); 107 108 /** 109 * Deprecated migrate to idProperty(). 110 */ 111 @Deprecated 112 default Property getWhenCreatedProperty() { 113 return whenCreatedProperty(); 114 } 115 116 /** 117 * Return the Property to read values from a bean. 118 */ 119 Property property(String propertyName); 120 121 /** 122 * Deprecated migrate to property(). 123 */ 124 @Deprecated 125 default Property getProperty(String propertyName) { 126 return property(propertyName); 127 } 128 129 /** 130 * Return the ExpressionPath for a given property path. 131 * <p> 132 * This can return a property or nested property path. 133 * </p> 134 */ 135 ExpressionPath expressionPath(String path); 136 137 /** 138 * Deprecated migrate to expressionPath(). 139 */ 140 @Deprecated 141 default ExpressionPath getExpressionPath(String path) { 142 return expressionPath(path); 143 } 144 145 /** 146 * Return true if the property is a valid known property or path for the given bean type. 147 */ 148 boolean isValidExpression(String property); 149 150 /** 151 * Return true if bean caching is on for this bean type. 152 */ 153 boolean isBeanCaching(); 154 155 /** 156 * Return true if query caching is on for this bean type. 157 */ 158 boolean isQueryCaching(); 159 160 /** 161 * Clear the bean cache. 162 */ 163 void clearBeanCache(); 164 165 /** 166 * Clear the query cache. 167 */ 168 void clearQueryCache(); 169 170 /** 171 * Return true if the type is document store only. 172 */ 173 boolean isDocStoreOnly(); 174 175 /** 176 * Return the base table this bean type maps to. 177 */ 178 String baseTable(); 179 180 /** 181 * Deprecated migrate to baseTable(). 182 */ 183 @Deprecated 184 default String getBaseTable() { 185 return baseTable(); 186 } 187 188 /** 189 * Create a new instance of the bean. 190 */ 191 T createBean(); 192 193 /** 194 * Return the bean id. This is the same as getBeanId() but without the generic type. 195 */ 196 Object id(Object bean); 197 198 /** 199 * Deprecated migrate to id() 200 */ 201 @Deprecated 202 default Object beanId(Object bean) { 203 return id(bean); 204 } 205 206 /** 207 * Deprecated migrate to id() 208 */ 209 @Deprecated 210 Object getBeanId(T bean); 211 212 /** 213 * Set the id value to the bean. 214 */ 215 void setId(T bean, Object idValue); 216 217 /** 218 * Deprecated migrate to setId() 219 */ 220 @Deprecated 221 default void setBeanId(T bean, Object idValue) { 222 setId(bean, idValue); 223 } 224 225 /** 226 * Return the bean persist controller. 227 */ 228 BeanPersistController persistController(); 229 230 /** 231 * Deprecated migrate to persistController() 232 */ 233 @Deprecated 234 default BeanPersistController getPersistController() { 235 return persistController(); 236 } 237 238 /** 239 * Return the bean persist listener. 240 */ 241 BeanPersistListener persistListener(); 242 243 /** 244 * Deprecated migrate to persistListener() 245 */ 246 @Deprecated 247 default BeanPersistListener getPersistListener() { 248 return persistListener(); 249 } 250 251 /** 252 * Return the beanFinder. Usually null unless overriding the finder. 253 */ 254 BeanFindController findController(); 255 256 /** 257 * Deprecated migrate to findController() 258 */ 259 @Deprecated 260 default BeanFindController getFindController() { 261 return findController(); 262 } 263 264 /** 265 * Return the BeanQueryAdapter or null if none is defined. 266 */ 267 BeanQueryAdapter queryAdapter(); 268 269 /** 270 * Deprecated migrate to queryAdapter() 271 */ 272 @Deprecated 273 default BeanQueryAdapter getQueryAdapter() { 274 return queryAdapter(); 275 } 276 277 /** 278 * Return the identity generation type. 279 */ 280 IdType idType(); 281 282 /** 283 * Deprecated migrate to idType() 284 */ 285 @Deprecated 286 default IdType getIdType() { 287 return idType(); 288 } 289 290 /** 291 * Return true if this bean type has doc store backing. 292 */ 293 boolean isDocStoreMapped(); 294 295 /** 296 * Return the DocumentMapping for this bean type. 297 * <p> 298 * This is the document structure and mapping options for how this bean type is mapped 299 * for the document store. 300 * </p> 301 */ 302 DocMapping docMapping(); 303 304 /** 305 * Deprecated migrate to docMapping() 306 */ 307 @Deprecated 308 default DocMapping getDocMapping() { 309 return docMapping(); 310 } 311 312 /** 313 * Return the doc store queueId for this bean type. 314 */ 315 String docStoreQueueId(); 316 317 /** 318 * Deprecated migrate to docStoreQueueId() 319 */ 320 @Deprecated 321 default String getDocStoreQueueId() { 322 return docStoreQueueId(); 323 } 324 325 /** 326 * Return the doc store support for this bean type.\ 327 */ 328 BeanDocType<T> docStore(); 329 330 /** 331 * Add the discriminator value to the query if needed. 332 */ 333 void addInheritanceWhere(Query<?> query); 334 335 /** 336 * Return the root bean type for an inheritance hierarchy. 337 */ 338 BeanType<?> root(); 339 340 /** 341 * Return true if this bean type has an inheritance hierarchy. 342 */ 343 boolean hasInheritance(); 344 345 /** 346 * Return true if this object is the root level object in its entity 347 * inheritance. 348 */ 349 boolean isInheritanceRoot(); 350 351 /** 352 * Returns all direct children of this beantype 353 */ 354 List<BeanType<?>> inheritanceChildren(); 355 356 /** 357 * Deprecated migrate to inheritanceChildren() 358 */ 359 @Deprecated 360 default List<BeanType<?>> getInheritanceChildren() { 361 return inheritanceChildren(); 362 } 363 364 /** 365 * Returns the parent in inheritance hierarchy 366 */ 367 BeanType<?> inheritanceParent(); 368 369 /** 370 * Deprecated migrate to inheritanceParent() 371 */ 372 @Deprecated 373 default BeanType<?> getInheritanceParent() { 374 return inheritanceParent(); 375 } 376 377 /** 378 * Visit all children recursively 379 */ 380 void visitAllInheritanceChildren(Consumer<BeanType<?>> visitor); 381 382 /** 383 * Return the discriminator column. 384 */ 385 String discColumn(); 386 387 /** 388 * Deprecated migrate to discColumn() 389 */ 390 @Deprecated 391 default String getDiscColumn() { 392 return discColumn(); 393 } 394 395 /** 396 * Create a bean given the discriminator value. 397 */ 398 T createBeanUsingDisc(Object discValue); 399}